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