HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbColorPicker.php
Go to the documentation of this file.
1 <?php
24 Yii::import('booster.widgets.TbBaseInputWidget');
25 
27 
33  public $form;
34 
38  public $format = 'hex';
39 
57  public $events = array();
58 
64  public function run()
65  {
66  list($name, $id) = $this->resolveNameID();
67 
68  $this->registerClientScript($id);
69 
70  $this->htmlOptions['id'] = $id;
71 
72  // Do we have a model?
73  if ($this->hasModel()) {
74  if ($this->form) {
75  echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
76  } else {
77  echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
78  }
79  } else {
80  echo CHtml::textField($name, $this->value, $this->htmlOptions);
81  }
82  }
83 
91  public function registerClientScript($id) {
92 
93  Booster::getBooster()->cs->registerPackage('colorpicker');
94  // Booster::getBooster()->registerAssetJs('bootstrap.colorpicker.js', CClientScript::POS_HEAD);
95  // Booster::getBooster()->registerAssetCss('bootstrap-colorpicker.css');
96 
97  $options = !empty($this->format) ? CJavaScript::encode(array('format' => $this->format)) : '';
98 
99  ob_start();
100  echo "jQuery('#{$id}').colorpicker({$options})";
101  foreach ($this->events as $event => $handler) {
102  echo ".on('{$event}', " . CJavaScript::encode($handler) . ")";
103  }
104 
105  Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->getId(), ob_get_clean() . ';');
106  }
107 }