* @copyright Copyright (c) 2010, ConsultorPC * @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html * @link http://smartclientphp.com/ * @since Version 0.1b * @filesource */ /** * Smart Client Tab Helper * */ class ScTab extends ScGeneral { /** * @var Array All tabs */ protected $_tabs; /** * * Add Tab * * @param mixed $data If string, it must be the title of the tab. If array, them we will loop on it * @param string $pane Content of the tab * @param array $options Additional options * @return string * */ public function addTab( $data , $pane = '' , $options = '' ) { $newTab = array(); // Check if it is an array if ( is_array( $data ) ) { $newTab = $data; } else { // Add name and title to the new field $newTab['title'] = $data; $newTab['pane'] = $pane; // Check if options is array and do the loop if ( is_array( $options ) ) { foreach ( $options as $name => $value ) { $newTab[$name] = $value; } } } // Add tab to the array $this->_tabs[] = $newTab; } /** * Add Multiple Tabs * * @param array $data Array containing multiple tabs * */ public function addTabs( $data ) { if ( is_array( $data ) ) { foreach ( $data as $row ) { $this->addTab( $row ); } } } /** * Get Tabs * * Return the current tabs array * * @return array * */ public function getTabs() { return $this->_tabs; } /** * * Clear Items array * */ public function clearTabs() { unset( $this->_tabs ); } /** * * Creates a Tab Set * * @param mixed $data If string, it must be the element ID. If array, them we will loop through it * @param integer $width Width of the tab set * @param integer $height Height of the tab set * @param array $options Additional options * @return string * */ public function create( $data , $width = '' , $height = '' , $options = '' ) { $newTabSet = array(); // Check if it is an array if ( is_array( $data ) ) { $newTabSet = $data; } else { // Add vars to the new button $newTabSet['ID'] = $data; $newTabSet['width'] = $width; $newTabSet['height'] = $height; // Set tabs $newTabSet['tabs'] = $this->_tabs; // Check if options is array and do the loop if ( is_array( $options ) ) { foreach ( $options as $name => $value ) { $newTabSet[$name] = $value; } } } // Encode data $dataEncoded = $this->encode( $newTabSet ); // Generate js code $js = 'isc.TabSet.create( '. $dataEncoded .' );'; // Add script tag $js = $this->addScriptTags( $js ); return $js; } }