-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWasDatepicker.php
More file actions
64 lines (55 loc) · 1.89 KB
/
WasDatepicker.php
File metadata and controls
64 lines (55 loc) · 1.89 KB
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
57
58
59
60
61
62
63
64
<?php
class WasDatepicker extends CInputWidget
{
/**
* @var array files for package
*/
public $package = array();
/**
* @var array extension options. For more info read {@link https://github.com/eternicode/bootstrap-datepicker documentation}
*/
public $options = array();
/**
* Initializes the widget.
*/
public function init()
{
list($this->name, $this->id) = $this->resolveNameId();
if($this->hasModel()) {
echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
} else {
$this->htmlOptions['id'] = $this->id;
echo CHtml::textField($this->name, $this->value, $this->htmlOptions);
}
if (isset($this->options['language'])) {
$language = 'locales/bootstrap-datepicker.' . $this->options['language'] . '.js';
} else $language = '';
$this->package = array(
'basePath' => dirname(__FILE__) . '/files',
'js' => array(
'bootstrap-datepicker.js',
$language
),
'css' => array(
'datepicker.css',
),
'depends'=>array('jquery'),
);
if (!isset($this->package['baseUrl'])) {
$this->package['baseUrl'] = Yii::app()->getAssetManager()->publish($this->package['basePath'], false, -1, YII_DEBUG);
}
$this->registerClientScript();
}
/**
* @return void
* Register JS and CSS.
*/
protected function registerClientScript()
{
$cs = Yii::app()->getClientScript();
$cs->packages['Datepicker'] = $this->package;
$cs->registerPackage('Datepicker');
$js = '$("#' . $this->id . '").datepicker(' . CJavaScript::encode($this->options) . ')';
$cs->registerScript(__CLASS__ . '#' . $this->id, $js, CClientScript::POS_READY);
}
}