CMS  Version 3.9
progressive_search_field_renderer.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
39 Fakoli::usingFeature("field_renderers");
40 
41 
42 class ProgressiveSearchFieldRenderer extends StringFieldRenderer
43 {
44  var $handler = "";
45  var $minimumLength = 4;
46  var $cssClass = "scrollbox";
47  var $scrollBoxWidth = "300px";
48  var $size = 20;
49 
50  var $browse = false;
51  var $browseLabel = "Browse";
52  var $browseCss = "button";
53 
64  {
65  $this->FieldRenderer($parent);
66  if ($field && !$parent->data->hasField($field))
67  {
68  $parent->add($this, $field);
69  $parent->overrides[$field]['label'] = $label;
70  }
71  else if($label)
72  {
73  $parent->override($field, $label, $this);
74  }
75 
76  $this->handler = $handler;
77  $this->autocomplete = false;
78  }
79 
80  function allowBrowse($text = "", $css = "")
81  {
82  $this->browse = true;
83  if ($text) $this->browseText = jsSafe($text);
84  if ($css) $this->browseCss = jsSafe($css);
85  return $this;
86  }
87 
88  function renderScript($field)
89  {
90  if ($this->parent->readOnlyForm || $this->parent->isReadOnly($field)
91  || array_key_exists($field, $this->parent->hidden)) return "";
92 
93  $browse = $this->browse ? "true": "false";
94 
95  $searchOptions = "{'search': '{$this->handler}', minimumLength: {$this->minimumLength}, 'cssClass': '{$this->cssClass}', 'width': '{$this->scrollBoxWidth}', 'parameter': '{$field}', 'browse': {$browse}, 'browseText': '{$this->browseText}', 'browseCssClass': '{$this->browseCss}'}";
96 
97  echo "<script type='text/javascript'>\n";
98  echo "var {$field}_progressiveSearch;\n";
99  echo "window.addEvent('domready', function()\n";
100  echo "{\n";
101  echo "\t{$field}_progressiveSearch = new ProgressiveSearch('{$this->parent->id}_{$field}', {$searchOptions});\n";
102  echo "});\n";
103  echo "</script>\n";
104  }
105 }?>
$parent
Definition: templates.inc:42
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
$handler
path to the action handler that retrieves and displays results
$scrollBoxWidth
width of progressive search results
ProgressiveSearchFieldRenderer(&$parent, $field, $label="", $handler)
$cssClass
class for the progressive search results
$minimumLength
minimum number of characters user must enter before search is called
$size
size of the input field for entering search string