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.my_aou,
266 return [ el.name(), el.id() ]
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 /* Populate the Patron Profile filter, if it exists */
303 if (obj.controller.view.profile) {
304 util.widgets.remove_children(obj.controller.view.profile);
305 var profile_ml = util.widgets.make_menulist(
306 util.functional.map_list( obj.OpenILS.data.list.pgt,
308 return [ el.name(), el.id() ]
312 if (a[0] < b[0]) return -1;
313 if (a[0] > b[0]) return 1;
318 profile_ml.addEventListener('command', function() {
319 profile_ml.parentNode.setAttribute('value', profile_ml.value);
322 profile_ml.setAttribute('id','profile_ml');
324 /* Add an empty menu item as the default profile */
325 var empty = document.createElement('menuitem');
326 profile_ml.firstChild.insertBefore(empty, profile_ml.firstChild.firstChild);
327 empty.setAttribute('label', '');
328 empty.setAttribute('value', '');
329 obj.controller.view.profile.appendChild(profile_ml);
330 profile_ml.value = profile_ml.getAttribute('value');
334 'on_submit' : function(q) {
335 var msg = 'Query = ' + q;
336 this.error.sdump('D_PATRON', msg);
339 'submit' : function() {
340 window.xulG.clear_left_deck();
343 for (var i = 0; i < obj.controller.render_list.length; i++) {
344 var id = obj.controller.render_list[i][0];
345 var node = document.getElementById(id);
346 if (node && node.value != '') {
347 if (id == 'inactive') {
348 query[id] = node.getAttribute('value');
349 obj.error.sdump('D_DEBUG','id = ' + id + ' value = ' + node.getAttribute('value') + '\n');
350 } else if (id == 'profile') {
351 query[id] = node.firstChild.getAttribute('value');
352 obj.error.sdump('D_DEBUG','id = ' + id + ' value = ' + node.getAttribute('value') + '\n');
354 if (id == 'search_depth') {
355 query[id] = node.firstChild.getAttribute('value');
357 var value = node.value.replace(/^\s+/,'').replace(/[\\\s]+$/,'');
358 //value = value.replace(/\d/g,'');
361 case 'first_given_name' :
362 case 'second_given_name' :
363 value = value.replace(/^[\d\s]+/g,'').replace(/[\d\s]+$/g,'')
368 obj.error.sdump('D_DEBUG','id = ' + id + ' value = ' + value + '\n');
374 if (typeof obj.on_submit == 'function') {
375 obj.on_submit(query,obj.search_limit,obj.search_sort);
377 if (typeof window.xulG == 'object'
378 && typeof window.xulG.on_submit == 'function') {
379 obj.error.sdump('D_PATRON','patron.search_form: Calling external .on_submit()\n');
380 window.xulG.on_submit(query,obj.search_limit,obj.search_sort);
382 obj.error.sdump('D_PATRON','patron.search_form: No external .on_query()\n');
388 dump('exiting patron/search_form.js\n');