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