HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
UWjuidate.php
Go to the documentation of this file.
1 <?php
2 
3 class UWjuidate
4 {
8  public $params = array(
9  'ui-theme' => 'base',
10  'language' => 'en',
11  );
12 
18  public function init()
19  {
20  return array(
21  'name' => __CLASS__,
22  'label' => UserModule::t('jQueryUI datepicker'),
23  'fieldType' => array('DATE','VARCHAR'),
24  'params' => $this->params,
25  'paramsLabels' => array(
26  'dateFormat' => UserModule::t('Date format'),
27  ),
28  );
29  }
30 
38  public function setAttributes($value, $model, $field_varname)
39  {
40  if ($value == '0000-00-00') {
41  $value = '';
42  }
43 
44  return $value;
45  }
46 
53  public function viewAttribute($model, $field)
54  {
55  return $model->getAttribute($field->varname);
56  }
57 
65  public function editAttribute($model, $field, $htmlOptions = array())
66  {
67  if (!isset($htmlOptions['size'])) {
68  $htmlOptions['size'] = 60;
69  }
70  if (!isset($htmlOptions['maxlength'])) {
71  $htmlOptions['maxlength'] = (($field->field_size) ? $field->field_size : 10);
72  }
73  if (!isset($htmlOptions['id'])) {
74  $htmlOptions['id'] = get_class($model).'_'.$field->varname;
75  }
76 
77  $id = $htmlOptions['id'];
78  $options['dateFormat'] = 'yy-mm-dd';
79  $options = CJavaScript::encode($options);
80 
81  $basePath = Yii::getPathOfAlias('user.views.asset');
82  $baseUrl = Yii::app()->getAssetManager()->publish($basePath);
83  $cs = Yii::app()->getClientScript();
84  $cs->registerCssFile($baseUrl.'/css/'.$this->params['ui-theme'].'/jquery-ui.css');
85  $cs->registerScriptFile($baseUrl.'/js/jquery-ui.min.js');
86 
87  $language = $this->params['language'];
88  if ($language != 'en') {
89  $js = "jQuery('#{$id}').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['{$language}'], {$options}));";
90  $cs->registerScriptFile($baseUrl.'/js/jquery-ui-i18n.min.js');
91  } else {
92  $js = "jQuery('#{$id}').datepicker({$options});";
93  }
94 
95  $cs->registerScript('ProfileFieldController'.'#'.$id, $js);
96 
97  return CHtml::activeTextField($model, $field->varname, $htmlOptions);
98  }
99 }