* @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 Button Helper * */ class ScButton extends ScGeneral { /** * * Button * * Creates a new button * * @param mixed $data If string, it must be the title of the button. If array, them we will loop through it * @param string $click Onclick function * @param string $buttonType Type of the button * @param array $options Additional options * @return string * */ public function create( $data , $click = '' , $buttonType = '' , $options = '' ) { $newButton = array(); // Set the valid buttons $validButtons = array( 'Button' , 'IButton' , 'ImgButton' ); // Check if it is an array if ( is_array( $data ) ) { // Get button type off the array $buttonType = $data['buttonType']; unset( $data['buttonType'] ); $newButton = $data; } else { // Add vars to the new button $newButton['title'] = $data; $newButton['click'] = $this->addQuotesStr( $click ); // Check if options is array and do the loop if ( is_array( $options ) ) { foreach ( $options as $name => $value ) { $newButton[$name] = $value; } } } // Check if buttonType is valid if ( !in_array( $buttonType , $validButtons ) ) { // Set buttonType to a default value $buttonType = 'IButton'; } // Encode data $dataEncoded = $this->encode( $newButton ); // Generate js code $js = 'isc.'. $buttonType .'.create( '. $dataEncoded .' );'; // Add script tag $js = $this->addScriptTags( $js ); return $js; } }