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