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