Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
lookup.php
Go to the documentation of this file.
1 <?php
2 /*-------------------------------------------------------------------------------
3  * Xataface Web Application Framework
4  * Copyright (C) 2005-2009 Web Lite Solutions Corp (shannah@sfu.ca)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *-------------------------------------------------------------------------------
20  */
21 
22 /*******************************************************************************
23  * File: HTML/QuickForm/lookup.php
24  * Author: Steve Hannah <shannah@sfu.ca>
25  * Created: July 13, 2009
26  * Description:
27  * HTML QuickForm lookup widget that allows users to click a "lookup" button and
28  * find the record id that they want to place in a field.
29  *
30  * @example
31  * $el = $form->addElement('lookup', 'myfield','My Field');
32  * $el->setProperties(array('table'=>'thelookuptable'));
33  *
34  *
35  ******************************************************************************/
36 
37 
38 require_once 'HTML/QuickForm/text.php';
39 
40 
49 class HTML_QuickForm_lookup extends HTML_QuickForm_text {
50 
51  var $index;
52  function HTML_QuickForm_lookup($elementName=null, $elementLabel=null, $attributes=null, $properties=null)
53  {
54  static $index=1;
55  $this->index = $index++;
56  $this->index_prefix = time();
57  if ( !isset($attributes) ) $attributes = array();
58  $class = @$attributes['class'];
59  $class .= ' xf-lookup xf-lookup-'.$this->index_prefix.'-'.$this->index;
60  $attributes['class'] = $class;
61  $attributes['df:cloneable'] = 1;
62  parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
63  $this->_type = 'lookup';
64 
65 
66 
67  } //end constructor
68 
69 
70 
78  function toHtml()
79  {
80 
81 
82 
83  $out = '';
84 
85  if ( !defined('HTML_QuickForm_lookup_files_loaded') ){
86  define('HTML_QuickForm_lookup_files_loaded',1);
88  $jt->import('xataface/widgets/lookup.js');
89 
90 
91  }
92  $properties = $this->getProperties();
93  if ( $this->_flagFrozen ){
94  $properties['frozen'] = 1;
95  }
96  if ( !isset($properties['callback']) ){
97  $properties['callback'] = 'function(out){}';
98  }
99 
100  ob_start();
101  $oldFrozen = $this->_flagFrozen;
102  $this->_flagFrozen=0;
103  $this->updateAttributes(array('data-xf-lookup-options'=>json_encode($properties)));
104  echo parent::toHtml();
105  $this->_flagFrozen=$oldFrozen;
106  $out .= ob_get_contents();
107  ob_end_clean();
108 
109  $selector = null;
110  if ( $this->getName() ){
111  $selector = "input[name='".$this->getName()."']";
112  } else {
113  $selector = '.xf-lookup-'.$this->index_prefix.'-'.$this->index;
114  }
115 
116 
117  /*
118  $out .= '
119  <script type="text/javascript">
120  jQuery(document).ready(function($){
121  var options = '.json_encode($properties).';
122  if ( !options.filters ) options.filters = {};
123  options.dynFilters = {};
124  $.each(options.filters, function(key,val){
125  if ( val.indexOf("$")==0 ){
126  options.dynFilters[key] = val.substr(1);
127  delete options.filters[key];
128  }
129  });
130  options.callback = '.$properties['callback'].';
131  options.click = function(){
132  $.each(options.dynFilters, function(key,val){
133  delete options.filters[key];
134  $("form *[name="+val+"]").each(function(){
135  options.filters[key] = $(this).val();
136  });
137  });
138 
139  };
140  $("'.$selector.'").RecordBrowserWidget(options);
141  });
142  </script>';
143  */
144  return '<span style="white-space:nowrap">'.$out.'</span>';
145 
146 
147 
148  } //end func toHtml
149 
150 
151  //function getFrozenHtml(){
152  // return $this->getValue();
153  //}
154 
155 
156 
157 
158 
159 }