Lazy Circ (AKA partial barcode lookup)
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / patron / display.js
1 dump('entering patron/display.js\n');
2 dojo.require("openils.User");
3 dojo.require("openils.XUL");
4
5 function $(id) { return document.getElementById(id); }
6
7 if (typeof patron == 'undefined') patron = {};
8 patron.display = function (params) {
9
10     JSAN.use('util.error'); this.error = new util.error();
11     JSAN.use('util.window'); this.window = new util.window();
12     JSAN.use('util.network'); this.network = new util.network();
13     JSAN.use('util.widgets'); 
14     this.w = window;
15 }
16
17 patron.display.prototype = {
18
19     'retrieve_ids' : [],
20     'stop_checkouts' : false,
21     'check_stop_checkouts' : function() { return this.stop_checkouts; },
22
23     'init' : function( params ) {
24
25         var obj = this;
26
27         obj.barcode = params['barcode'];
28         obj.id = params['id'];
29
30         JSAN.use('OpenILS.data'); this.OpenILS = {}; 
31         obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
32         
33         //var horizontal_interface = String( obj.OpenILS.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
34         //document.getElementById('ui.circ.patron_summary.horizontal').setAttribute('orient', horizontal_interface ? 'vertical' : 'horizontal');
35         //document.getElementById('pdms1').setAttribute('orient', horizontal_interface ? 'vertical' : 'horizontal');
36         
37         JSAN.use('util.deck'); 
38         obj.right_deck = new util.deck('patron_right_deck');
39         obj.left_deck = new util.deck('patron_left_deck');
40
41         JSAN.use('util.controller'); obj.controller = new util.controller();
42         obj.controller.init(
43             {
44                 control_map : {
45                     'cmd_broken' : [
46                         ['command'],
47                         function() { alert($("commonStrings").getString('common.unimplemented')); }
48                     ],
49                     'cmd_patron_retrieve' : [
50                         ['command'],
51                         function(ev) {
52                             if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
53                                 for (var i = 0; i < obj.retrieve_ids.length; i++) {    
54                                     try {
55                                         window.xulG.new_patron_tab(
56                                             {}, { 'id' : obj.retrieve_ids[i] }
57                                         );
58                                     } catch(E) {
59                                         alert(E);
60                                     }
61                                 }
62                             }
63                         }
64                     ],
65                     'cmd_patron_merge' : [
66                         ['command'],
67                         function(ev) {
68                             JSAN.use('patron.util');
69                             if (patron.util.merge( obj.retrieve_ids )) {
70                                 obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','true');
71                                 obj.controller.view.cmd_patron_merge.setAttribute('disabled','true');
72                                 var sobj = obj.search_result.g.search_result;
73                                 if ( sobj.query ) { sobj.search( sobj.query ); }
74                             }
75                         }
76                     ],
77                     'cmd_patron_toggle_summary' : [
78                         ['command'],
79                         function(ev) {
80                             document.getElementById('splitter_grippy').doCommand();
81                         }
82                     ],
83                     'cmd_patron_delete' : [
84                         ['command'],
85                         function(ev) {
86                             try {
87                                 if (get_bool( obj.patron.super_user() )) {
88                                     alert($("patronStrings").getString('staff.patron.display.cmd_patron_delete.deny_deletion_of_super_user'));
89                                     return;
90                                 }
91                                 if (obj.patron.id() == obj.OpenILS.data.list.au[0].id()) {
92                                     alert($("patronStrings").getString('staff.patron.display.cmd_patron_delete.deny_deletion_of_self'));
93                                     return;
94                                 }
95                                 var rv = obj.error.yns_alert_original(
96                                     $("patronStrings").getString('staff.patron.display.cmd_patron_delete.dialog.message'),
97                                     $("patronStrings").getString('staff.patron.display.cmd_patron_delete.dialog.title'),
98                                     $("patronStrings").getString('staff.patron.display.cmd_patron_delete.dialog.okay'),
99                                     $("patronStrings").getString('staff.patron.display.cmd_patron_delete.dialog.cancel'),
100                                     null,
101                                     $("patronStrings").getString('staff.patron.display.cmd_patron_delete.dialog.confirmation')
102                                 );
103                                 //alert('rv = ' + rv + ' (' + typeof rv + ')');
104                                 if (rv == 0) {
105                                     var params = [ ses(), obj.patron.id() ];
106                                     var staff_check = obj.network.simple_request('PERM_RETRIEVE_WORK_OU',[ ses(), 'STAFF_LOGIN', obj.patron.id() ]);
107                                     if (staff_check.length > 0) {
108                                         var dest_barcode = window.prompt(
109                                             $("patronStrings").getString('staff.patron.display.cmd_patron_delete.dest_user.prompt'),
110                                             $("patronStrings").getString('staff.patron.display.cmd_patron_delete.dest_user.default_value'),
111                                             $("patronStrings").getString('staff.patron.display.cmd_patron_delete.dest_user.title')
112                                         );
113                                         if (!dest_barcode) return;
114                                         JSAN.use('patron.util');
115                                         var dest_usr = patron.util.retrieve_fleshed_au_via_barcode( ses(), dest_barcode );
116                                         if (typeof dest_usr.ilsevent != 'undefined') {
117                                             alert( $("patronStrings").getString('staff.patron.display.cmd_patron_delete.dest_user.failure') );
118                                             return;
119                                         }
120                                         if (dest_usr.id() == obj.patron.id()) {
121                                             alert( $("patronStrings").getString('staff.patron.display.cmd_patron_delete.dest_user.self_reference_failure') );
122                                             return;
123                                         }
124                                         params.push( dest_usr.id() );
125                                     }
126                                     obj.network.simple_request( 'FM_AU_DELETE', params );
127                                     obj.refresh_all();
128                                 }
129                             } catch(E) {
130                                 obj.error.standard_unexpected_error_alert('Error in server/patron/display.js -> cmd_patron_delete: ',E);
131                             }
132                         }
133                     ],
134                     'cmd_search_form' : [
135                         ['command'],
136                         function(ev) {
137                             obj.controller.view.cmd_search_form.setAttribute('disabled','true');
138                             obj.left_deck.node.selectedIndex = 0;
139                             obj.controller.view.patron_name.setAttribute('value', $("patronStrings").getString('staff.patron.display.cmd_search_form.no_patron'));
140                             obj.controller.view.patron_name.setAttribute('tooltiptext', '');
141                             obj.controller.view.patron_name.setAttribute('onclick', '');
142                             removeCSSClass(document.documentElement,'PATRON_HAS_BILLS');
143                             removeCSSClass(document.documentElement,'PATRON_HAS_OVERDUES');
144                             removeCSSClass(document.documentElement,'PATRON_HAS_NOTES');
145                             removeCSSClass(document.documentElement,'PATRON_EXCEEDS_CHECKOUT_COUNT');
146                             removeCSSClass(document.documentElement,'PATRON_EXCEEDS_OVERDUE_COUNT');
147                             removeCSSClass(document.documentElement,'PATRON_EXCEEDS_FINES');
148                             removeCSSClass(document.documentElement,'NO_PENALTIES');
149                             removeCSSClass(document.documentElement,'ONE_PENALTY');
150                             removeCSSClass(document.documentElement,'MULTIPLE_PENALTIES');
151                             removeCSSClass(document.documentElement,'PATRON_HAS_ALERT');
152                             removeCSSClass(document.documentElement,'PATRON_BARRED');
153                             removeCSSClass(document.documentElement,'PATRON_INACTIVE');
154                             removeCSSClass(document.documentElement,'PATRON_EXPIRED');
155                             removeCSSClass(document.documentElement,'PATRON_HAS_INVALID_DOB');
156                             removeCSSClass(document.documentElement,'PATRON_JUVENILE');
157                             removeCSSClass(document.documentElement,'PATRON_HAS_INVALID_ADDRESS');
158                             removeCSSClass(document.documentElement,'PATRON_AGE_GE_65');
159                             removeCSSClass(document.documentElement,'PATRON_AGE_LT_65');
160                             removeCSSClass(document.documentElement,'PATRON_AGE_GE_24');
161                             removeCSSClass(document.documentElement,'PATRON_AGE_LT_24');
162                             removeCSSClass(document.documentElement,'PATRON_AGE_GE_21');
163                             removeCSSClass(document.documentElement,'PATRON_AGE_LT_21');
164                             removeCSSClass(document.documentElement,'PATRON_AGE_GE_18');
165                             removeCSSClass(document.documentElement,'PATRON_AGE_LT_18');
166                             removeCSSClass(document.documentElement,'PATRON_AGE_GE_13');
167                             removeCSSClass(document.documentElement,'PATRON_AGE_LT_13');
168                             removeCSSClass(document.documentElement,'PATRON_NET_ACCESS_1');
169                             removeCSSClass(document.documentElement,'PATRON_NET_ACCESS_2');
170                             removeCSSClass(document.documentElement,'PATRON_NET_ACCESS_3');
171                         }
172                     ],
173                     'cmd_patron_refresh' : [
174                         ['command'],
175                         function(ev) {
176                             try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_refresh" ) ); } catch(E) {};
177                             obj.network.simple_request(
178                                 'RECALCULATE_STANDING_PENALTIES',
179                                 [ ses(), obj.patron.id() ]
180                             );
181                             obj.refresh_all();
182                         }
183                     ],
184                     'cmd_patron_checkout' : [
185                         ['command'],
186                         function(ev) {
187                             obj.reset_nav_styling('cmd_patron_checkout');
188                             obj.spawn_checkout_interface();
189                         }
190                     ],
191                     'cmd_patron_items' : [
192                         ['command'],
193                         function(ev) {
194                             try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_items" ) ); } catch(E) {};
195                             obj.reset_nav_styling('cmd_patron_items');
196                             var frame = obj.right_deck.set_iframe(
197                                 urls.XUL_PATRON_ITEMS,
198                                 //+ '?patron_id=' + window.escape( obj.patron.id() ),
199                                 {},
200                                 {
201                                     'patron_id' : obj.patron.id(),
202                                     'on_list_change' : function(b) {
203                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
204                                         obj.summary_window.g.summary.controller.render('patron_checkouts');
205                                         obj.summary_window.g.summary.controller.render('patron_standing_penalties');
206                                         obj.summary_window.g.summary.controller.render('patron_bill');
207                                         obj.bill_window.g.bills.refresh(true);
208                                     },
209                                     'url_prefix' : function(url) { return xulG.url_prefix(url); },
210                                     'get_new_session' : function(a) { return xulG.get_new_session(a); },
211                                     'new_tab' : function(a,b,c) { return xulG.new_tab(a,b,c); },
212                                     'new_patron_tab' : function(a,b) { return xulG.new_patron_tab(a,b); }
213                                 }
214                             );
215                             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
216                             obj.items_window = get_contentWindow(frame);
217                         }
218                     ],
219                     'cmd_patron_edit' : [
220                         ['command'],
221                         function(ev) {
222                                 try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_edit" ) ); } catch(E) {};
223                                 obj.reset_nav_styling('cmd_patron_edit');
224
225                                 function spawn_search(s) {
226                                     obj.error.sdump('D_TRACE', 'Editor would like to search for: ' + js2JSON(s)); 
227                                     obj.OpenILS.data.stash_retrieve();
228                                     xulG.new_patron_tab( {}, { 'doit' : 1, 'query' : js2JSON(s) } );
229                                 }
230
231                                 function spawn_editor(p) {
232                                     var url = urls.XUL_PATRON_EDIT;
233                                     //var param_count = 0;
234                                     //for (var i in p) {
235                                     //    if (param_count++ == 0) url += '?'; else url += '&';
236                                     //    url += i + '=' + window.escape(p[i]);
237                                     //}
238                                     var loc = xulG.url_prefix( urls.XUL_REMOTE_BROWSER ); // + '?url=' + window.escape( url );
239                                     xulG.new_tab(
240                                         loc, 
241                                         {}, 
242                                         { 
243                                             'url' : url,
244                                             'show_print_button' : true , 
245                                             'tab_name' : $("patronStrings").getString('staff.patron.display.spawn_editor.editing_related_patron'),
246                                             'passthru_content_params' : {
247                                                 'spawn_search' : spawn_search,
248                                                 'spawn_editor' : spawn_editor,
249                                                 'url_prefix' : function(url) { return xulG.url_prefix(url); },
250                                                 'get_new_session' : function(a) { return xulG.get_new_session(a); },
251                                                 'new_tab' : function(a,b,c) { return xulG.new_tab(a,b,c); },
252                                                 'new_patron_tab' : function(a,b) { return xulG.new_patron_tab(a,b); },
253                                                 'params' : p,
254                                                 'on_save' : function(p_obj) {
255                                                     JSAN.use('patron.util');
256                                                     patron.util.work_log_patron_edit(p_obj);
257                                                 }
258                                             },
259                                             'lock_tab' : function() { return xulG.lock_tab(); },
260                                             'unlock_tab' : function() { return xulG.unlock_tab(); }
261                                         }
262                                     );
263                                 }
264
265                             obj.right_deck.set_iframe(
266                                 urls.XUL_REMOTE_BROWSER + '?patron_edit=1',
267                                 //+ '?url=' + window.escape( 
268                                 //    urls.XUL_PATRON_EDIT
269                                 //    + '?ses=' + window.escape( ses() )
270                                 //    + '&usr=' + window.escape( obj.patron.id() )
271                                 //),
272                                 {}, {
273                                     'url' : urls.XUL_PATRON_EDIT,
274                                     'show_print_button' : true,
275                                     'passthru_content_params' : {
276                                         'params' : {
277                                             'ses' : ses(),
278                                             'usr' : obj.patron.id()
279                                         },
280                                         'on_save' : function(p) {
281                                             try {
282                                                 JSAN.use('patron.util'); 
283                                                 patron.util.work_log_patron_edit(p);
284                                                 if (obj.barcode) obj.barcode = p.card().barcode();
285                                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
286                                                 //obj.summary_window.g.summary.retrieve();
287                                                 obj.refresh_all();
288                                             } catch(E) {
289                                                 alert(E);
290                                             }
291                                         },
292                                         'spawn_search' : spawn_search,
293                                         'spawn_editor' : spawn_editor,
294                                         'url_prefix' : function(url) { return xulG.url_prefix(url); },
295                                         'get_new_session' : function(a) { return xulG.get_new_session(a); },
296                                         'new_tab' : function(a,b,c) { return xulG.new_tab(a,b,c); },
297                                         'new_patron_tab' : function(a,b) { return xulG.new_patron_tab(a,b); }
298                                     },
299                                     'lock_tab' : function() { return xulG.lock_tab(); },
300                                     'unlock_tab' : function() { return xulG.unlock_tab(); }
301                                 }
302                             );
303                         }
304                     ],
305                     'cmd_patron_other' : [
306                         ['command'],
307                         function(ev) {
308                             try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_other" ) ); } catch(E) {};
309                             obj.reset_nav_styling('cmd_patron_other');
310                             try { document.getElementById('PatronNavBar_other').firstChild.showPopup(); } catch(E) {};
311                         }
312                     ],
313                     'cmd_patron_info_notes' : [
314                         ['command'],
315                         function(ev) {
316                             obj.right_deck.set_iframe(
317                                 urls.XUL_PATRON_INFO_NOTES,
318                                 {},
319                                 {
320                                     'patron_id' : obj.patron.id(),
321                                     'url_prefix' : function(url) { return xulG.url_prefix(url); },
322                                     'get_new_session' : function(a) { return xulG.get_new_session(a); },
323                                     'new_tab' : function(a,b,c) { return xulG.new_tab(a,b,c); },
324                                     'new_patron_tab' : function(a,b) { return xulG.new_patron_tab(a,b); }
325                                 }
326                             );
327                         }
328                     ],
329                     'cmd_patron_info_triggered_events' : [
330                         ['command'],
331                         function(ev) {
332                             obj.right_deck.set_iframe(
333                                 urls.XUL_TRIGGER_EVENTS,
334                                 {},
335                                 {
336                                     'patron_id' : obj.patron.id()
337                                 }
338                             );
339                         }
340                     ],
341                     'cmd_patron_info_stats' : [
342                         ['command'],
343                         function(ev) {
344                             obj.right_deck.set_iframe(
345                                 urls.XUL_PATRON_INFO_STAT_CATS,
346                                 {},
347                                 {
348                                     'patron_id' : obj.patron.id(),
349                                     'url_prefix' : function(url) { return xulG.url_prefix(url); },
350                                     'get_new_session' : function(a) { return xulG.get_new_session(a); },
351                                     'new_tab' : function(a,b,c) { return xulG.new_tab(a,b,c); },
352                                     'new_patron_tab' : function(a,b) { return xulG.new_patron_tab(a,b); }
353                                 }
354                             );
355                         }
356                     ],
357                     'cmd_patron_info_surveys' : [
358                         ['command'],
359                         function(ev) {
360                             obj.right_deck.set_iframe(
361                                 urls.XUL_PATRON_INFO_SURVEYS,
362                                 {},
363                                 {
364                                     'patron_id' : obj.patron.id(),
365                                     'url_prefix' : function(url) { return xulG.url_prefix(url); },
366                                     'get_new_session' : function(a) { return xulG.get_new_session(a); },
367                                     'new_tab' : function(a,b,c) { return xulG.new_tab(a,b,c); },
368                                     'new_patron_tab' : function(a,b) { return xulG.new_patron_tab(a,b); }
369                                 }
370                             );
371                         }
372                     ],
373                     'cmd_patron_info_groups' : [
374                         ['command'],
375                         function(ev) {
376                             obj.spawn_group_interface();
377                         }
378                     ],
379                     'cmd_patron_alert' : [
380                         ['command'],
381                         function(ev) {
382                             if (obj.msg_url) {
383                                 obj.right_deck.set_iframe('data:text/html,'+obj.msg_url,{},{});
384                             } else {
385                                 obj.right_deck.set_iframe('data:text/html,<h1>' + $("patronStrings").getString('staff.patron.display.no_alerts_or_messages') + '</h1>',{},{});
386                             }
387                         }
388                     ],
389                     'cmd_patron_reservation' : [
390                         ['command'],
391                         function(ev) {
392                             openils.XUL.newTabEasy(
393                                 "/eg/booking/reservation",
394                                 $("offlineStrings").getString(
395                                     "menu.cmd_booking_reservation.tab"
396                                 ), {
397                                     "bresv_interface_opts": {
398                                         "patron_barcode":
399                                             obj.patron.card().barcode()
400                                     }
401                                 },
402                                 true
403                             );
404                         }
405                     ],
406                     'cmd_patron_reservation_pickup' : [
407                         ['command'],
408                         function(ev) {
409                             openils.XUL.newTabEasy(
410                                 "/eg/booking/pickup",
411                                 $("offlineStrings").getString(
412                                     "menu.cmd_booking_reservation_pickup.tab"
413                                 ), {
414                                     "bresv_interface_opts": {
415                                         "patron_barcode":
416                                             obj.patron.card().barcode()
417                                     }
418                                 },
419                                 true
420                             );
421                         }
422                     ],
423                     'cmd_patron_reservation_return' : [
424                         ['command'],
425                         function(ev) {
426                             openils.XUL.newTabEasy(
427                                 "/eg/booking/return",
428                                 $("offlineStrings").getString(
429                                     "menu.cmd_booking_reservation_return.tab"
430                                 ), {
431                                     "bresv_interface_opts": {
432                                         "patron_barcode":
433                                             obj.patron.card().barcode()
434                                     }
435                                 },
436                                 true
437                             );
438                         }
439                     ],
440                     'cmd_patron_exit' : [
441                         ['command'],
442                         function(ev) {
443                             xulG.set_tab(urls.XUL_PATRON_BARCODE_ENTRY,{},{});
444                         }
445                     ],
446                     'cmd_patron_holds' : [
447                         ['command'],
448                         function(ev) {
449                             try {
450                                 try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_holds" ) ); } catch(E) {};
451                                 obj.reset_nav_styling('cmd_patron_holds');
452                                 obj.right_deck.set_iframe(
453                                     urls.XUL_PATRON_HOLDS,    
454                                     //+ '?patron_id=' + window.escape( obj.patron.id() ),
455                                     {},
456                                     {
457                                         'display_window' : window,
458                                         'patron_id' : obj.patron.id(),
459                                         'patron_barcode' : obj.patron.card().barcode(),
460                                         'on_list_change' : function(h) {
461                                             try {
462                                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
463                                                 obj.summary_window.g.summary.controller.render('patron_holds');
464                                             } catch(E) {
465                                                 alert(E);
466                                             }
467                                         },
468                                         'url_prefix' : function(url) { return xulG.url_prefix(url); },
469                                         'get_new_session' : function(a) { return xulG.get_new_session(a); },
470                                         'new_tab' : function(a,b,c) { return xulG.new_tab(a,b,c); },
471                                         'new_patron_tab' : function(a,b) { return xulG.new_patron_tab(a,b); }
472                                     }
473                                 );
474                             } catch(E) {
475                                 alert(E);
476                             }
477                         }
478                     ],
479                     'cmd_patron_bills' : [
480                         ['command'],
481                         function(ev) {
482                             try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_bills" ) ); } catch(E) {};
483                             obj.reset_nav_styling('cmd_patron_bills');
484                             var f = obj.right_deck.set_iframe(
485                                 urls.XUL_PATRON_BILLS,
486                                 //+ '?patron_id=' + window.escape( obj.patron.id() ),
487                                 {},
488                                 {
489                                     'display_window' : window,
490                                     'patron_id' : obj.patron.id(),
491                                     'url_prefix' : function(url) { return xulG.url_prefix(url); },
492                                     'get_new_session' : function(a) { return xulG.get_new_session(a); },
493                                     'new_tab' : function(a,b,c) { return xulG.new_tab(a,b,c); },
494                                     'on_money_change' : function(b) {
495                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
496                                         obj.summary_window.refresh();
497                                     }
498                                 }
499                             );
500                             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
501                             obj.bill_window = get_contentWindow(f);
502                         }
503                     ],
504                     'patron_name' : [
505                         ['render'],
506                         function(e) {
507                             return function() { 
508                                 JSAN.use('patron.util'); 
509                                 e.setAttribute('value',
510                                     patron.util.format_name( obj.patron )
511                                 );
512                                 patron.util.set_penalty_css(obj.patron);
513                                 var tooltiptext = $("patronStrings").getFormattedString(
514                                     'staff.patron.display.db_data',
515                                     [
516                                         obj.patron.id(),
517                                         obj.patron.create_date()
518                                     ]
519                                 );
520                                 e.setAttribute('tooltiptext',tooltiptext);
521                                 e.setAttribute('onclick','try { copy_to_clipboard(event); } catch(E) { alert(E); }');
522                             };
523                         }
524                     ],
525                     'PatronNavBar' : [
526                         ['render'],
527                         function(e) {
528                             return function() {}
529                         }
530                     ],
531                     'cmd_verify_credentials' : [
532                         ['command'],
533                         function() {
534                             var vframe = obj.right_deck.reset_iframe(
535                                 urls.XUL_VERIFY_CREDENTIALS,
536                                 {},
537                                 {
538                                     'barcode' : obj.patron.card().barcode(),
539                                     'usrname' : obj.patron.usrname()
540                                 }
541                             );
542                         } 
543                     ],
544                     'cmd_perm_editor' : [
545                         ['command'],
546                         function() {
547                              var frame = obj.right_deck.reset_iframe( urls.XUL_USER_PERM_EDITOR + '?ses=' + window.escape(ses()) + '&usr=' + obj.patron.id(), {}, {});
548                         }
549                     ],
550                     'cmd_standing_penalties' : [
551                         ['command'],
552                         function() {
553                             function penalty_interface() {
554                                 try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_messages" ) ); } catch(E) {};
555                                 obj.reset_nav_styling('cmd_standing_penalties');
556                                 return obj.right_deck.set_iframe(
557                                     urls.XUL_STANDING_PENALTIES,
558                                     {},
559                                     {
560                                         'patron' : obj.patron,
561                                         'refresh' : function() { 
562                                             obj.refresh_all(); 
563                                         }
564                                     }
565                                 );
566                             }
567                             penalty_interface();
568                         } 
569                     ]
570                 }
571             }
572         );
573
574         var x = document.getElementById("PatronNavBar_checkout");
575         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
576         var x = document.getElementById("PatronNavBar_refresh");
577         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
578         var x = document.getElementById("PatronNavBar_items");
579         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
580         var x = document.getElementById("PatronNavBar_holds");
581         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
582         var x = document.getElementById("PatronNavBar_other");
583         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
584         var x = document.getElementById("PatronNavBar_edit");
585         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
586         var x = document.getElementById("PatronNavBar_bills");
587         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
588         var x = document.getElementById("PatronNavBar_messages");
589         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
590
591         if (obj.barcode || obj.id) {
592             if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
593                 try { window.xulG.set_tab_name($("patronStrings").getString('staff.patron.display.init.retrieving_patron')); } catch(E) { alert(E); }
594             }
595
596             obj.controller.view.PatronNavBar.selectedIndex = 1;
597             JSAN.use('util.widgets'); 
598             util.widgets.enable_accesskeys_in_node_and_children(
599                 obj.controller.view.PatronNavBar.lastChild
600             );
601             util.widgets.disable_accesskeys_in_node_and_children(
602                 obj.controller.view.PatronNavBar.firstChild
603             );
604             obj.controller.view.cmd_patron_refresh.setAttribute('disabled','true');
605             obj.controller.view.cmd_patron_checkout.setAttribute('disabled','true');
606             obj.controller.view.cmd_patron_items.setAttribute('disabled','true');
607             obj.controller.view.cmd_patron_holds.setAttribute('disabled','true');
608             obj.controller.view.cmd_patron_bills.setAttribute('disabled','true');
609             obj.controller.view.cmd_patron_edit.setAttribute('disabled','true');
610             obj.controller.view.patron_name.setAttribute('value', $("patronStrings").getString('staff.patron.display.init.retrieving'));
611             document.documentElement.setAttribute('class','');
612             var frame = obj.left_deck.set_iframe(
613                 urls.XUL_PATRON_SUMMARY,
614                 {},
615                 {
616                     'display_window' : window,
617                     'barcode' : obj.barcode,
618                     'id' : obj.id,
619                     'refresh' : function() { obj.refresh_all(); },
620                     'on_finished' : obj.gen_patron_summary_finish_func(params),
621                     'stop_sign_page' : obj.gen_patron_stop_sign_page_func(),
622                     'spawn_group_interface' : function() { obj.spawn_group_interface(); },
623                     'new_patron_tab' : function(a,b) { return xulG.new_patron_tab(a,b); },
624                     'new_tab' : function(a,b,c) { return xulG.new_tab(a,b,c); },
625                     'set_tab' : function(a,b,c) { return xulG.set_tab(a,b,c); },
626                     'on_error' : function(E) {
627                         try {
628                             var error;
629                             if (typeof E.ilsevent != 'undefined') {
630                                 error = E.textcode;
631                             } else {
632                                 error = js2JSON(E).substr(0,100);
633                             }
634                             location.href = urls.XUL_PATRON_BARCODE_ENTRY + '?error=' + window.escape(error);
635                         } catch(F) {
636                             alert(F);
637                         }
638                     }
639                 }
640             );
641             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
642             obj.summary_window = get_contentWindow(frame);
643
644         } else {
645             obj.render_search_form(params);
646         }
647     },
648
649     'reset_nav_styling' : function(btn,dont_hide_summary) {
650         try {
651             if (!dont_hide_summary) { dont_hide_summary = false; }
652             if (this.skip_hide_summary) {
653                 this.skip_hide_summary = false;
654                 dont_hide_summary = true;
655             }
656             this.controller.view.cmd_patron_checkout.setAttribute('style','');
657             this.controller.view.cmd_patron_items.setAttribute('style','');
658             this.controller.view.cmd_patron_edit.setAttribute('style','');
659             this.controller.view.cmd_patron_other.setAttribute('style','');
660             this.controller.view.cmd_patron_holds.setAttribute('style','');
661             this.controller.view.cmd_patron_bills.setAttribute('style','');
662             this.controller.view.cmd_standing_penalties.setAttribute('style','');
663             this.controller.view[ btn ].setAttribute('style','background: blue; color: white;');
664             var auto_hide_patron_sidebar = String( this.OpenILS.data.hash.aous['circ.auto_hide_patron_summary'] ) == 'true';
665             var x = document.getElementById('splitter_grippy'); 
666             if (x && auto_hide_patron_sidebar && ! dont_hide_summary) {
667                 if (! this.summary_hidden_once_already ) {
668                     var first_deck = x.parentNode.previousSibling;
669                     if (! first_deck.collapsed) x.doCommand();
670                     this.summary_hidden_once_already = true;
671                 }
672             }
673         } catch(E) {
674             alert(E);
675         }
676     },
677
678     'render_search_form' : function(params) {
679         var obj = this;
680             if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
681                 try { window.xulG.set_tab_name($("patronStrings").getString('staff.patron.display.render_search_form.patron_search')); } catch(E) { alert(E); }
682             }
683
684             obj.controller.view.PatronNavBar.selectedIndex = 0;
685             obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','true');
686             obj.controller.view.cmd_patron_merge.setAttribute('disabled','true');
687             obj.controller.view.cmd_search_form.setAttribute('disabled','true');
688
689             var horizontal_interface = String( obj.OpenILS.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
690             var loc = horizontal_interface ? urls.XUL_PATRON_HORIZONTAL_SEARCH_FORM : urls.XUL_PATRON_SEARCH_FORM; 
691             var my_xulG = {
692                 'clear_left_deck' : function() {
693                     setTimeout( function() {
694                         obj.left_deck.clear_all_except(loc);
695                         obj.render_search_form(params);
696                     }, 0);
697                 },
698                 'on_submit' : function(query,search_limit,search_sort) {
699                     obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','true');
700                     obj.controller.view.cmd_patron_merge.setAttribute('disabled','true');
701                     var list_frame = obj.right_deck.reset_iframe(
702                         urls.XUL_PATRON_SEARCH_RESULT, // + '?' + query,
703                         {},
704                         {
705                             'query' : query,
706                             'search_limit' : search_limit,
707                             'search_sort' : search_sort,
708                             'on_select' : function(list) {
709                                 if (!list) return;
710                                 if (list.length < 1) return;
711                                 obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','false');
712                                 if (list.length > 1) obj.controller.view.cmd_patron_merge.setAttribute('disabled','false');
713                                 obj.controller.view.cmd_search_form.setAttribute('disabled','false');
714                                 obj.retrieve_ids = list;
715                                 obj.controller.view.patron_name.setAttribute('value',$("patronStrings").getString('staff.patron.display.init.retrieving'));
716                                 document.documentElement.setAttribute('class','');
717                                 setTimeout(
718                                     function() {
719                                         var frame = obj.left_deck.set_iframe(
720                                             urls.XUL_PATRON_SUMMARY + '?id=' + window.escape(list[0]),
721                                             {},
722                                             {
723                                                 //'id' : list[0],
724                                                 'spawn_group_interface' : function() { obj.spawn_group_interface(); },
725                                                 'new_patron_tab' : function(a,b) { return xulG.new_patron_tab(a,b); },
726                                                 'new_tab' : function(a,b,c) { return xulG.new_tab(a,b,c); },
727                                                 'set_tab' : function(a,b,c) { return xulG.set_tab(a,b,c); },
728                                                 'on_finished' : function(patron) {
729                                                     obj.patron = patron;
730                                                     obj.controller.render();
731                                                 }
732                                             }
733                                         );
734                                         netscape.security.PrivilegeManager.enablePrivilege(
735                                             "UniversalXPConnect"
736                                         );
737                                         obj.summary_window = get_contentWindow(frame);
738                                         obj.patron = obj.summary_window.g.summary.patron;
739                                         obj.controller.render('patron_name');
740                                     }, 0
741                                 );
742                             }
743                         }
744                     );
745                     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
746                     obj.search_result = get_contentWindow(list_frame);
747                 }
748             };
749
750             if (params['query']) {
751                 my_xulG.query = JSON2js(params['query']);
752                 if (params.doit) my_xulG.doit = 1;
753             }
754
755             var form_frame = obj.left_deck.set_iframe(
756                 loc,
757                 {},
758                 my_xulG
759             );
760             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
761             obj.search_window = get_contentWindow(form_frame);
762             obj._already_defaulted_once = true;
763     },
764
765     '_already_defaulted_once' : false,
766
767     'refresh_deck' : function(url) {
768         var obj = this;
769         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
770         for (var i = 0; i < obj.right_deck.node.childNodes.length; i++) {
771             try {
772                 var f = obj.right_deck.node.childNodes[i];
773                 var w = get_contentWindow(f);
774                 if (url) {
775                     if (w.location.href == url) w.refresh(true);
776                 } else {
777                     if (typeof w.refresh == 'function') {
778                         w.refresh(true);
779                     }
780                 }
781
782             } catch(E) {
783                 obj.error.sdump('D_ERROR','refresh_deck: ' + E + '\n');
784             }
785         }
786     },
787     
788     'refresh_all' : function() {
789         var obj = this;
790         obj.controller.view.patron_name.setAttribute('value', $("patronStrings").getString('staff.patron.display.init.retrieving'));
791         document.documentElement.setAttribute('class','');
792         try { obj.summary_window.refresh(); } catch(E) { obj.error.sdump('D_ERROR', E + '\n'); }
793         try { obj.refresh_deck(); } catch(E) { obj.error.sdump('D_ERROR', E + '\n'); }
794     },
795
796     'spawn_checkout_interface' : function() {
797         var obj = this;
798         try {
799             try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_checkout" ) ); } catch(E) {};
800             obj.reset_nav_styling('cmd_patron_checkout',true);
801             var frame = obj.right_deck.set_iframe(
802                 urls.XUL_CHECKOUT,
803                 {},
804                 { 
805                     'set_tab' : function(a,b,c) { return xulG.set_tab(a,b,c); },
806                     'patron_id' : obj.patron.id(),
807                     'patron' : obj.patron,
808                     'check_stop_checkouts' : function() { return obj.check_stop_checkouts(); },
809                     'on_list_change' : function(checkout) {
810                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
811                         var x = obj.summary_window.g.summary.controller.view.patron_checkouts;
812                         var n = Number(x.getAttribute('value'));
813                         x.setAttribute('value',n+1);
814                     },
815                     'on_list_change_old' : function(checkout) {
816                     
817                         /* this stops noncats from getting pushed into Items Out */
818                         if (!checkout.circ.id()) return; 
819
820                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
821                         obj.summary_window.g.summary.controller.render('patron_checkouts');
822                         obj.summary_window.g.summary.controller.render('patron_standing_penalties');
823                         if (obj.items_window) {
824                             obj.items_window.g.items.list.append(
825                                 {
826                                     'row' : {
827                                         'my' : {
828                                             'circ_id' : checkout.circ.id()
829                                         }
830                                     }
831                                 }
832                             )
833                         }
834                     },
835                     'get_barcode' : xulG.get_barcode,
836                     'url_prefix' : xulG.url_prefix
837                 }
838             );
839             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
840             obj.checkout_window = get_contentWindow(frame);
841         } catch(E) {
842             alert('Error in spawn_checkout_interface(): ' + E);
843         }
844     },
845
846     'gen_patron_summary_finish_func' : function(display_params) {
847         var obj = this;
848
849         return function(patron,params) {
850             try {
851                 obj.patron = patron; obj.controller.render();
852
853                 obj.controller.view.cmd_patron_refresh.setAttribute('disabled','false');
854                 obj.controller.view.cmd_patron_checkout.setAttribute('disabled','false');
855                 obj.controller.view.cmd_patron_items.setAttribute('disabled','false');
856                 obj.controller.view.cmd_patron_holds.setAttribute('disabled','false');
857                 obj.controller.view.cmd_patron_bills.setAttribute('disabled','false');
858                 obj.controller.view.cmd_patron_edit.setAttribute('disabled','false');
859
860                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
861                     try { 
862                         window.xulG.set_tab_name(
863                             $("patronStrings").getString('staff.patron.display.tab_name')
864                                 + ' ' + patron.family_name() + ', ' + patron.first_given_name() + ' ' 
865                                 + (patron.second_given_name() ? patron.second_given_name() : '' ) 
866                         ); 
867                     } catch(E) { 
868                         obj.error.sdump('D_ERROR',E);
869                     }
870                 }
871
872                 if (!obj._already_defaulted_once) {
873                     obj._already_defaulted_once = true;
874                     if (display_params['show']) {
875                         setTimeout(
876                             function() {
877                                 switch(display_params['show']) {
878                                     case 'bills' : util.widgets.dispatch('command','cmd_patron_bills'); break;
879                                 }
880                             },
881                             0
882                         );
883                     } else {
884                         obj.spawn_checkout_interface();
885                     }
886                 }
887
888                 if (obj.stop_checkouts && obj.checkout_window) {
889                     setTimeout( function() {
890                         try {
891                             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
892                             obj.checkout_window.g.checkout.check_disable();
893                         } catch(E) { }
894                     }, 1000);
895                 }
896                             
897             } catch(E) {
898                 alert('Error in patron_summary_finish_func(): ' + E);
899             }
900         };
901     },
902
903     'gen_patron_stop_sign_page_func' : function() {
904         var obj = this;
905         // FIXME - replace this generated "stop sign" page with a dedicated XUL file or template
906         return function(patron,params) {
907             try {
908                 var msg = ''; obj.stop_checkouts = false;
909                 if (patron.alert_message())
910                     msg += $("patronStrings").getFormattedString('staff.patron.display.init.network_request.alert_message', [patron.alert_message()]);
911                 //alert('obj.barcode = ' + obj.barcode);
912                 if (obj.barcode) {
913                     if (patron.cards()) for (var i = 0; i < patron.cards().length; i++) {
914                         //alert('card #'+i+' == ' + js2JSON(patron.cards()[i]));
915                         if ( (patron.cards()[i].barcode()==obj.barcode) && ( ! get_bool(patron.cards()[i].active()) ) ) {
916                             msg += $("patronStrings").getString('staff.patron.display.init.network_request.inactive_card');
917                             obj.stop_checkouts = true;
918                         }
919                     }
920                 }
921                 if (get_bool(patron.barred())) {
922                     msg += $("patronStrings").getString('staff.patron.display.init.network_request.account_barred');
923                     obj.stop_checkouts = true;
924                 }
925                 if (!get_bool(patron.active())) {
926                     msg += $("patronStrings").getString('staff.patron.display.init.network_request.account_inactive');
927                     obj.stop_checkouts = true;
928                 }
929                 if (patron.expire_date()) {
930                     var now = new Date();
931                     now = now.getTime()/1000;
932
933                     var expire_parts = patron.expire_date().substr(0,10).split('-');
934                     expire_parts[1] = expire_parts[1] - 1;
935
936                     var expire = new Date();
937                     expire.setFullYear(expire_parts[0], expire_parts[1], expire_parts[2]);
938                     expire = expire.getTime()/1000
939
940                     if (expire < now) {
941                         msg += $("patronStrings").getString('staff.patron.display.init.network_request.account_expired');
942                     obj.stop_checkouts = true;
943                     }
944                 }
945                 var penalties = patron.standing_penalties();
946                 if (!penalties) { penalties = []; }
947                 var dl_flag_opened = false;
948                 for (var i = 0; i < penalties.length; i++) {
949                     if (penalties[i].standing_penalty().block_list() || penalties[i].standing_penalty().id() == 20 /* ALERT_NOTE */) {
950                         if (!dl_flag_opened) {
951                             msg += '<dl>';
952                             dl_flag_opened = true;
953                         }
954                         msg += '<dt>';
955                         msg += obj.OpenILS.data.hash.aou[ penalties[i].org_unit() ].shortname() + ' : ' + penalties[i].standing_penalty().label() + '<br/>';
956                         msg += '</dt><dd>';
957                         msg += penalties[i].note();
958                         msg += '</dd>';
959                     }
960                 }
961                 if (dl_flag_opened) { msg += '</dl>'; }
962                 var holds = params.holds_summary;
963                 if (holds.ready && holds.ready > 0) {
964                     msg += $("patronStrings").getFormattedString('staff.patron.display.init.holds_ready', [holds.ready]);
965                 }
966                 if (msg) {
967                     if (msg != obj.old_msg) {
968                         //obj.error.yns_alert(msg,'Alert Message','OK',null,null,'Check here to confirm this message.');
969                         document.documentElement.firstChild.focus();
970                         var data_url = window.escape("<img src='" + xulG.url_prefix('/xul/server/skin/media/images/stop_sign.png') + "'/>" + '<h1>'
971                             + $("patronStrings").getString('staff.patron.display.init.network_request.window_title') + '</h1><blockquote><p>' + msg + '</p>\r\n\r\n<pre>'
972                             + $("patronStrings").getString('staff.patron.display.init.network_request.window_message') + '</pre></blockquote>');
973                         obj.right_deck.set_iframe('data:text/html,'+data_url,{},{});
974                         obj.old_msg = msg;
975                         obj.msg_url = data_url;
976                     } else {
977                         obj.error.sdump('D_TRACE',$("patronStrings").getFormattedString('staff.patron.display.init.network_request.dump_error_message', [msg]));
978                     }
979                 }
980             } catch(E) {
981                 alert('Error in patron_stop_sign_page_func(): ' + E);
982             }
983         };
984     },
985
986     'spawn_group_interface' : function() {
987         var obj = this;
988         try {
989             obj.right_deck.set_iframe(
990                 urls.XUL_PATRON_INFO_GROUP,
991                 {},
992                 {
993                     'patron_id' : obj.patron.id(),
994                     'url_prefix' : function(url) { return xulG.url_prefix(url); },
995                     'get_new_session' : function(a) { return xulG.get_new_session(a); },
996                     'new_tab' : function(a,b,c) { return xulG.new_tab(a,b,c); },
997                     'new_patron_tab' : function(a,b) { return xulG.new_patron_tab(a,b); }
998                 }
999             );
1000         } catch(E) {
1001             alert('Error in display.js, spawn_group_interface(): ' + E);
1002         }
1003     }
1004
1005 }
1006
1007 dump('exiting patron/display.js\n');