Framework  3.9
color_field_renderer.inc
Go to the documentation of this file.
1 <?php
6 /**************************************************************
7 
8 Copyright (c) 2020 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 require_once realpath(dirname(__FILE__))."/../field_renderers.inc";
39 
44 {
45  var $disable = false;
46  var $onChange = null;
47 
52  function __construct(&$parent, $field = null, $label = null)
53  {
54  $this->FieldRenderer($parent);
55  if ($field && !$parent->data->hasField($field))
56  {
57  $parent->add($this, $field, $label);
58  }
59  }
60 
61  function renderScript($field)
62  {
63  $f = "{$this->parent->id}_{$field}";
64  $onChange = ($this->onChange) ? " {$this->onChange}(elt);" : ";";
65 
66  echo <<<ENDSCRIPT
67  <script type='text/javascript'>
68  function {$f}_onChange(elt)
69  {
70  document.id('{$f}_color').value = elt.value;
71  return{$onChange}
72  }
73 
74  function {$f}_color_onChange(elt)
75  {
76  document.id('{$f}').value = elt.value;
77  return{$onChange}
78  }
79  </script>
80 ENDSCRIPT;
81  }
82 
83  function renderField($field)
84  {
85  $this->_startField($field);
86 
87  $val = $this->parent->data->get($field);
88 
89  $f = "{$this->parent->id}_{$field}";
90  $disable = ($this->disable) ? "disabled='disabled'" : "";
91 
92  echo "<input id='{$f}' class='color' type='text' size='7' value='{$val}' name='$field' {$disable} onkeyup='return {$f}_onChange(this);'>&nbsp;";
93  echo "<input id='{$f}_color' type='color' value='{$val}' name='{$field}' {$disable} onchange='return {$f}_color_onChange(this);'>";
94 
95  $this->_endField($field);
96  }
97 
98  function renderSearchField($field, $mode = "match")
99  {
100  $this->_startField($field);
101 
102  $val = $this->parent->data->get($field);
103 
104  $disable = ($this->disable) ? "disabled='disabled'" : "";
105  $onChange = ($this->onChange) ? " onchange='return {$this->onChange}(this);'" : "";
106  echo "<input id='{$this->parent->id}_{$field}' type='color' value='{$val}' name='$field:$mode' {$disable}{$onChange}>";
107 
108  $this->_endField($field);
109  }
110 
111  function renderReadOnly($field)
112  {
113  $this->_startField($field);
114 
115  $val = $this->parent->data->get($field);
116 
117  echo "<input id='{$this->parent->id}_{$field}' type='color' value='{$val}' name='$field' readonly='readonly'>";
118 
119  $this->_endField($field);
120  }
121 }
122 ?>
Field renderer for boolean data fields.
renderSearchField($field, $mode="match")
FieldRenderers must override this method to provide the HTML implementation of the control displayed ...
$onChange
, alternative to readonly; field can be reenabled thru javascript
__construct(&$parent, $field=null, $label=null)
Create a new BooleanFieldRenderer.
renderField($field)
FieldRenderers must override this method to provide the HTML implementation of the control used to ed...
renderScript($field)
FieldRenderers can override this method to provide any Javascript that their control requires for an ...
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.