38 require_once realpath(dirname(__FILE__)).
"/../field_renderers.inc";
58 if ($form->data->hasField($field))
62 $form->override($field, $label, $this);
66 $form->add($this, $field);
68 $form->overrides[$field][
'label'] = $label;
88 $style =
"style='width: {$this->width}'";
91 echo
"<span class='subselect_container'>";
92 echo
"<select $style name='$field' id='{$this->parent->id}_{$field}'";
94 if ($this->onChange !=
"")
96 echo
" onchange='$this->onChange(this)'";
111 if ($mode !=
"equal") $mode =
"equal";
113 $searchValue = (!$value) ? $this->parent->params->get($field, $mode) : $value;
117 echo
"<select id='$field' name='$field:$mode'><option value=''></option>\n";
118 foreach($this->options as $value => $name)
120 $selected = ($searchValue == $value) ?
" selected" :
"";
122 echo
"<option value='".htmlSafe($value).
"'$selected>$name</option>";
133 $super_id = $this->parent->data->get($this->super);
135 if (!array_key_exists($super_id, $this->options))
return;
139 $item =
findItem($this->options[$super_id], $field, $this->parent->data->get($field));
143 echo $item->format($this->format);
147 echo
"Not specified";
155 if ($this->parent->readOnlyForm || $this->parent->isReadOnly($field)
156 || array_key_exists($field, $this->parent->hidden))
return "";
158 $mgr =
"{$this->parent->id}_{$field}_mgr";
159 $super_id =
"{$this->parent->id}_{$this->super}";
160 $value = $this->parent->data->get($field);
163 <script type=
"text/javascript">
164 window.addEvent(
'domready',
function()
166 var <?echo $mgr?> =
new SubSelectManager(
'<?echo $super_id?>',
'<?echo $this->parent->id?>_<?echo $field?>',
'<?echo $value?>');
168 foreach($this->options as $key =>
$options)
171 $values =
formatItems(
$options,
"{'name': '{SubSelectFieldRenderer::formatOption}', 'value': {{$pk}} }",
", ");
173 <?echo $mgr?>.addOptions(<?echo $key?>, [{
'name':
'',
'value': 0}, <?echo $values?>]);
177 <?echo $mgr?>.update();
191 foreach($this->options as $key =>
$options)
195 $option->set(
"_formatTemplate", $this->format);
202 $template = $option->get(
"_formatTemplate");
203 return jsSafe($option->format(
"{$template}"));
208 if(!$this->parent->data->hasField($this->super))
return;
210 $super_id = $this->parent->data->get($this->super);
212 if (!array_key_exists($super_id, $this->options))
214 $this->parent->data->set($field, 0);
FieldRenderer is the abstract base class for all FieldRenderers.
_startField($field, $styles="")
Internal method to generate the starting HTML for the field (including the label)
_endField($field)
Internal method to generate the closing HTML for the field.
FieldRenderer($parent)
Constructor.
SubSelectFieldRenderer - provides a second-level hierarchical selection mechanism based on the result...
SubSelectFieldRenderer(&$form, $field, $label, $super, $options, $format)
static formatOption($option)
renderSearchField($field, $mode, $value="")
preProcess($field="")
FieldRenderers can override this method to provide behavior that occurs prior to the saving of the pa...
extraControls($field)
Override this function to provide extra editing controls that follow the visibility rules of the main...
renderScript($field)
FieldRenderers can override this method to provide any Javascript that their control requires for an ...
renderField($field)
FieldRenderers must override this method to provide the HTML implementation of the control used to ed...
setFormatTemplate()
We need to save the class var format into the object for use in the static call to formatOption.
jsSafe($str, $escapeEntities=false)
Utility function to escape a string correctly for use in a Javascript client-side call.
findItem($items, $field, $value)
Find the first item in the array that matches the supplied value for the specified field.
formatItems($items, $template, $separator="")
Format a list of DataItems using the specified templated.