HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbDateTimePicker.php
Go to the documentation of this file.
1 <?php
9 Yii::import('booster.widgets.TbBaseInputWidget');
17 
23  public $form;
24 
28  public $options = array();
29 
33  public $events = array();
34 
40  public function init() {
41 
42  parent::init();
43 
44  $this->htmlOptions['type'] = 'text';
45  $this->htmlOptions['autocomplete'] = 'off';
46 
47  if (!isset($this->options['language'])) {
48  $this->options['language'] = substr(Yii::app()->getLanguage(), 0, 2);
49  }
50 
51  }
52 
58  public function run() {
59 
60  list($name, $id) = $this->resolveNameID();
61 
62  if ($this->hasModel()) {
63  if ($this->form) {
64  echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
65  } else {
66  echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
67  }
68 
69  } else {
70  echo CHtml::textField($name, $this->value, $this->htmlOptions);
71  }
72 
73  $this->registerClientScript();
74  $this->registerLanguageScript();
75  $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
76 
77  ob_start();
78  echo "jQuery('#{$id}').datetimepicker({$options})";
79  foreach ($this->events as $event => $handler) {
80  echo ".on('{$event}', " . CJavaScript::encode($handler) . ")";
81  }
82 
83  Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->getId(), ob_get_clean() . ';');
84 
85  }
86 
93  public function registerClientScript() {
94 
95  Booster::getBooster()->registerPackage('datetimepicker');
96  }
97 
98  public function registerLanguageScript() {
99 
100  if (isset($this->options['language']) && $this->options['language'] != 'en') {
101  $file = 'locales/bootstrap-datetimepicker.' . $this->options['language'] . '.js';
102  $booster = Booster::getBooster();
103  if (@file_exists(Yii::getPathOfAlias('booster.assets.bootstrap-datetimepicker') . '/js/' . $file)) {
104  if ($booster->enableCdn) {
105  // Not in CDN yet
106  $booster->registerAssetJs('../bootstrap-datetimepicker/' . '/js/' . $file);
107  } else {
108  $booster->registerAssetJs('../bootstrap-datetimepicker/' . '/js/' . $file);
109  }
110  }
111  }
112  }
113 }