~fusonic/chive/1.1

« back to all changes in this revision

Viewing changes to yii/zii/widgets/jui/CJuiDatePicker.php

  • Committer: Matthias Burtscher
  • Date: 2010-02-12 09:12:35 UTC
  • Revision ID: matthias.burtscher@fusonic.net-20100212091235-jqxrb62klx872ajc
* Updated Yii to 1.1.0
* Removed CodePress and CodeMirror
* Updated jQuery and some plugins
* Cleaned some code ...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * CJuiDatePicker class file.
 
4
 *
 
5
 * @author Sebastian Thiere <sebathi@gmail.com>
 
6
 * @link http://www.yiiframework.com/
 
7
 * @copyright Copyright &copy; 2008-2010 Yii Software LLC
 
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: CJuiDatePicker.php 99 2010-01-07 20:55:13Z qiang.xue $
 
40
 * @package zii.widgets.jui
 
41
 * @since 1.1
 
42
 */
 
43
class CJuiDatePicker extends CJuiInputWidget
 
44
{
 
45
        /**
 
46
         * @var string the locale ID (e.g. 'fr', 'de') for the language to be used by the date picker.
 
47
         * If this property is not set, I18N will not be involved. That is, the date picker will show in English.
 
48
         */
 
49
        public $language;
 
50
 
 
51
        /**
 
52
         * @var string The i18n Jquery UI script file. It uses scriptUrl property as base url.
 
53
         */
 
54
        public $i18nScriptFile = 'jquery-ui-i18n.js';
 
55
 
 
56
        /**
 
57
         * Run this widget.
 
58
         * This method registers necessary javascript and renders the needed HTML code.
 
59
         */
 
60
        public function run()
 
61
        {
 
62
                list($name,$id)=$this->resolveNameID();
 
63
 
 
64
                if(isset($this->htmlOptions['id']))
 
65
                        $id=$this->htmlOptions['id'];
 
66
                else
 
67
                        $this->htmlOptions['id']=$id;
 
68
                if(isset($this->htmlOptions['name']))
 
69
                        $name=$this->htmlOptions['name'];
 
70
                else
 
71
                        $this->htmlOptions['name']=$name;
 
72
 
 
73
                if($this->hasModel())
 
74
                        echo CHtml::activeTextField($this->model,$this->attribute,$this->htmlOptions);
 
75
                else
 
76
                        echo CHtml::textField($name,$this->value,$this->htmlOptions);
 
77
 
 
78
                $options=CJavaScript::encode($this->options);
 
79
 
 
80
                $js = "jQuery('#{$id}').datepicker($options);";
 
81
 
 
82
                if (isset($this->language)){
 
83
                        $this->registerScriptFile($this->i18nScriptFile);
 
84
                        $js .= "\njQuery('#{$id}').datepicker('option', jQuery.datepicker.regional['{$this->language}']);";
 
85
                }
 
86
 
 
87
                Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id, $js);
 
88
        }
 
89
}
 
 
b'\\ No newline at end of file'