1 dump('entering patron/search_form.js\n');
3 if (typeof patron == 'undefined') patron = {};
4 patron.search_form = function (params) {
6 JSAN.use('util.error'); this.error = new util.error();
7 JSAN.use('util.network'); this.network = new util.network();
11 patron.search_form.prototype = {
13 'init' : function( params ) {
17 // The bulk of params.query is getting parsed/rendered by obj.controller.init below, and will be reconstituted from possibly modified XUL elements upon Submit.
18 // But we're going to let search_limit and search_sort be configurable now by those spawning this interface, and let's assume there are no corresponding widgets for now.
19 // I'm going to place them into the "obj" scope for this instance.
20 obj.search_limit = params.query.search_limit;
21 obj.search_sort = JSON2js( params.query.search_sort ); // Let's assume this is encoded as JSON
23 JSAN.use('OpenILS.data'); this.OpenILS = {};
24 obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
26 JSAN.use('util.controller'); obj.controller = new util.controller();
32 function() { alert($("commonStrings").getString('common.unimplemented')); }
34 'cmd_patron_search_submit' : [
40 'cmd_patron_search_clear' : [
43 obj.controller.render();
44 window.xulG.clear_left_deck();
51 if (params.query&¶ms.query.family_name) {
52 e.setAttribute('value',params.query.family_name);
53 e.value = params.query.family_name;
60 'first_given_name' : [
64 if (params.query&¶ms.query.first_given_name) {
65 e.setAttribute('value',params.query.first_given_name);
66 e.value = params.query.first_given_name;
73 'second_given_name' : [
77 if (params.query&¶ms.query.second_given_name) {
78 e.setAttribute('value',params.query.second_given_name);
79 e.value = params.query.second_given_name;
90 if (params.query&¶ms.query.alias) {
91 e.setAttribute('value',params.query.alias);
92 e.value = params.query.alias;
103 if (params.query&¶ms.query.usrname) {
104 e.setAttribute('value',params.query.usrname);
105 e.value = params.query.usrname;
116 if (params.query&¶ms.query.card) {
117 e.setAttribute('value',params.query.card);
118 e.value = params.query.card;
129 if (params.query&¶ms.query.email) {
130 e.setAttribute('value',params.query.email);
131 e.value = params.query.email;
142 if (params.query&¶ms.query.phone) {
143 e.setAttribute('value',params.query.phone);
144 e.value = params.query.phone;
155 if (params.query&¶ms.query.ident) {
156 e.setAttribute('value',params.query.ident);
157 e.value = params.query.ident;
158 } else if (params.query&¶ms.query.ident_value) {
159 e.setAttribute('value',params.query.ident_value);
160 e.value = params.query.ident_value;
161 } else if (params.query&¶ms.query.ident_value2) {
162 e.setAttribute('value',params.query.ident_value2);
163 e.value = params.query.ident_value2;
174 if (params.query&¶ms.query.street1) {
175 e.setAttribute('value',params.query.street1);
176 e.value = params.query.street1;
187 if (params.query&¶ms.query.street2) {
188 e.setAttribute('value',params.query.street2);
189 e.value = params.query.street2;
200 if (params.query&¶ms.query.city) {
201 e.setAttribute('value',params.query.city);
202 e.value = params.query.city;
213 if (params.query&¶ms.query.state) {
214 e.setAttribute('value',params.query.state);
215 e.value = params.query.state;
226 if (params.query&¶ms.query.post_code) {
227 e.setAttribute('value',params.query.post_code);
228 e.value = params.query.post_code;
235 'profile' : [ ['render'],function(e) {
236 return function() {};
239 'inactive' : [ ['render'], function(e) {
240 return function() {};
243 'search_depth' : [ ['render'],function(e) {
244 return function() {};
251 obj.controller.render();
252 var nl = document.getElementsByTagName('textbox');
253 for (var i = 0; i < nl.length; i++) {
254 nl[i].addEventListener('keypress',function(ev){
255 if (ev.target.tagName != 'textbox') return;
256 if (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* enter on a mac */) setTimeout( function() { obj.submit(); }, 0);
259 document.getElementById('family_name').focus();
261 JSAN.use('util.file'); JSAN.use('util.widgets'); JSAN.use('util.functional');
262 util.widgets.remove_children(obj.controller.view.search_depth);
263 var ml = util.widgets.make_menulist(
264 util.functional.map_list( obj.OpenILS.data.list.aout,
266 return [ el.opac_label(), el.depth() ]
270 if (a[1] < b[1]) return -1;
271 if (a[1] > b[1]) return 1;
276 ml.addEventListener('command', function() {
277 ml.parentNode.setAttribute('value',ml.value);
278 var file = new util.file('patron_search_prefs.'+obj.OpenILS.data.server_unadorned);
279 util.widgets.save_attributes(file, { 'search_depth_ml' : [ 'value' ], 'inactive' : [ 'value' ] });
282 ml.setAttribute('id','search_depth_ml');
283 obj.controller.view.search_depth.appendChild(ml);
285 var file = new util.file('patron_search_prefs.'+obj.OpenILS.data.server_unadorned);
286 util.widgets.load_attributes(file);
287 ml.value = ml.getAttribute('value');
290 ml.setAttribute('value',ml.value);
293 var cb = obj.controller.view.inactive;
294 cb.addEventListener('command',function() {
295 cb.setAttribute('value',cb.checked ? "true" : "false");
296 var file = new util.file('patron_search_prefs.'+obj.OpenILS.data.server_unadorned);
297 util.widgets.save_attributes(file, { 'search_depth_ml' : [ 'value' ], 'inactive' : [ 'value' ] });
300 cb.checked = cb.getAttribute('value') == "true" ? true : false;
302 var menupopup = document.getElementById('profile').firstChild;
303 for (var i = 0; i < obj.OpenILS.data.list.pgt.length; i++) {
304 var my_pgt = obj.OpenILS.data.list.pgt[i];
305 var menuitem = document.createElement('menuitem');
306 menuitem.setAttribute('label',my_pgt.name());
307 menuitem.setAttribute('value',my_pgt.id());
308 menupopup.appendChild(menuitem);
312 'on_submit' : function(q) {
313 var msg = 'Query = ' + q;
314 this.error.sdump('D_PATRON', msg);
317 'submit' : function() {
318 window.xulG.clear_left_deck();
321 for (var i = 0; i < obj.controller.render_list.length; i++) {
322 var id = obj.controller.render_list[i][0];
323 var node = document.getElementById(id);
324 if (node && node.value != '') {
325 if (id == 'inactive') {
326 query[id] = node.getAttribute('value');
327 obj.error.sdump('D_DEBUG','id = ' + id + ' value = ' + node.getAttribute('value') + '\n');
328 } else if (id == 'profile') {
329 query[id] = node.selectedItem.getAttribute('value');
330 obj.error.sdump('D_DEBUG','id = ' + id + ' value = ' + node.getAttribute('value') + '\n');
332 if (id == 'search_depth') {
333 query[id] = node.firstChild.getAttribute('value');
335 var value = node.value.replace(/^\s+/,'').replace(/[\\\s]+$/,'');
336 //value = value.replace(/\d/g,'');
339 case 'first_given_name' :
340 case 'second_given_name' :
341 value = value.replace(/^[\d\s]+/g,'').replace(/[\d\s]+$/g,'')
346 obj.error.sdump('D_DEBUG','id = ' + id + ' value = ' + value + '\n');
352 if (typeof obj.on_submit == 'function') {
353 obj.on_submit(query,obj.search_limit,obj.search_sort);
355 if (typeof window.xulG == 'object'
356 && typeof window.xulG.on_submit == 'function') {
357 obj.error.sdump('D_PATRON','patron.search_form: Calling external .on_submit()\n');
358 window.xulG.on_submit(query,obj.search_limit,obj.search_sort);
360 obj.error.sdump('D_PATRON','patron.search_form: No external .on_query()\n');
366 dump('exiting patron/search_form.js\n');