This repository has been archived by the owner on Jan 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTTimePicker.php
56 lines (49 loc) · 1.94 KB
/
TTimePicker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
class TTimePicker extends CInputWidget{
public $overwrite=false;
//default value that is treated as lack of date.
public $default='0000-00-00 00:00:00';
// options specific to timepicker
// custom user options
public $options=array();
// default options
public $defaultOptions = array(
'format'=>'yyyy-MM-dd hh:mm:ss',
);
public function run(){
$cs = Yii::app()->getClientScript();
$assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__) . '/assets');
$cs->registerCssFile($assets . '/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css');
$cs->registerScriptFile($assets . '/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js');
$id;
if($this->hasModel()){
list($name, $id) = $this->resolveNameId();
$htmlOptions=$this->htmlOptions;
$value=CHtml::resolveValue($this->model, $this->attribute);
if($this->default===$value){
$htmlOptions['value']='';
}
echo '<div id="'.$id.'_datetimepicker" class="input-append date">';
echo CHtml::activeTextField($this->model, $this->attribute, $htmlOptions);
echo '<span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span></div>';
}else{
$id=$this->getId();
$this->name=$id;
$defaults=array(
'id'=>$id,
);
$htmlOptions=array_merge($defaults, $this->htmlOptions);
echo '<div id="'.$id.'_datetimepicker" class="input-append date">';
echo CHtml::textField($this->name, $this->value, $htmlOptions);
echo '<span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span></div>';
}
$joptions=CJavaScript::encode(array_merge($this->defaultOptions, $this->options));
$jscode='$("#'.$id.'_datetimepicker").datetimepicker('.$joptions.');';
if($this->overwrite){
$jscode.='$("#'.$id.'_datetimepicker")'.
'.data("datetimepicker")'.
'.setLocalDate(new Date());';
}
Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, $jscode);
}
}