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