Skip to content
Newer
Older
100644 133 lines (116 sloc) 4.07 KB
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
1 <?php
2 /**
3 * CJuiDatePicker class file.
4 *
5 * @author Sebastian Thierer <sebathi@gmail.com>
6 * @link http://www.yiiframework.com/
4be0af6 changed copyright year.
qiang.xue authored Jan 1, 2011
7 * @copyright Copyright &copy; 2008-2011 Yii Software LLC
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
8 * @license http://www.yiiframework.com/license/
9 */
10
11 Yii::import('zii.widgets.jui.CJuiInputWidget');
12
13 /**
14 * CJuiDatePicker displays a datepicker.
15 *
16 * CJuiDatePicker encapsulates the {@link http://jqueryui.com/demos/datepicker/ JUI
17 * datepicker} plugin.
18 *
19 * To use this widget, you may insert the following code in a view:
20 * <pre>
21 * $this->widget('zii.widgets.jui.CJuiDatePicker', array(
22 * 'name'=>'publishDate',
23 * // additional javascript options for the date picker plugin
24 * 'options'=>array(
25 * 'showAnim'=>'fold',
26 * ),
27 * 'htmlOptions'=>array(
28 * 'style'=>'height:20px;'
29 * ),
30 * ));
31 * </pre>
32 *
33 * By configuring the {@link options} property, you may specify the options
34 * that need to be passed to the JUI datepicker plugin. Please refer to
35 * the {@link http://jqueryui.com/demos/datepicker/ JUI datepicker} documentation
36 * for possible options (name-value pairs).
37 *
38 * @author Sebastian Thierer <sebathi@gmail.com>
39 * @version $Id$
40 * @package zii.widgets.jui
41 * @since 1.1
42 */
43 class CJuiDatePicker extends CJuiInputWidget
44 {
45 /**
cd8c2ad doc fix
mdomba authored Jan 4, 2011
46 * @var string the locale ID (eg 'fr', 'de') for the language to be used by the date picker.
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
47 * If this property is not set, I18N will not be involved. That is, the date picker will show in English.
c7b6b00 change on DatePicker documentation
sebathi authored Dec 7, 2010
48 * You can force English language by setting the language attribute as '' (empty string)
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
49 */
50 public $language;
51
52 /**
53 * @var string The i18n Jquery UI script file. It uses scriptUrl property as base url.
54 */
55 public $i18nScriptFile = 'jquery-ui-i18n.min.js';
56
57 /**
58 * @var array The default options called just one time per request. This options will alter every other CJuiDatePicker instance in the page.
59 * It has to be set at the first call of CJuiDatePicker widget in the request.
60 */
61 public $defaultOptions;
eb7428c Fixed break on CJuiDatePicker.
qiang.xue authored Jan 16, 2011
62
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
63 /**
c10160b code style update
sebathi authored Oct 14, 2010
64 * @var boolean If true, shows the widget as an inline calendar and the input as a hidden field. Use the onSelect event to update the hidden field
f506841 merge
alexander.makarow authored Oct 14, 2010
65 */
66 public $flat = false;
eb7428c Fixed break on CJuiDatePicker.
qiang.xue authored Jan 16, 2011
67
f506841 merge
alexander.makarow authored Oct 14, 2010
68 /**
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
69 * Run this widget.
70 * This method registers necessary javascript and renders the needed HTML code.
71 */
7947d52 (Fixes issue 1419) CMaskedTextField, CAutoComplete, CStarRating, CJui…
alexander.makarow authored Oct 13, 2010
72 public function run()
73 {
eb7428c Fixed break on CJuiDatePicker.
qiang.xue authored Jan 16, 2011
74
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
75 list($name,$id)=$this->resolveNameID();
76
7947d52 (Fixes issue 1419) CMaskedTextField, CAutoComplete, CStarRating, CJui…
alexander.makarow authored Oct 13, 2010
77 if(isset($this->htmlOptions['id']))
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
78 $id=$this->htmlOptions['id'];
7947d52 (Fixes issue 1419) CMaskedTextField, CAutoComplete, CStarRating, CJui…
alexander.makarow authored Oct 13, 2010
79 else
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
80 $this->htmlOptions['id']=$id;
7947d52 (Fixes issue 1419) CMaskedTextField, CAutoComplete, CStarRating, CJui…
alexander.makarow authored Oct 13, 2010
81 if(isset($this->htmlOptions['name']))
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
82 $name=$this->htmlOptions['name'];
83
c10160b code style update
sebathi authored Oct 14, 2010
84 if ($this->flat===false)
f506841 merge
alexander.makarow authored Oct 14, 2010
85 {
86 if($this->hasModel())
87 echo CHtml::activeTextField($this->model,$this->attribute,$this->htmlOptions);
88 else
89 echo CHtml::textField($name,$this->value,$this->htmlOptions);
90 }
7947d52 (Fixes issue 1419) CMaskedTextField, CAutoComplete, CStarRating, CJui…
alexander.makarow authored Oct 13, 2010
91 else
f506841 merge
alexander.makarow authored Oct 14, 2010
92 {
93 if($this->hasModel())
bd3f668 Added default value for inline option.
sebathi authored Nov 1, 2010
94 {
f506841 merge
alexander.makarow authored Oct 14, 2010
95 echo CHtml::activeHiddenField($this->model,$this->attribute,$this->htmlOptions);
bd3f668 Added default value for inline option.
sebathi authored Nov 1, 2010
96 $attribute = $this->attribute;
97 $this->options['defaultDate'] = $this->model->$attribute;
98 }
f506841 merge
alexander.makarow authored Oct 14, 2010
99 else
bd3f668 Added default value for inline option.
sebathi authored Nov 1, 2010
100 {
c10160b code style update
sebathi authored Oct 14, 2010
101 echo CHtml::hiddenField($name,$this->value,$this->htmlOptions);
bd3f668 Added default value for inline option.
sebathi authored Nov 1, 2010
102 $this->options['defaultDate'] = $this->value;
103 }
eb7428c Fixed break on CJuiDatePicker.
qiang.xue authored Jan 16, 2011
104
f506841 merge
alexander.makarow authored Oct 14, 2010
105 if (!isset($this->options['onSelect']))
ada1ced @samdark added CJavaScriptExpression while keeping BC
samdark authored Jul 27, 2012
106 $this->options['onSelect']=new CJavaScriptExpression("function( selectedDate ) { jQuery('#{$id}').val(selectedDate);}");
eb7428c Fixed break on CJuiDatePicker.
qiang.xue authored Jan 16, 2011
107
99bdf5e (Fixes issue 1799) Better fix as the old one (r2674) was breaking CJu…
mdomba authored Jan 15, 2012
108 $id = $this->htmlOptions['id'] = $id.'_container';
109 $this->htmlOptions['name'] = $name.'_container';
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
110
006a81a Fixed issue 1936
sebathi authored Dec 30, 2010
111 echo CHtml::tag('div', $this->htmlOptions, '');
f506841 merge
alexander.makarow authored Oct 14, 2010
112 }
7947d52 (Fixes issue 1419) CMaskedTextField, CAutoComplete, CStarRating, CJui…
alexander.makarow authored Oct 13, 2010
113
f506841 merge
alexander.makarow authored Oct 14, 2010
114 $options=CJavaScript::encode($this->options);
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
115 $js = "jQuery('#{$id}').datepicker($options);";
116
727c6fc (Fixes issue 2544)
qiang.xue authored Jun 23, 2011
117 if ($this->language!='' && $this->language!='en')
c10160b code style update
sebathi authored Oct 14, 2010
118 {
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
119 $this->registerScriptFile($this->i18nScriptFile);
120 $js = "jQuery('#{$id}').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['{$this->language}'], {$options}));";
121 }
122
123 $cs = Yii::app()->getClientScript();
eb7428c Fixed break on CJuiDatePicker.
qiang.xue authored Jan 16, 2011
124
c10160b code style update
sebathi authored Oct 14, 2010
125 if (isset($this->defaultOptions))
f506841 merge
alexander.makarow authored Oct 14, 2010
126 {
127 $this->registerScriptFile($this->i18nScriptFile);
128 $cs->registerScript(__CLASS__, $this->defaultOptions!==null?'jQuery.datepicker.setDefaults('.CJavaScript::encode($this->defaultOptions).');':'');
129 }
130 $cs->registerScript(__CLASS__.'#'.$id, $js);
c10160b code style update
sebathi authored Oct 14, 2010
131
44bbab5 merged zii repository into yii.
qiang.xue authored Aug 20, 2010
132 }
133 }
Something went wrong with that request. Please try again.