HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbDateRangePicker.php
Go to the documentation of this file.
1 <?php
18 Yii::import('booster.widgets.TbBaseInputWidget');
19 
21 
27  public $form;
28 
32  public $selector;
33 
37  public $callback;
38 
42  public $options = array();
43 
47  public $htmlOptions = array();
48 
54  public function init() {
55 
56  $this->registerClientScript();
57  parent::init();
58  }
59 
65  public function run() {
66 
67  if ($this->selector) {
68  $this->registerScript($this->selector, $this->options, $this->callback);
69  } else {
70  list($name, $id) = $this->resolveNameID();
71 
72  if ($this->hasModel()) {
73  if ($this->form) {
74  echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
75  } else {
76  echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
77  }
78 
79  } else {
80  echo CHtml::textField($name, $this->value, $this->htmlOptions);
81  }
82 
83  $this->setLocaleSettings();
84  $this->registerScript('#' . $id, $this->options, $this->callback);
85  }
86 
87  }
88 
89  public function registerScript($selector, $options = array(), $callback = null) {
90 
91  Yii::app()->clientScript->registerScript(
92  uniqid(__CLASS__ . '#', true),
93  '$("' . $selector . '").daterangepicker(' . CJavaScript::encode($options) . ($callback
94  ? ', ' . CJavaScript::encode($callback) : '') . ');'
95  );
96  }
97 
107  private function setLocaleSettings() {
108 
109  $this->setDaysOfWeekNames();
110  $this->setMonthNames();
111  }
112 
116  private function setDaysOfWeekNames() {
117 
118  if (empty($this->options['locale']['daysOfWeek'])) {
119  $this->options['locale']['daysOfWeek'] = Yii::app()->locale->getWeekDayNames('narrow', true);
120  }
121  }
122 
126  private function setMonthNames() {
127 
128  if (empty($this->options['locale']['monthNames'])) {
129  $this->options['locale']['monthNames'] = array_values(
130  Yii::app()->locale->getMonthNames('wide', true)
131  );
132  }
133  }
134 
140  public function registerClientScript() {
141 
142  $booster = Booster::getBooster();
143  $booster->registerAssetCss('bootstrap-daterangepicker.css');
144  $booster->registerAssetJs('bootstrap.daterangepicker.js');
145  $booster->registerPackage('moment');
146  }
147 }