[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/framework/Web/UI/WebControls/ -> TColorPicker.php (source)

   1  <?php
   2  /**
   3   * TColorPicker class file
   4   *
   5   * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
   6   * @link http://www.pradosoft.com/
   7   * @copyright Copyright &copy; 2005 PradoSoft
   8   * @license http://www.pradosoft.com/license/
   9   * @version $Id: TColorPicker.php 1397 2006-09-07 07:55:53Z wei $
  10   * @package System.Web.UI.WebControls
  11   */
  12  
  13  /**
  14   * TColorPicker class.
  15   *
  16   * Be aware, this control is EXPERIMENTAL and is not stablized yet.
  17   *
  18   * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
  19   * @version $Id: TColorPicker.php 1397 2006-09-07 07:55:53Z wei $
  20   * @package System.Web.UI.WebControls
  21   * @since 3.0
  22   */
  23  class TColorPicker extends TTextBox
  24  {
  25      /**
  26       * @return boolean whether the color picker should pop up when the button is clicked.
  27       */
  28  	public function getShowColorPicker()
  29      {
  30          return $this->getViewState('ShowColorPicker',true);
  31      }
  32  
  33      /**
  34       * Sets whether to pop up the color picker when the button is clicked.
  35       * @param boolean whether to show the color picker popup
  36       */
  37  	public function setShowColorPicker($value)
  38      {
  39          $this->setViewState('ShowColorPicker',TPropertyValue::ensureBoolean($value),true);
  40      }
  41  
  42      /**
  43       * @param TColorPickerMode color picker UI mode
  44       */
  45  	public function setMode($value)
  46      {
  47         $this->setViewState('Mode', TPropertyValue::ensureEnum($value, 'TColorPickerMode'), TColorPickerMode::Basic);
  48      }
  49  
  50      /**
  51       * @return TColorPickerMode current color picker UI mode. Defaults to TColorPickerMode::Basic.
  52       */
  53  	public function getMode()
  54      {
  55         return $this->getViewState('Mode', TColorPickerMode::Basic);
  56      }
  57  
  58      /**
  59       * @param string set the color picker style
  60       */
  61  	public function setColorPickerStyle($value)
  62      {
  63         $this->setViewState('ColorStyle', $value, 'default');
  64      }
  65  
  66      /**
  67       * @return string current color picker style
  68       */
  69  	public function getColorPickerStyle()
  70      {
  71         return $this->getViewState('ColorStyle', 'default');
  72      }
  73  
  74      /**
  75       * @return string text for the color picker OK button. Default is "OK".
  76       */
  77  	public function getOKButtonText()
  78      {
  79          return $this->getViewState('OKButtonText', 'OK');
  80      }
  81  
  82      /**
  83       * @param string text for the color picker OK button
  84       */
  85  	public function setOKButtonText($value)
  86      {
  87          $this->setViewState('OKButtonText', $value, 'OK');
  88      }
  89  
  90      /**
  91       * @return string text for the color picker Cancel button. Default is "Cancel".
  92       */
  93  	public function getCancelButtonText()
  94      {
  95          return $this->getViewState('CancelButtonText', 'Cancel');
  96      }
  97  
  98      /**
  99       * @param string text for the color picker Cancel button
 100       */
 101  	public function setCancelButtonText($value)
 102      {
 103          $this->setViewState('CancelButtonText', $value, 'Cancel');
 104      }
 105  
 106      /**
 107       * Get javascript color picker options.
 108       * @return array color picker client-side options
 109       */
 110  	protected function getColorPickerOptions()
 111      {
 112          $options['ID'] = $this->getClientID();
 113          $options['ClassName'] = $this->getCssClass();
 114          $options['ShowColorPicker'] = $this->getShowColorPicker();
 115  
 116          if($options['ShowColorPicker'])
 117          {
 118              $mode = $this->getMode();
 119  
 120              if($mode == TColorPickerMode::Full) $options['Mode'] = $mode;
 121              else if($mode == TColorPickerMode::Simple) $options['Palette'] = 'Tiny';
 122  
 123              $options['OKButtonText'] = $this->getOKButtonText();
 124              $options['CancelButtonText'] = $this->getCancelButtonText();
 125          }
 126  
 127          return $options;
 128      }
 129  
 130      /**
 131       * Publish the color picker Css asset files.
 132       */
 133  	public function onPreRender($param)
 134      {
 135          parent::onPreRender($param);
 136          $this->publishColorPickerStyle();
 137      }
 138  
 139      /**
 140       * Publish the color picker style Css asset file.
 141       * @return string Css file url.
 142       */
 143  	protected function publishColorPickerStyle()
 144      {
 145          $cs = $this->getPage()->getClientScript();
 146          $style = 'System.Web.Javascripts.colorpicker.'.$this->getColorPickerStyle();
 147          if(($cssFile=Prado::getPathOfNamespace($style,'.css'))!==null)
 148          {
 149              $url = $this->publishFilePath($cssFile);
 150              if(!$cs->isStyleSheetFileRegistered($style))
 151                  $cs->registerStyleSheetFile($style, $url);
 152              return $url;
 153          }
 154          else
 155              throw new TConfigurationException('colorpicker_style_invalid',$style);
 156      }
 157  
 158      /**
 159       * Publish the color picker image assets.
 160       * @return array list of  image URLs
 161       */
 162  	protected function publishColorPickerImageAssets()
 163      {
 164          $cs = $this->getPage()->getClientScript();
 165          $key = "prado:".get_class($this);
 166  
 167          $images = array('button' => '.gif', 'target_black' => '.gif',
 168                          'target_white' => '.gif', 'background' => '.png',
 169                          'slider' => '.gif', 'hue' => '.gif');
 170  
 171          $list = array();
 172  
 173          foreach($images as $filename => $ext)
 174          {
 175              $image = 'System.Web.Javascripts.colorpicker.'.$filename;
 176              if(($file =  Prado::getPathOfNamespace($image, $ext))!==null)
 177                  $list[$filename.$ext] = $this->publishFilePath($file);
 178              else
 179                  throw new TConfigurationException('colorpicker_image_invalid',$image);
 180          }
 181          $imgs['button.gif'] = $list['button.gif'];
 182          $imgs['background.png'] = $list['background.png'];
 183          $options = TJavaScript::encode($imgs);
 184          $code = "Prado.WebUI.TColorPicker.UIImages = {$options};";
 185          $cs->registerEndScript($key, $code);
 186          return $list;
 187      }
 188  
 189      /**
 190       * Registers the javascript code to initialize the color picker.
 191       * Must use "Event.OnLoad" to initialize the color picker when the
 192       * full page is loaded, otherwise IE will throw an error.
 193       * @param THtmlWriter writer
 194       */
 195  	protected function addAttributesToRender($writer)
 196      {
 197          parent::addAttributesToRender($writer);
 198          $writer->addAttribute('id',$this->getClientID());
 199          $scripts = $this->getPage()->getClientScript();
 200          $scripts->registerPradoScript("colorpicker");
 201          $options = TJavaScript::encode($this->getColorPickerOptions());
 202          $id = $this->getClientID();
 203          $code = "Event.OnLoad(function(){ new Prado.WebUI.TColorPicker($options); });";
 204          $scripts->registerEndScript("prado:$id", $code);
 205      }
 206  
 207      /**
 208       * Renders body content.
 209       * This method overrides parent implementation by adding
 210       * additional color picker button.
 211       * @param THtmlWriter writer
 212       */
 213  	public function render($writer)
 214      {
 215          parent::render($writer);
 216  
 217          $images = $this->publishColorPickerImageAssets();
 218          $color = $this->getText();
 219  
 220          $writer->addAttribute('class', 'TColorPicker_button');
 221          $writer->renderBeginTag('span');
 222  
 223          $writer->addAttribute('id', $this->getClientID().'_button');
 224          $writer->addAttribute('src', $images['button.gif']);
 225          if($color !== '')
 226              $writer->addAttribute('style', "background-color:{$color};");
 227          $writer->addAttribute('width', '20');
 228          $writer->addAttribute('height', '20');
 229          $writer->renderBeginTag('img');
 230          $writer->renderEndTag();
 231          $writer->renderEndTag();
 232      }
 233  
 234  }
 235  
 236  /**
 237   * TColorPickerMode class.
 238   * TColorPickerMode defines the enumerable type for the possible UI mode
 239   * that a {@link TColorPicker} control can take.
 240   *
 241   * The following enumerable values are defined:
 242   * - Simple
 243   * - Basic
 244   * - Full
 245   *
 246   * @author Qiang Xue <qiang.xue@gmail.com>
 247   * @version $Id: TColorPicker.php 1397 2006-09-07 07:55:53Z wei $
 248   * @package System.Web.UI.WebControls
 249   * @since 3.0.4
 250   */
 251  class TColorPickerMode extends TEnumerable
 252  {
 253      const Simple='Simple';
 254      const Basic='Basic';
 255      const Full='Full';
 256  }
 257  
 258  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7