SCPHP
[ class tree: SCPHP ] [ index: SCPHP ] [ all elements ]

Source for file ScButtons.php

Documentation is available at ScButtons.php

  1. <?php
  2. /**
  3.  * SCPHP
  4.  *
  5.  * An open source SmartClient library for PHP
  6.  *
  7.  * @package        SCPHP
  8.  * @author        Fernando Marcelo Morgenstern <fernando@consultorpc.com>
  9.  * @copyright    Copyright (c) 2009, ConsultorPC
  10.  * @license        http://www.gnu.org/licenses/lgpl-3.0-standalone.html
  11.  * @link        http://smartclientphp.com/
  12.  * @since        Version 0.1b
  13.  * @filesource
  14.  */
  15.  
  16.  
  17. /**
  18.  * Smart Client Buttons Helper
  19.  *
  20.  */
  21. class ScButtons extends ScGeneral 
  22. {
  23.     /**
  24.      * 
  25.      * Button
  26.      * 
  27.      * Creates a new button
  28.      *
  29.      * @param mixed $data If string, it must be the title of the button. If array, them we will loop through it
  30.      * @param string $click Onclick function
  31.      * @param string $buttonType Type of the button
  32.      * @param array $options Additional options
  33.      * @return string 
  34.      * 
  35.      */
  36.     public function create$data $click '' $buttonType '' $options '' )
  37.     {
  38.         $newButton array();
  39.         
  40.         // Set the valid buttons
  41.         $validButtons array'Button' 'IButton' 'ImgButton' );
  42.         
  43.         // Check if it is an array
  44.         if is_array$data ) )
  45.         {
  46.             // Get button type off the array
  47.             $buttonType $data['buttonType'];
  48.             unset$data['buttonType');
  49.             
  50.             $newButton $data;
  51.         }
  52.         else
  53.         {
  54.             // Add vars to the new button
  55.             $newButton['title'$data;
  56.             $newButton['click'$this->addQuotesStr$click );
  57.             
  58.             // Check if options is array and do the loop
  59.             if is_array$options ) )
  60.             {
  61.                 foreach $options as $name => $value )
  62.                 {
  63.                     $newButton[$name$value;
  64.                 }
  65.             }
  66.         }
  67.         
  68.         // Check if buttonType is valid
  69.         if !in_array$buttonType $validButtons ) )
  70.         {
  71.             // Set buttonType to a default value
  72.             $buttonType 'IButton';
  73.         }
  74.         
  75.         // Encode all data
  76.         $dataEncoded json_encode$newButton );
  77.         
  78.         // Remove vars that shouldn't be quoted
  79.         $dataEncoded $this->removeQuotes$dataEncoded );
  80.         
  81.         // Generate js code
  82.         $js '
  83.         <script type="text/javascript">
  84.             isc.'$buttonType .'.create(
  85.                 '$dataEncoded .'
  86.             );
  87.         </script>
  88.         ';
  89.         
  90.         return $js;
  91.     }
  92. }

Documentation generated on Wed, 29 Jul 2009 22:37:13 -0300 by phpDocumentor 1.4.1