Framework  3.9
SubSelectFieldRenderer Class Reference

SubSelectFieldRenderer - provides a second-level hierarchical selection mechanism based on the results of another select-based field renderer (such as SelectFieldRenderer or RelatedItemSelectFieldRenderer) More...

+ Inheritance diagram for SubSelectFieldRenderer:
+ Collaboration diagram for SubSelectFieldRenderer:

Public Member Functions

 SubSelectFieldRenderer (&$form, $field, $label, $super, $options, $format)
 
 extraControls ($field)
 Override this function to provide extra editing controls that follow the visibility rules of the main control. More...
 
 renderField ($field)
 FieldRenderers must override this method to provide the HTML implementation of the control used to edit the field. More...
 
 renderSearchField ($field, $mode, $value="")
 
 renderReadOnly ($field)
 
 renderScript ($field)
 FieldRenderers can override this method to provide any Javascript that their control requires for an edit form. More...
 
 setFormatTemplate ()
 We need to save the class var format into the object for use in the static call to formatOption. More...
 
 preProcess ($field="")
 FieldRenderers can override this method to provide behavior that occurs prior to the saving of the parent form's target object to the database. More...
 
- Public Member Functions inherited from FieldRenderer
 FieldRenderer ($parent)
 Constructor. More...
 
 _printLabel ($field, $colspan=1, $styles="", $annotation="")
 Internal method to generate the HTML for the field label. More...
 
 _getLabel ($field, $addSuffix=true)
 
 _startField ($field, $styles="")
 Internal method to generate the starting HTML for the field (including the label) More...
 
 _endField ($field)
 Internal method to generate the closing HTML for the field. More...
 
 addValidatorsToForm ($field, $required=false)
 This method is called by the AutoForm to add any default input validators that are required by the FieldRenderer. More...
 
 addSearchValidatorsToForm ($field, $mode, $required=false)
 For SearchForm, the validator field needs to match the name tag in the form which is in the format field:mode. More...
 
 formatName ($item, $name)
 Formats the given DataItem based on the supplied format string. More...
 
 renderSearchScript ($field, $mode)
 FieldRenderers can override this method to provide any Javascript that the control requires when being used in a search form. More...
 
 renderSearchField ($field, $mode)
 FieldRenderers must override this method to provide the HTML implementation of the control displayed for the field in a search form. More...
 
 renderOnSubmitHandler ($field)
 FieldRenderers can override this method to provide any Javascript that must be executed when the form is submitted on the client. More...
 
 postProcess ($field="")
 FieldRenderers can override this method to provide behavior that occurs after the parent form's target object has been saved to the database. More...
 

Static Public Member Functions

static formatOption ($option)
 

Public Attributes

 $super
 
 $options
 
 $format
 
- Public Attributes inherited from FieldRenderer
 $parent = null
 
 $labelSuffix = ""
 
 $colspan = 1
 
 $annotateBefore = false
 
 $annotateNextLine = true
 
 $hideLabel = false
 
 $onPreProcess = null
 callback hook for processing prior to saving the form's data object - individual renderers may override with custom processing More...
 
 $onPostProcess = null
 callback hook for processing after saving the form's data object - individual renderers may override with custom processing More...
 

Detailed Description

SubSelectFieldRenderer - provides a second-level hierarchical selection mechanism based on the results of another select-based field renderer (such as SelectFieldRenderer or RelatedItemSelectFieldRenderer)

Author
andy

Definition at line 46 of file subselect_field_renderer.inc.

Member Function Documentation

◆ extraControls()

SubSelectFieldRenderer::extraControls (   $field)

Override this function to provide extra editing controls that follow the visibility rules of the main control.

Parameters
string$field

Definition at line 77 of file subselect_field_renderer.inc.

78  {
79 
80  }

◆ formatOption()

static SubSelectFieldRenderer::formatOption (   $option)
static

Definition at line 200 of file subselect_field_renderer.inc.

201  {
202  $template = $option->get("_formatTemplate");
203  return jsSafe($option->format("{$template}"));
204  }
jsSafe($str, $escapeEntities=false)
Utility function to escape a string correctly for use in a Javascript client-side call.
Definition: functions.inc:434

◆ preProcess()

SubSelectFieldRenderer::preProcess (   $field = "")

FieldRenderers can override this method to provide behavior that occurs prior to the saving of the parent form's target object to the database.

For example, the FileUploadFieldRenderer overrides this method to process the uploading of the file and then store the location in the associated field in the target object.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 206 of file subselect_field_renderer.inc.

207  {
208  if(!$this->parent->data->hasField($this->super)) return;
209 
210  $super_id = $this->parent->data->get($this->super);
211 
212  if (!array_key_exists($super_id, $this->options))
213  {
214  $this->parent->data->set($field, 0);
215  }
216  }

◆ renderField()

SubSelectFieldRenderer::renderField (   $field)

FieldRenderers must override this method to provide the HTML implementation of the control used to edit the field.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 82 of file subselect_field_renderer.inc.

83  {
84  $this->_startField($field);
85 
86  if($this->width)
87  {
88  $style = "style='width: {$this->width}'";
89  }
90 
91  echo "<span class='subselect_container'>";
92  echo "<select $style name='$field' id='{$this->parent->id}_{$field}'";
93 
94  if ($this->onChange != "")
95  {
96  echo " onchange='$this->onChange(this)'";
97  }
98 
99  echo ">\n";
100  echo "</select>\n";
101 
102  $this->extraControls($field);
103 
104  echo "</span>";
105 
106  $this->_endField($field);
107  }
_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.
extraControls($field)
Override this function to provide extra editing controls that follow the visibility rules of the main...

◆ renderReadOnly()

SubSelectFieldRenderer::renderReadOnly (   $field)

Definition at line 131 of file subselect_field_renderer.inc.

132  {
133  $super_id = $this->parent->data->get($this->super);
134 
135  if (!array_key_exists($super_id, $this->options)) return;
136 
137  $this->_startField($field);
138 
139  $item = findItem($this->options[$super_id], $field, $this->parent->data->get($field));
140 
141  if ($item)
142  {
143  echo $item->format($this->format);
144  }
145  else
146  {
147  echo "Not specified";
148  }
149 
150  $this->_endField($field);
151  }
findItem($items, $field, $value)
Find the first item in the array that matches the supplied value for the specified field.
Definition: data_item.inc:2261

◆ renderScript()

SubSelectFieldRenderer::renderScript (   $field)

FieldRenderers can override this method to provide any Javascript that their control requires for an edit form.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 153 of file subselect_field_renderer.inc.

154  {
155  if ($this->parent->readOnlyForm || $this->parent->isReadOnly($field)
156  || array_key_exists($field, $this->parent->hidden)) return "";
157 
158  $mgr = "{$this->parent->id}_{$field}_mgr";
159  $super_id = "{$this->parent->id}_{$this->super}";
160  $value = $this->parent->data->get($field);
161  $this->setFormatTemplate();
162 ?>
163 <script type="text/javascript">
164 window.addEvent('domready', function()
165 {
166  var <?echo $mgr?> = new SubSelectManager('<?echo $super_id?>', '<?echo $this->parent->id?>_<?echo $field?>', '<?echo $value?>');
167 <?
168  foreach($this->options as $key => $options)
169  {
170  $pk = $options[0]->getPrimaryKey();
171  $values = formatItems($options, "{'name': '{SubSelectFieldRenderer::formatOption}', 'value': {{$pk}} }", ", ");
172 ?>
173  <?echo $mgr?>.addOptions(<?echo $key?>, [{'name': '', 'value': 0}, <?echo $values?>]);
174 <?
175  }
176 ?>
177  <?echo $mgr?>.update();
178 });
179 </script>
180 <?
181  }
setFormatTemplate()
We need to save the class var format into the object for use in the static call to formatOption.
formatItems($items, $template, $separator="")
Format a list of DataItems using the specified templated.
Definition: data_item.inc:2176

◆ renderSearchField()

SubSelectFieldRenderer::renderSearchField (   $field,
  $mode,
  $value = "" 
)

Definition at line 109 of file subselect_field_renderer.inc.

110  {
111  if ($mode != "equal") $mode = "equal";
112 
113  $searchValue = (!$value) ? $this->parent->params->get($field, $mode) : $value;
114 
115  $this->_startField($field);
116 
117  echo "<select id='$field' name='$field:$mode'><option value=''></option>\n";
118  foreach($this->options as $value => $name)
119  {
120  $selected = ($searchValue == $value) ? " selected" : "";
121 
122  echo "<option value='".htmlSafe($value)."'$selected>$name</option>";
123  }
124 
125  echo "</select>";
126 
127  $this->_endField($field);
128  }

◆ setFormatTemplate()

SubSelectFieldRenderer::setFormatTemplate ( )

We need to save the class var format into the object for use in the static call to formatOption.

We can't call formatOption using the class instance $this through the formatItems function.

Definition at line 189 of file subselect_field_renderer.inc.

190  {
191  foreach($this->options as $key => $options)
192  {
193  foreach($options as $option)
194  {
195  $option->set("_formatTemplate", $this->format);
196  }
197  }
198  }

◆ SubSelectFieldRenderer()

SubSelectFieldRenderer::SubSelectFieldRenderer ( $form,
  $field,
  $label,
  $super,
  $options,
  $format 
)

Definition at line 52 of file subselect_field_renderer.inc.

53  {
54  $this->options = $options;
55  $this->super = $super;
56  $this->format = $format;
57  $this->FieldRenderer($form);
58  if ($form->data->hasField($field))
59  {
60  // JDG 5/30/11 - don't crash on additiona/psuedo fields
61  // only query if real field
62  $form->override($field, $label, $this);
63  }
64  else
65  {
66  $form->add($this, $field);
67  // JDG 7/22/2011 - allow "additional" fields to override label
68  $form->overrides[$field]['label'] = $label;
69  }
70  }
FieldRenderer($parent)
Constructor.

Member Data Documentation

◆ $format

SubSelectFieldRenderer::$format

Definition at line 50 of file subselect_field_renderer.inc.

◆ $options

SubSelectFieldRenderer::$options

Definition at line 49 of file subselect_field_renderer.inc.

◆ $super

SubSelectFieldRenderer::$super

Definition at line 48 of file subselect_field_renderer.inc.


The documentation for this class was generated from the following file: