16 Yii::import(
'zii.widgets.jui.CJuiDatePicker' );
49 if( !in_array( $this->mode, array(
'date',
'time',
'datetime' ) ) )
50 throw new CException(
'unknown mode "' . $this->mode .
'"' );
52 if( !isset( $this->language ) )
53 $this->language = Yii::app()->getLanguage();
56 if( $this->mode ===
'time' )
58 $this->options = array_merge( $this->options, $this->timeOptions );
59 $this->htmlOptions = array_merge( $this->htmlOptions, $this->timeHtmlOptions );
62 return parent::init();
70 list(
$name, $id ) = $this->resolveNameID();
72 if( isset( $this->htmlOptions[
'id'] ) )
73 $id = $this->htmlOptions[
'id'];
75 $this->htmlOptions[
'id'] = $id;
76 if( isset( $this->htmlOptions[
'name'] ) )
77 $name = $this->htmlOptions[
'name'];
79 $this->htmlOptions[
'name'] =
$name;
81 if( $this->hasModel() )
82 echo CHtml::activeTextField( $this->model, $this->attribute, $this->htmlOptions );
84 echo CHtml::textField(
$name, $this->value, $this->htmlOptions );
86 $options = CJavaScript::encode( $this->options );
88 $js =
"jQuery('#{$id}').{$this->mode}picker({$options});";
90 if( isset( $this->language ) && $this->language !=
'en_us' )
92 $this->registerScriptFile( $this->i18nScriptFile );
93 $js =
"jQuery('#{$id}').{$this->mode}picker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['{$this->language}'], {$options}));";
97 $assets = Yii::app()->getAssetManager()->publish( Yii::getPathOfAlias(
98 'ext.EJuiTimePicker' ) .
'/assets' );
99 $cs = Yii::app()->getClientScript();
100 $cs->registerCssFile( $assets . self::ASSETS_NAME .
'.css' );
101 $cs->registerScriptFile( $assets . self::ASSETS_NAME .
'.js',
102 CClientScript::POS_END );
105 $cs->registerScript( __CLASS__, $this->defaultOptions ?
'jQuery.{$this->mode}picker.setDefaults(' . CJavaScript::encode( $this->defaultOptions ) .
');' :
'' );
106 $cs->registerScript( __CLASS__ .
'#' . $id, $js );
109 $localization = $assets . self::LOCALIZATION_NAME . $this->language .
'.js';
110 if( file_exists( Yii::getPathOfAlias(
'webroot' ) . $localization ) )
111 $cs->registerScriptFile( $localization, CClientScript::POS_END );