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 ) {
16 obj.event_listeners = new EventListenerList();
18 // 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.
19 // 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.
20 // I'm going to place them into the "obj" scope for this instance.
21 obj.search_limit = params.query.search_limit;
22 obj.search_sort = (typeof params.query.search_sort === 'undefined') ?
24 JSON2js( params.query.search_sort ); // Let's assume this is encoded as JSON
26 obj.include_inactive = (typeof params.query.include_inactive !== 'undefined') ? params.query.include_inactive : null;
28 JSAN.use('OpenILS.data'); this.OpenILS = {};
29 obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
31 JSAN.use('util.controller'); obj.controller = new util.controller();
37 function() { alert($("commonStrings").getString('common.unimplemented')); }
39 'cmd_patron_search_submit' : [
45 'cmd_patron_search_clear' : [
48 obj.controller.render();
49 window.xulG.clear_left_deck();
56 if (params.query&¶ms.query.family_name) {
57 e.setAttribute('value',params.query.family_name);
58 e.value = params.query.family_name;
65 'first_given_name' : [
69 if (params.query&¶ms.query.first_given_name) {
70 e.setAttribute('value',params.query.first_given_name);
71 e.value = params.query.first_given_name;
78 'second_given_name' : [
82 if (params.query&¶ms.query.second_given_name) {
83 e.setAttribute('value',params.query.second_given_name);
84 e.value = params.query.second_given_name;
95 if (params.query&¶ms.query.alias) {
96 e.setAttribute('value',params.query.alias);
97 e.value = params.query.alias;
108 if (params.query&¶ms.query.usrname) {
109 e.setAttribute('value',params.query.usrname);
110 e.value = params.query.usrname;
121 if (params.query&¶ms.query.card) {
122 e.setAttribute('value',params.query.card);
123 e.value = params.query.card;
134 if (params.query&¶ms.query.email) {
135 e.setAttribute('value',params.query.email);
136 e.value = params.query.email;
147 if (params.query&¶ms.query.phone) {
148 e.setAttribute('value',params.query.phone);
149 e.value = params.query.phone;
160 if (params.query&¶ms.query.ident) {
161 e.setAttribute('value',params.query.ident);
162 e.value = params.query.ident;
163 } else if (params.query&¶ms.query.ident_value) {
164 e.setAttribute('value',params.query.ident_value);
165 e.value = params.query.ident_value;
166 } else if (params.query&¶ms.query.ident_value2) {
167 e.setAttribute('value',params.query.ident_value2);
168 e.value = params.query.ident_value2;
179 if (params.query&¶ms.query.street1) {
180 e.setAttribute('value',params.query.street1);
181 e.value = params.query.street1;
192 if (params.query&¶ms.query.street2) {
193 e.setAttribute('value',params.query.street2);
194 e.value = params.query.street2;
205 if (params.query&¶ms.query.city) {
206 e.setAttribute('value',params.query.city);
207 e.value = params.query.city;
218 if (params.query&¶ms.query.state) {
219 e.setAttribute('value',params.query.state);
220 e.value = params.query.state;
231 if (params.query&¶ms.query.post_code) {
232 e.setAttribute('value',params.query.post_code);
233 e.value = params.query.post_code;
240 'profile' : [ ['render'], function(e) {
241 return function() {};
244 'inactive' : [ ['render'], function(e) {
245 return function() {};
248 'search_depth' : [ ['render'],function(e) {
249 return function() {};
256 obj.controller.render();
257 var nl = document.getElementsByTagName('textbox');
258 for (var i = 0; i < nl.length; i++) {
259 obj.event_listeners.add(nl[i], 'keypress', function(ev) {
260 if (ev.target.tagName != 'textbox') return;
261 if (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* enter on a mac */) setTimeout( function() { obj.submit(); }, 0);
264 document.getElementById('family_name').focus();
266 JSAN.use('util.file'); JSAN.use('util.widgets'); JSAN.use('util.functional');
267 util.widgets.remove_children(obj.controller.view.search_depth);
268 var ml = util.widgets.make_menulist(
269 util.functional.map_list( obj.OpenILS.data.list.my_aou,
271 return [ el.name(), el.id() ]
275 if (a[1] < b[1]) return -1;
276 if (a[1] > b[1]) return 1;
281 obj.event_listeners.add(ml, 'command', function() {
282 ml.parentNode.setAttribute('value',ml.value);
283 var file = new util.file('patron_search_prefs.'+obj.OpenILS.data.server_unadorned);
284 util.widgets.save_attributes(file, { 'search_depth_ml' : [ 'value' ], 'inactive' : [ 'value' ] });
287 ml.setAttribute('id','search_depth_ml');
288 obj.controller.view.search_depth.appendChild(ml);
290 var file = new util.file('patron_search_prefs.'+obj.OpenILS.data.server_unadorned);
291 util.widgets.load_attributes(file);
292 ml.value = ml.getAttribute('value');
295 ml.setAttribute('value',ml.value);
298 var cb = obj.controller.view.inactive;
299 obj.event_listeners.add(cb, 'command',function() {
300 obj.include_inactive = null;
301 cb.setAttribute('value',cb.checked ? "true" : "false");
302 var file = new util.file('patron_search_prefs.'+obj.OpenILS.data.server_unadorned);
303 util.widgets.save_attributes(file, { 'search_depth_ml' : [ 'value' ], 'inactive' : [ 'value' ] });
306 if (obj.include_inactive !== null)
307 cb.checked = obj.include_inactive == "true" ? true : false;
309 cb.checked = cb.getAttribute('value') == "true" ? true : false;
311 /* Populate the Patron Profile filter, if it exists */
312 if (obj.controller.view.profile) {
313 util.widgets.remove_children(obj.controller.view.profile);
314 var profile_ml = util.widgets.make_menulist(
315 util.functional.map_list( obj.OpenILS.data.list.pgt,
317 return [ el.name(), el.id() ]
321 if (a[0] < b[0]) return -1;
322 if (a[0] > b[0]) return 1;
327 obj.event_listeners.add(profile_ml, 'command', function() {
328 profile_ml.parentNode.setAttribute('value', profile_ml.value);
331 profile_ml.setAttribute('id','profile_ml');
333 /* Add an empty menu item as the default profile */
334 var empty = document.createElement('menuitem');
335 profile_ml.firstChild.insertBefore(empty, profile_ml.firstChild.firstChild);
336 empty.setAttribute('label', '');
337 empty.setAttribute('value', '');
338 obj.controller.view.profile.appendChild(profile_ml);
339 profile_ml.value = profile_ml.getAttribute('value');
343 'cleanup' : function() {
345 obj.controller.cleanup();
346 obj.event_listeners.removeAll();
349 'on_submit' : function(q) {
350 var msg = 'Query = ' + q;
351 this.error.sdump('D_PATRON', msg);
354 'submit' : function() {
355 window.xulG.clear_left_deck();
358 for (var i = 0; i < obj.controller.render_list.length; i++) {
359 var id = obj.controller.render_list[i][0];
360 var node = document.getElementById(id);
361 if (node && node.value != '') {
362 if (id == 'inactive') {
363 query[id] = node.getAttribute('value');
364 // always include inactive when include_inactive is true
365 if (obj.include_inactive !== null)
366 query[id] = obj.include_inactive;
367 obj.error.sdump('D_DEBUG','id = ' + id + ' value = ' + node.getAttribute('value') + '\n');
368 } else if (id == 'profile') {
369 query[id] = node.firstChild.getAttribute('value');
370 obj.error.sdump('D_DEBUG','id = ' + id + ' value = ' + node.getAttribute('value') + '\n');
372 if (id == 'search_depth') {
373 query[id] = node.firstChild.getAttribute('value');
375 var value = node.value.replace(/^\s+/,'').replace(/[\\\s]+$/,'');
376 //value = value.replace(/\d/g,'');
379 case 'first_given_name' :
380 case 'second_given_name' :
381 value = value.replace(/^[\d\s]+/g,'').replace(/[\d\s]+$/g,'')
386 obj.error.sdump('D_DEBUG','id = ' + id + ' value = ' + value + '\n');
392 if (typeof obj.on_submit == 'function') {
393 obj.on_submit(query,obj.search_limit,obj.search_sort);
395 if (typeof window.xulG == 'object'
396 && typeof window.xulG.on_submit == 'function') {
397 obj.error.sdump('D_PATRON','patron.search_form: Calling external .on_submit()\n');
398 window.xulG.on_submit(query,obj.search_limit,obj.search_sort);
400 obj.error.sdump('D_PATRON','patron.search_form: No external .on_query()\n');
406 dump('exiting patron/search_form.js\n');