Framework  3.9
select_field_view_source_renderer.inc
Go to the documentation of this file.
1 <?php
6 /**************************************************************
7 
8  Copyright (c) 2007-2010 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 
80 require_once realpath(dirname(__FILE__))."/../field_renderers.inc";
81 
82 class SelectFieldViewSourceRenderer extends SelectFieldRenderer
83 {
84  var $buttonLabel; // defaults to field label
85  var $field;
86  // javascript function that opens the popup e.g., openMyDialog or new MyClass().openMyDialog
87  var $callback;
88 
89  function SelectFieldViewSourceRenderer(&$form, $field, $label, $options, $callback)
90  {
91  $onChange = "selChanged_{$field}";
92  $this->field = $field;
93 
94  // If user provided ending "()" on function, remove
95  $callback = preg_replace("/\‍(*?\‍)$/", "", $callback);
96  $this->callback = $callback;
97 
98  // show none if none - overrides SelectFieldRenderer code that
99  // adds options when there are none
100  if ($options == null)
101  $options[0] = "";
102 
103  $this->SelectFieldRenderer($form, $field, $label, $options, $onChange);
104  $this->buttonLabel = $label;
105  }
106 
108  {
109  $fn = "{$this->parent->id}_{$field}";
110  $selChanged = "selChanged_" . $field;
111 
112 ?>
113 <script type="text/javascript">
114 function <?echo $fn ?>_preview()
115 {
116  var elt = document.id('<? echo $fn ?>');
117 
118  if (elt.value)
119  {
120  var dialog = <?php echo $this->callback ?>(elt.value);
121  }
122 }
123 
124 function <? echo $selChanged ?>(elt)
125 {
126  var button = document.id('view_<? echo $field ?>_button');
127  if (elt.value)
128  button.disabled = "";
129  else
130  button.disabled = "disabled";
131 }
132 
133 window.addEvent('load', function()
134 {
135  var elt = document.id('<? echo $field ?>');
136  <? echo $selChanged ?>(elt);
137  });
138 </script>
139 <?
140  }
141 
142 
143  function _endField($field)
144  {
145  $name = "view_{$field}_button";
146 
147  echo "&nbsp;<button id=\"$name\" name=\"$name\" onclick=\"{$this->parent->id}_{$field}_preview(); return false;\" class=\"button\">View {$this->buttonLabel}</button>";
148 
149  parent::_endField($field);
150  }
151 } // end class SelectFieldViewSourceRenderer
152 ?>
SelectFieldViewSourceRenderer: Renders the specified list of options as a dropdown select box with a ...
SelectFieldViewSourceRenderer(&$form, $field, $label, $options, $callback)