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