1 <?php
2 3 4 5 6 7 8 9 10 11
12 Yii::import('bootstrap.helpers.TbArray');
13 Yii::import('bootstrap.helpers.TbHtml');
14
15 class WhTimePickerHelper extends CInputWidget
16 {
17
18 19 20
21 public $inputOptions = array();
22
23 24 25
26 public $pluginOptions = array();
27
28
29 30 31 32
33 public function init()
34 {
35
36 $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
37
38 TbHtml::addCssClass('bfh-timepicker', $this->htmlOptions);
39 $this->htmlOptions['data-time'] = $this->hasModel()
40 ? $this->model->{$this->attribute}
41 : $this->value;
42
43 $this->inputOptions['readonly'] = true;
44 }
45
46 47 48
49 public function run()
50 {
51 $this->renderField();
52 $this->registerClientScript();
53 }
54
55 56 57
58 public function renderField()
59 {
60
61 list($name, $id) = $this->resolveNameID();
62
63 TbArray::defaultValue('id', $id, $this->htmlOptions);
64 TbArray::defaultValue('name', $name, $this->htmlOptions);
65
66 echo CHtml::openTag('div', $this->htmlOptions);
67 echo CHtml::openTag('div', array(
68 'class' => 'input-prepend bfh-timepicker-toggle',
69 'data-toggle' => 'bfh-timepicker'
70 ));
71 echo CHtml::tag('span', array('class' => 'add-on'), TbHtml::icon(TbHtml::ICON_TIME));
72 if ($this->hasModel()) {
73 echo CHtml::activeTextField($this->model, $this->attribute, $this->inputOptions);
74 } else {
75 echo CHtml::textField($name, $this->value, $this->inputOptions);
76 }
77 echo CHtml::closeTag('div');
78
79 echo '<div class="bfh-timepicker-popover">
80 <table class="table">
81 <tbody>
82 <tr>
83 <td class="hour">
84 <a class="next" href="#"><i class="icon-chevron-up"></i></a><br>
85 <input type="text" class="input-mini" readonly><br>
86 <a class="previous" href="#"><i class="icon-chevron-down"></i></a>
87 </td>
88 <td class="separator">:</td>
89 <td class="minute">
90 <a class="next" href="#"><i class="icon-chevron-up"></i></a><br>
91 <input type="text" class="input-mini" readonly><br>
92 <a class="previous" href="#"><i class="icon-chevron-down"></i></a>
93 </td>
94 </tr>
95 </tbody>
96 </table>
97 </div>';
98 echo CHtml::closeTag('div');
99 }
100
101 102 103
104 public function registerClientScript()
105 {
106
107 $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
108 $assetsUrl = $this->getAssetsUrl($path);
109
110
111 $cs = Yii::app()->getClientScript();
112
113 $cs->registerCssFile($assetsUrl . '/css/bootstrap-formhelpers.css');
114 $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-timepicker.js');
115
116
117
118
119
120 }
121 }