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