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