|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the fangface/yii2-concord package |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view |
|
6
|
|
|
* the file LICENSE.md that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @package fangface/yii2-concord |
|
9
|
|
|
* @author Fangface <[email protected]> |
|
10
|
|
|
* @copyright Copyright (c) 2014 Fangface <[email protected]> |
|
11
|
|
|
* @license https://github.com/fangface/yii2-concord/blob/master/LICENSE.md MIT License |
|
12
|
|
|
* |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace fangface\widgets; |
|
16
|
|
|
|
|
17
|
|
|
use backend\assets\BootstrapDateTimePickerAsset; |
|
18
|
|
|
use fangface\widgets\InputWidget; |
|
19
|
|
|
use fangface\helpers\Html; |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Date and Time Picker widget |
|
24
|
|
|
*/ |
|
25
|
|
|
class DateTimePicker extends InputWidget |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string the name of the jQuery plugin |
|
30
|
|
|
*/ |
|
31
|
|
|
public $pluginName = 'datetimepicker'; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var array default widget plugin options that user pluginOptions will be merged into |
|
34
|
|
|
*/ |
|
35
|
|
|
public $defaultPluginOptions = ['format' => 'yyyy-mm-dd hh:ii:ss', 'todayBtn' => true, 'autoclose' => true, 'weekStart' => 1]; |
|
36
|
|
|
/** |
|
37
|
|
|
* @var array the HTML attributes for the input tag. |
|
38
|
|
|
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
|
39
|
|
|
*/ |
|
40
|
|
|
public $options = ['class' => 'form-control input-medium']; |
|
41
|
|
|
/** |
|
42
|
|
|
* @var string element id to use when calling the datepicker |
|
43
|
|
|
*/ |
|
44
|
|
|
public $elementId = null; |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Renders the color picker widget |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function renderWidget() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->prepareInput(); |
|
53
|
|
|
$this->registerAssets(); |
|
54
|
|
|
$this->prepareTemplate(); |
|
55
|
|
|
echo $this->renderTemplate(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Prepare the input fields for the input |
|
60
|
|
|
* |
|
61
|
|
|
* @return void |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function prepareInput() |
|
64
|
|
|
{ |
|
65
|
|
|
if ($this->hasModel()) { |
|
66
|
|
|
if (!isset($this->options['value']) && $this->model->{$this->attribute} == '0000-00-00 00:00:00') { |
|
67
|
|
|
$this->options['value'] = ''; |
|
68
|
|
|
} |
|
69
|
|
|
$this->sections['input'] = Html::activeTextInput($this->model, $this->attribute, $this->options); |
|
70
|
|
|
} else { |
|
71
|
|
|
$this->sections['input'] = Html::textInput($this->name, ($this->value == '0000-00-00 00:00:00' ? '' : $this->value), $this->options); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Registers the needed client assets |
|
77
|
|
|
* |
|
78
|
|
|
* @return void |
|
79
|
|
|
*/ |
|
80
|
|
|
public function registerAssets() |
|
81
|
|
|
{ |
|
82
|
|
|
if ($this->disabled) { |
|
83
|
|
|
return; |
|
84
|
|
|
} |
|
85
|
|
|
$view = $this->getView(); |
|
86
|
|
|
BootstrapDateTimePickerAsset::register($view); |
|
87
|
|
|
if ($this->elementId !== null) { |
|
88
|
|
|
$element = "jQuery('#" . $this->elementId . "')"; |
|
89
|
|
|
} else { |
|
90
|
|
|
$element = "jQuery('#" . $this->options['id'] . "')"; |
|
91
|
|
|
} |
|
92
|
|
|
$this->registerPlugin($this->pluginName, $element); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
} |