HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbDatePicker.php
Go to the documentation of this file.
1 <?php
17 Yii::import('booster.widgets.TbBaseInputWidget');
18 
20 
26  public $form;
27 
31  public $options = array();
32 
36  public $events = array();
37 
43  public function init() {
44 
45  $this->htmlOptions['type'] = 'text';
46  $this->htmlOptions['autocomplete'] = 'off';
47 
48  if (!isset($this->options['language'])) {
49  $this->options['language'] = substr(Yii::app()->getLanguage(), 0, 2);
50  }
51 
52  parent::init();
53  }
54 
60  public function run() {
61 
62  list($name, $id) = $this->resolveNameID();
63 
64  if ($this->hasModel()) {
65  if ($this->form) {
66  echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
67  } else {
68  echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
69  }
70 
71  } else {
72  echo CHtml::textField($name, $this->value, $this->htmlOptions);
73  }
74 
75  $this->registerClientScript();
76  $this->registerLanguageScript();
77  $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
78 
79  ob_start();
80  echo "jQuery('#{$id}').datepicker({$options})";
81  foreach ($this->events as $event => $handler) {
82  echo ".on('{$event}', " . CJavaScript::encode($handler) . ")";
83  }
84 
85  Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->getId(), ob_get_clean() . ';');
86 
87  }
88 
95  public function registerClientScript() {
96 
97  Booster::getBooster()->registerPackage('datepicker');
98  }
99 
103  public function registerLanguageScript() {
104 
105  $booster = Booster::getBooster();
106 
107  if (isset($this->options['language']) && $this->options['language'] != 'en') {
108  $filename = '/bootstrap-datepicker/js/locales/bootstrap-datepicker.' . $this->options['language'] . '.js';
109 
110  if (file_exists(Yii::getPathOfAlias('booster.assets') . $filename)) {
111  if ($booster->enableCdn) {
112  Yii::app()->clientScript->registerScriptFile(
113  '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.2.0/js/locales/bootstrap-datepicker.' . $this->options['language'] . '.js',
114  CClientScript::POS_HEAD
115  );
116  } else {
117  $booster->cs->registerScriptFile($booster->getAssetsUrl() . $filename, CClientScript::POS_HEAD);
118  }
119  }
120  }
121  }
122 }