HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbFormInputElement.php
Go to the documentation of this file.
1 <?php
2 
3 
4 class TbFormInputElement extends CFormElement {
5 
10  public static $inputTypes = array(
11  // standard fields
12  'text' => 'textFieldGroup',
13  'hidden' => 'hiddenField',
14  'password' => 'passwordFieldGroup',
15  'textarea' => 'textAreaGroup',
16  'file' => 'fileFieldGroup',
17  'radio' => 'radioButtonGroup',
18  'checkbox' => 'checkBoxGroup',
19  'listbox' => 'listBoxGroup',
20  'dropdownlist' => 'dropDownListGroup',
21  'checkboxlist' => 'checkBoxListGroup',
22  'radiolist' => 'radioButtonListGroup',
23  'url' => 'urlFieldGroup',
24  'email' => 'emailFieldGroup',
25  'number' => 'numberFieldGroup',
26  'range' => 'rangeFieldGroup',
27  'date' => 'dateFieldGroup',
28  'time' => 'timeFieldGroup',
29  'tel' => 'telFieldGroup',
30  'search' => 'searchFieldGroup',
31  // extended fields
32  'switch' => 'switchGroup',
33  'datepicker' => 'datePickerGroup',
34  'daterange' => 'dateRangeGroup',
35  'timepicker' => 'timePickerGroup',
36  'datetimepicker' => 'dateTimePickerGroup',
37  'select2' => 'select2Group',
38  'redactor' => 'redactorGroup',
39  'html5editor' => 'html5EditorGroup',
40  'markdowneditor' => 'markdownEditorGroup',
41  'ckeditor' => 'ckEditorGroup',
42  'typeahead' => 'typeAheadGroup',
43  'maskedtext' => 'maskedTextFieldGroup',
44  'colorpicker' => 'colorPickerGroup',
45  //'captcha' => 'captchaGroup',
46  'pass' => 'passFieldGroup'
47  );
48 
49  public $widgetOptions = array();
50 
57  public $type;
58 
62  public $name;
63 
68  public $label;
69 
77  public $labelOptions;
78 
83  public $hint;
84 
90  public $hintOptions;
91 
96  public $prepend;
97 
104 
109  public $append;
110 
117 
123  public $items = array();
124 
131  public $errorOptions = array();
132 
140  public $enableAjaxValidation = true;
141 
149  public $enableClientValidation = true;
150 
155  protected function generateGroupOptions() {
156 
157  $options = array();
158  $fields = array('widgetOptions, label', 'labelOptions', 'errorOptions', 'hint', 'hintOptions', 'prepend', 'prependOptions',
159  'append', 'appendOptions', 'enableAjaxValidation', 'enableClientValidation');
160 
161  foreach ($fields as $prop) {
162  if (isset($this->$prop)) {
163  $options[$prop] = $this->$prop;
164  }
165  }
166 
167  $options['widgetOptions']['data'] = $this->items;
168 
169  return $options;
170  }
171 
176  public function render() {
177 
178  $model = $this->getParent()->getModel();
179  $attribute = $this->name;
180  $options = $this->generateGroupOptions();
181 
182  if (isset(self::$inputTypes[$this->type])) {
183  $method = self::$inputTypes[$this->type];
184  // FIXME ... why we are passing $this->attributes ... most all TbActiveForm method only require $options
185  return $this->getParent()->getActiveFormWidget()->$method($model, $attribute, $this->attributes, $options);
186  /* no need for this as now data goes inside $options['widgetOptions']['data']
187  switch ($method) {
188  case 'listBoxGroup':
189  case 'dropDownListGroup':
190  case 'checkBoxListGroup':
191  case 'radioButtonListGroup':
192  return $this->getParent()->getActiveFormWidget()->$method($model, $attribute, $this->attributes, $this->items, $options);
193 
194  default:
195  return $this->getParent()->getActiveFormWidget()->$method($model, $attribute, $this->attributes, $options);
196  }
197  */
198  } else {
200  $attributes['model'] = $this->getParent()->getModel();
201  $attributes['attribute'] = $this->name;
202 
203  return $this->getParent()->getActiveFormWidget()->customFieldGroup(
204  array(array($this->getParent()->getOwner(), 'widget'), array($this->type, $attributes, true)),
205  $model,
206  $attribute,
207  $options
208  );
209  }
210  }
211 
217  protected function evaluateVisible() {
218 
219  return $this->getParent()->getModel()->isAttributeSafe($this->name);
220  }
221 }