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