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