38 require_once realpath(dirname(__FILE__)).
"/../field_renderers.inc";
98 if ($form->data->hasField($field))
100 $form->override($field, $label, $this);
104 $form->add($this, $field);
105 if ($label) $form->alias($field, $label);
111 $this->addEntry =
true;
112 $this->addEntryText = $text;
113 $this->addEntrySize = $size;
122 $this->scrollAfter = $scrollAfter;
129 $this->fixedOptions[$value] = $value;
136 $this->defaultOptions[$value] = $value;
143 if (!$this->grouped)
return count($this->options);
147 foreach($this->options as $groupName => $group);
149 $count += count($group) + 1;
159 $rawValue = $this->parent->data->get($field);
160 if (is_array($rawValue))
163 $rawValue = $this->parent->data->get($field);
166 $values = explode(
",", $rawValue);
168 $divider = $this->horizontal ?
" " :
"";
169 $layout = $this->horizontal ?
" style='display: inline'" :
"";
171 if ($this->showSelectAll)
173 echo
"<a class='select_toggle' href='#' onclick='return {$this->parent->id}_{$field}_toggleSelectAll(this);'>Select All</a><br/>";
176 if ($this->width && $this->height && $this->
getOptionCount() > $this->scrollAfter)
180 $padding = (
$width ==
"auto") ?
"padding-right: 20px; " :
"";
183 $dropdown = $this->dropdown ?
" multi_select_dropdown_list" :
"";
184 echo
"<div id='{$this->parent->id}_{$field}_container' class='selectbox scrollbox{$resizable}{$dropdown}' style='width: {$width}; height: {$height}; $padding overflow: auto'>\n";
188 echo
"<div class='selectbox'>";
196 foreach($this->options as $groupName => $group)
198 echo
"<dt>$groupName</dt>\n<dd>\n";
199 foreach($group as $value => $text)
201 $checked = (array_search($value, $values) !== FALSE) ?
" checked" :
"";
203 if ($this->nobr) { $text = str_replace(
" ",
" ", $text); }
205 echo
"<label for='{$this->parent->id}_{$field}[$idx]'$layout><input type='checkbox' class='checkbox' id='{$this->parent->id}_{$field}[$idx]' name='{$field}[$idx]' value='$value'$checked/>$text</label>$divider";
215 if(count($this->options) > 0)
217 foreach($this->options as $value => $text)
221 if ($this->fixedOptions[$value])
223 $disabled =
" disabled";
224 $checked =
" checked";
226 else if ($this->defaultOptions[$value])
228 $checked =
"checked";
232 $checked = (array_search($value, $values) !== FALSE) ?
" checked" :
"";
234 if ($this->nobr) { $text = str_replace(
" ",
" ", $text); }
235 echo
"<label for='{$this->parent->id}_{$field}[$idx]'$layout><input type='checkbox' class='checkbox' id='{$this->parent->id}_{$field}[$idx]' name='{$field}[$idx]' value='$value'$checked$disabled/>$text</label>$divider";
241 foreach($values as $value)
243 if(!array_key_exists($value, $this->options))
244 $addEntryValue .= $value;
252 echo
" {$this->addEntryText} ";
257 echo
"<input type='text' name='{$field}_addEntry' value='{$addEntryValue}' size='{$this->addEntrySize}'/>";
261 echo
"<input type=\"hidden\" name=\"count_{$field}\" value=\"".$idx.
"\">";
270 if ($this->showSelectAll)
273 <script type=
"text/javascript">
275 function <?echo $this->parent->id?>_<?echo $field ?>_toggleSelectAll(link)
277 link = document.id(link);
279 var value = (link.innerHTML ==
"Select All");
281 var container = document.id(
'<?echo $this->parent->id?>_<?echo $field?>_container');
283 container.getElements(
"input[type=checkbox]").each(
function(cbox)
285 cbox.set(
'checked', value);
288 link.innerHTML = (value) ?
"Deselect All" :
"Select All";
289 if (container.multiSelect) container.multiSelect.selectionChanged();
300 <script type=
'text/javascript'>
301 window.addEvent(
'domready',
function()
303 new MultiSelect(
'<?echo $this->parent->id?>_<?echo $field?>_container', {maxWidth:
'<?echo $this->dropdownMaxWidth?>', message:
'<?echo jsSafe($this->dropdownMessage)?>'});
314 $value = $this->parent->data->get($field);
316 $items = explode(
",", $value);
320 foreach($this->options as $category =>
$options)
324 foreach($items as $item)
326 if (array_key_exists($item,
$options))
330 $out =
"$category: ";
341 if ($out) $answers[] = $out;
348 foreach($items as $item)
350 $answers[] = array_key_exists($item, $this->options) ? $this->options[$item] : $item;
354 $value = implode($this->separator, $answers);
373 $rawValue = $this->parent->params->get($field, $mode);
375 if (is_array($rawValue))
377 $rawValue = implode(
",", array_values($rawValue));
378 $this->parent->params->set($field, $mode, $rawValue);
381 $values = explode(
",", $rawValue);
382 $values = array_combine($values, $values);
384 $divider = $this->horizontal ?
" " :
"";
385 $layout = $this->horizontal ?
" style='display: inline'" :
"";
387 if ($this->showSelectAll)
389 echo
"<a href='#' onclick='return {$this->parent->id}_{$field}_toggleSelectAll(this);'>Select All</a><br/>";
392 if ($this->width && $this->height && $this->
getOptionCount() > $this->scrollAfter)
396 $padding = (
$width ==
"auto") ?
"padding-right: 20px; " :
"";
399 $dropdown = $this->dropdown ?
" multi_select_dropdown_list" :
"";
400 echo
"<div id='{$this->parent->id}_{$field}_container' class='selectbox scrollbox{$resizable}{$dropdown}' style='width: {$width}; height: {$height}; $padding overflow: auto'>\n";
404 echo
"<div class='selectbox'>";
412 foreach($this->options as $groupName => $group)
414 echo
"<dt>$groupName</dt>\n<dd>\n";
415 foreach($group as $value => $text)
417 $checked = (array_search($value, $values) !== FALSE) ?
" checked" :
"";
419 if ($this->nobr) { $text = str_replace(
" ",
" ", $text); }
421 echo
"<label for='{$this->parent->id}_{$field}_$idx'$layout><input type='checkbox' class='checkbox' id='{$this->parent->id}_{$field}_$idx' name='{$field}:{$mode}[$idx]' value='$value'$checked/>$text</label>$divider";
432 if(count($this->options) > 0)
434 foreach($this->options as $value => $text)
436 $checked = (array_key_exists($value, $values)) ?
" checked" :
"";
437 echo
"<label for='{$this->parent->id}_{$field}_$value'$layout><input type='checkbox' class='checkbox' id='{$this->parent->id}_{$field}_$value' name='{$field}:{$mode}[$value]' value='$value'$checked/>$text</label>$divider";
444 if ($this->width && $this->height)
454 $value = ($this->parent->method ==
"POST") ? $_POST[$field] : $_GET[$field];
455 $addEntry = ($this->parent->method ==
"POST") ? $_POST[
"{$field}_addEntry"] : $_GET[
"{$field}_addEntry"];
457 if (is_array($value))
459 $this->parent->data->set($field, implode(
",", array_values($value)));
463 $this->parent->data->set($field,
"");
467 $this->parent->data->set($field, $value);
470 trace(
"addEntry($field): $addEntry", 3);
474 if($this->parent->data->get($field))
476 $this->parent->data->set($field, $this->parent->data->get($field) .
",");
479 $this->parent->data->set($field, $this->parent->data->get($field) .
$addEntry);
CheckListFieldRenderer: Renders the specified list of options as a list of checkboxes from which mult...
$separator
The separator between values in read only list.
renderScript($field)
FieldRenderers can override this method to provide any Javascript that their control requires for an ...
renderSearchField($field, $mode)
FieldRenderers must override this method to provide the HTML implementation of the control displayed ...
CheckListFieldRenderer(&$form, $field, $label, $options, $grouped=false)
allowAddEntry($text="or add new", $size=40)
renderSearchScript($field, $mode)
FieldRenderers can override this method to provide any Javascript that the control requires when bein...
renderField($field)
FieldRenderers must override this method to provide the HTML implementation of the control used to ed...
setSize($width, $height, $scrollAfter=0)
preProcess($field="")
FieldRenderers can override this method to provide behavior that occurs prior to the saving of the pa...
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.
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.