41 if ($form->data->hasField($field))
43 $form->override($field, $label, $this);
47 $form->add($this, $field);
48 if ($label) $form->alias($field, $label);
56 $this->groupByFormat = $format;
61 if ($this->parent->readOnlyForm || $this->parent->isReadOnly($field))
return;
62 $id =
"{$this->parent->id}_{$field}";
64 <script type=
'text/javascript'>
65 function <?echo $id?>_update(sel)
67 if (sel.hasClass(
"selected"))
69 sel.removeClass(
"selected");
73 sel.addClass(
"selected");
78 $$(
'.<?echo $id?>_list > li').each(
function(elt)
80 if (elt.hasClass(
'selected'))
82 var v = elt.get(
'data-value');
87 var hidden = document.id(
'<?echo $id?>');
89 hidden.value = values.join(
",");
90 var f = document.id(
'<?echo $this->parent->id?>');
91 if (v != hidden.value && f && f.manager)
104 trace(
"# of Options: ".count($this->options), 3);
106 if (count($this->options))
108 if ($this->containerClass) { echo
"<div class='{$this->containerClass}'>\n"; }
110 $obj = $this->parent->data;
114 $keys = array_keys($this->options);
115 $rc = $this->options[$keys[0]][0];
117 else if ($this->grouped)
119 $keys = array_keys($this->options);
120 $rc = $this->options[$keys[0]][0];
124 $rc = $this->options[0];
126 $pk = $obj->getPrimaryKey();
134 $selectedItems = $this->
getSelected($obj, $rc, $pk);
137 $value = implode(
",", array_keys($selectedItems));
139 $id =
"{$this->parent->id}_{$field}";
141 echo
"<input type='hidden' id='{$id}' name='{$field}' value='{$value}'/>";
145 $gpk = $this->
groupBy[0]->getPrimaryKey();
147 foreach($this->
groupBy as $group)
149 if (array_key_exists($group->get($gpk), $this->options))
151 echo $group->format($this->groupByFormat);
152 $this->
renderOptions($field, $this->options[$group->get($gpk)], $selectedItems);
156 else if (is_string($this->
groupBy))
158 trace(
"Rendering grouped by", 3);
161 foreach($options as $group => $choices)
163 echo
"<{$this->groupTag}>$group</{$this->groupTag}>";
167 else if ($this->grouped)
169 trace(
"Rendering grouped", 3);
170 foreach($this->options as $group => $choices)
172 echo
"<{$this->groupTag}>$group</{$this->groupTag}>";
178 trace(
"Rendering simple", 3);
179 $this->
renderOptions($field, $this->options, $selectedItems);
182 if ($this->containerClass) { echo
"</div>\n"; }
189 $id =
"{$this->parent->id}_{$field}";
191 echo
"<ul class='{$id}_list {$this->cssClass}'>";
194 $val = $option->get($option->getPrimaryKey());
196 if (array_key_exists($val, $selectedItems)) $classes[] =
"selected";
198 if ($this->onStartOption)
200 $flag = call_user_func($this->onStartOption, $option);
201 if ($flag ===
false)
continue;
202 if ($flag) $classes[] = $flag;
205 $classes = implode(
" ", $classes);
207 $description = $this->
formatName($option, $this->nameField);
208 echo
"<li class='{$classes}' data-value='{$val}' onclick='{$id}_update(this); return false;'>{$description}</li>\n";
217 if (count($this->options))
220 $obj = $this->parent->data;
222 $rc = $this->options[0];
223 $pk = $obj->getPrimaryKey();
225 $selectedItems = $this->
getSelected($obj, $rc, $pk);
228 foreach($this->options as $option)
230 $val = $option->get($option->getPrimaryKey());
231 if (array_key_exists($val, $selectedItems)) $selected[] = $option;
234 echo
formatItems($selected,
"{".$this->nameField.
"}", $this->separator);
242 return ($obj->get($pk) !=
"") ?
indexedQuery($this->xrefClass,
"WHERE {$pk}={$obj->get($pk)}", $rc->getPrimaryKey()) : array();
247 $pks = $obj->getPrimaryKeyList();
250 if ($xref->hasField($pk))
return $pk;
258 if (count($this->options) == 0)
return;
262 $obj = $this->parent->data;
267 $keys = array_keys($this->options);
268 $rc = $this->options[$keys[0]][0];
272 $rc = $this->options[0];
282 if (isset($_POST[$field]))
284 $ids = explode(
",", $_POST[$field]);
289 $xref->joinTransaction($tx);
290 $xref->set($pk, $obj->get($pk));
291 $xref->set($optpk, $id);
314 $xref->joinTransaction($tx);
315 $xref->delete(
"WHERE {$pk}=".$obj->get($pk));
The DataTransaction class wraps the underlying database's transaction model.
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)
formatName($item, $name)
Formats the given DataItem based on the supplied format string.
_endField($field)
Internal method to generate the closing HTML for the field.
FieldRenderer($parent)
Constructor.
Displays a control that provides a highly styleable set of options from which the user can select a n...
postProcess($field="")
FieldRenderers can override this method to provide behavior that occurs after the parent form's targe...
getMatchingPK($xref, $obj)
renderOptions($field, $options, $selectedItems)
OptionCrossReferenceFieldRenderer(&$form, $field, $label, $options, $nameField, $xrefClass, $grouped=false)
renderField($field)
FieldRenderers must override this method to provide the HTML implementation of the control used to ed...
getSelected($obj, $rc, $pk)
groupBy($groupBy, $format="")
clearOutRelations($obj, $pk, $tx)
Clear out the current relations stored in the xref class.
renderScript($field)
FieldRenderers can override this method to provide any Javascript that their control requires for an ...
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
regroupList($list, $field)
Regroup an indexed or grouped query result by a different field.
indexedQuery($class)
Performs a query against the database, returning an array of DataItem objects of the specified class,...
formatItems($items, $template, $separator="")
Format a list of DataItems using the specified templated.