Framework  3.9
subselect_checklist_field_renderer.inc
Go to the documentation of this file.
1 <?php
6 /**************************************************************
7 
8  Copyright (c) 2018 Sonjara, Inc
9 
10  Permission is hereby granted, free of charge, to any person
11  obtaining a copy of this software and associated documentation
12  files (the "Software"), to deal in the Software without
13  restriction, including without limitation the rights to use,
14  copy, modify, merge, publish, distribute, sublicense, and/or sell
15  copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following
17  conditions:
18 
19  The above copyright notice and this permission notice shall be
20  included in all copies or substantial portions of the Software.
21 
22  Except as contained in this notice, the name(s) of the above
23  copyright holders shall not be used in advertising or otherwise
24  to promote the sale, use or other dealings in this Software
25  without prior written authorization.
26 
27  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
29  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
32  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34  OTHER DEALINGS IN THE SOFTWARE.
35 
36 *****************************************************************/
37 
38 
39 class SubSelectCheckListFieldRenderer extends CheckListFieldRenderer
40 {
41  var $super;
42  var $format = null;
43 
44  function __construct(&$form, $field, $label, $super, $options, $format = null)
45  {
46  $this->options = $options;
47  $this->super = $super;
48  $this->format = $format;
49 
50  $this->CheckListFieldRenderer($form, $field, $label, $options, true);
51  }
52 
53  function renderScript($field)
54  {
55  $id = "{$this->parent->id}_{$field}_container";
56  $superId = "{$this->parent->id}_{$this->super}";
57 
58  Fakoli::includeScript("/fakoli/js/subselect_checklist_manager.js");
59 ?>
60  <script>
61  window.addEvent('domready', function()
62  {
63  new SubSelectChecklistManager('<?php echo $superId?>', '<?php echo $id?>');
64  });
65  </script>
66 <?php
67  }
68 
69  function renderField($field)
70  {
71  $this->_startField($field);
72 
73  $rawValue = $this->parent->data->get($field);
74  if (!isset($rawValue)) $rawValue = $this->parent->data->getDecoration($field);
75 
76  if (is_array($rawValue))
77  {
78  $this->preProcess($field);
79  $rawValue = $this->parent->data->get($field);
80  }
81 
82  $values = explode(",", $rawValue);
83 
84  $divider = $this->horizontal ? " " : "";
85  $layout = $this->horizontal ? " style='display: inline'" : "";
86 
87  if ($this->showSelectAll)
88  {
89  echo "<a class='select_toggle' href='#' onclick='return {$this->parent->id}_{$field}_toggleSelectAll(this);'>Select All</a><br/>";
90  }
91 
92  if ($this->width && $this->height && $this->getOptionCount() > $this->scrollAfter)
93  {
94  $width = is_numeric($this->width) ? "{$this->width}px" : $this->width;
95  $height = is_numeric($this->height) ? "{$this->height}px" : $this->height;
96  $padding = ($width == "auto") ? "padding-right: 20px; " : "";
97 
98  $resizable = ($this->resizable && !$this->dropdown) ? " resizable": "";
99  $dropdown = $this->dropdown ? " multi_select_dropdown_list" : "";
100  echo "<div id='{$this->parent->id}_{$field}_container' class='selectbox scrollbox{$resizable}{$dropdown}' style='width: {$width}; height: {$height}; $padding overflow: auto'>\n";
101  }
102  else
103  {
104  echo "<div id='{$this->parent->id}_{$field}_container' class='selectbox'>";
105  }
106 
107  $idx = 0;
108 
109  foreach($this->options as $group => $options)
110  {
111  foreach($options as $value => $item)
112  {
113  $disabled = "";
114 
115  if ($this->format)
116  {
117  $text = $item->format($this->format);
118  $value = $item->getPrimaryKeyValue();
119  }
120  else
121  {
122  $text = $item;
123  }
124 
125  if ($this->fixedOptions[$value])
126  {
127  $disabled = " disabled";
128  $checked = " checked";
129  }
130  else
131  {
132  $checked = (array_search($value, $values) !== FALSE) ? " checked" : "";
133  }
134  if ($this->nobr) { $text = str_replace(" ", "&nbsp;", $text); }
135 
136  echo "<label data-select='{$group}' 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";
137  $idx++;
138  }
139  }
140 
141  // Save this count to loop through checkboxes on required validation
142  echo "<input type=\"hidden\" name=\"count_{$field}\" value=\"".$idx."\">";
143 
144  echo "</div>\n";
145 
146  $this->_endField($field);
147  }
148 }
149 
CheckListFieldRenderer: Renders the specified list of options as a list of checkboxes from which mult...
renderScript($field)
FieldRenderers can override this method to provide any Javascript that their control requires for an ...
CheckListFieldRenderer(&$form, $field, $label, $options, $grouped=false)
renderField($field)
FieldRenderers must override this method to provide the HTML implementation of the control used to ed...
preProcess($field="")
FieldRenderers can override this method to provide behavior that occurs prior to the saving of the pa...
_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.