Framework  3.9
SliderFieldRenderer Class Reference
+ Inheritance diagram for SliderFieldRenderer:
+ Collaboration diagram for SliderFieldRenderer:

Public Member Functions

 __construct (&$form, $field, $min=0, $max=10, $editable=true)
 
 setThresholds ($thresholds)
 
 renderScript ($field)
 FieldRenderers can override this method to provide any Javascript that their control requires for an edit form. More...
 
 renderField ($field)
 FieldRenderers must override this method to provide the HTML implementation of the control used to edit the field. More...
 
 renderReadOnly ($field)
 
- 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...
 
 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...
 
 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...
 

Public Attributes

 $min = 0
 
 $max = 10
 
 $editable = true
 
 $thresholds = null
 
 $displayValue = true
 
- 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

Definition at line 40 of file slider_field_renderer.inc.

Constructor & Destructor Documentation

◆ __construct()

SliderFieldRenderer::__construct ( $form,
  $field,
  $min = 0,
  $max = 10,
  $editable = true 
)

Definition at line 48 of file slider_field_renderer.inc.

49  {
50  $this->min = $min;
51  $this->max = $max;
52  $this->editable = $editable;
53  $this->FieldRenderer($form);
54 
55  if ($field && !$form->data->hasField($field))
56  {
57  $form->add($this, $field);
58  }
59  else
60  {
61  $form->override($field, $label, $this);
62  }
63  }
FieldRenderer($parent)
Constructor.

Member Function Documentation

◆ renderField()

SliderFieldRenderer::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 119 of file slider_field_renderer.inc.

120  {
121  $this->_startField($field);
122  $value = $this->parent->data->get($field);
123  if (!$value) $value = $this->min;
124 
125  echo "<input type='range' id='{$this->parent->id}_{$field}' name='{$field}' min='{$this->min}' max='{$this->max}' value='{$value}' data-displayField='{$this->parent->id}_{$field}_display'/>";
126 
127  if ($this->displayValue)
128  {
129  $threshold = ($this->thresholds) ? $this->thresholds[$value] : "";
130  echo "<span class='range_display' id='{$this->parent->id}_{$field}_display'>{$threshold}</span>";
131  }
132 
133  $this->_endField($field);
134  }
_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.

◆ renderReadOnly()

SliderFieldRenderer::renderReadOnly (   $field)

Definition at line 136 of file slider_field_renderer.inc.

137  {
138  }

◆ renderScript()

SliderFieldRenderer::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 70 of file slider_field_renderer.inc.

71  {
72  if (isset($this->thresholds))
73  {
74  krsort($this->thresholds, SORT_NUMERIC);
75  $thresholds = json_encode($this->thresholds);
76  }
77  else
78  {
79  $thresholds = "null";
80  }
81 
82  $id = "{$this->parent->id}_{$field}";
83 
84  $script = <<<ENDSCRIPT
85 <script type='text/javascript'>
86 var {$id}_thresholds = {$thresholds};
87 window.addEvent('domready', function()
88 {
89  var range = document.id('{$id}');
90  var display = document.id('{$id}_display');
91 
92  if (display != null)
93  {
94  range.addEvent('input', function(elt)
95  {
96  if ({$id}_thresholds != null)
97  {
98  for(var score in {$id}_thresholds)
99  {
100  if (range.value == score)
101  {
102  display.set('html', ${id}_thresholds[score]);
103  }
104  }
105  }
106  else
107  {
108  display.set('text', range.value);
109  }
110  });
111  }
112 });
113 </script>
114 ENDSCRIPT;
115 
116  echo $script;
117  }

◆ setThresholds()

SliderFieldRenderer::setThresholds (   $thresholds)

Definition at line 65 of file slider_field_renderer.inc.

66  {
67  $this->thresholds = $thresholds;
68  }

Member Data Documentation

◆ $displayValue

SliderFieldRenderer::$displayValue = true

Definition at line 46 of file slider_field_renderer.inc.

◆ $editable

SliderFieldRenderer::$editable = true

Definition at line 44 of file slider_field_renderer.inc.

◆ $max

SliderFieldRenderer::$max = 10

Definition at line 43 of file slider_field_renderer.inc.

◆ $min

SliderFieldRenderer::$min = 0

Definition at line 42 of file slider_field_renderer.inc.

◆ $thresholds

SliderFieldRenderer::$thresholds = null

Definition at line 45 of file slider_field_renderer.inc.


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