]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/display.js
alternative horizontal patron search 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');
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                                                                                 var url = urls.XUL_PATRON_DISPLAY; //+ '?id=' + window.escape( obj.retrieve_ids[i] );
95                                                                                 window.xulG.new_tab(
96                                                                                         url, {}, { 'id' : obj.retrieve_ids[i] }
97                                                                                 );
98                                                                         } catch(E) {
99                                                                                 alert(E);
100                                                                         }
101                                                                 }
102                                                         }
103                                                 }
104                                         ],
105                     'cmd_patron_merge' : [
106                         ['command'],
107                         function(ev) {
108                             JSAN.use('patron.util');
109                             if (patron.util.merge( obj.retrieve_ids )) {
110                                 obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','true');
111                                 obj.controller.view.cmd_patron_merge.setAttribute('disabled','true');
112                                 var sobj = obj.search_result.g.search_result;
113                                 if ( sobj.query ) { sobj.search( sobj.query ); }
114                             }
115                         }
116                     ],
117                                         'cmd_search_form' : [
118                                                 ['command'],
119                                                 function(ev) {
120                                                         obj.controller.view.cmd_search_form.setAttribute('disabled','true');
121                                                         obj.left_deck.node.selectedIndex = 0;
122                                                         obj.controller.view.patron_name.setAttribute('value', $("patronStrings").getString('staff.patron.display.cmd_search_form.no_patron'));
123                                                         removeCSSClass(document.documentElement,'PATRON_HAS_BILLS');
124                                                         removeCSSClass(document.documentElement,'PATRON_HAS_OVERDUES');
125                                                         removeCSSClass(document.documentElement,'PATRON_HAS_NOTES');
126                                                         removeCSSClass(document.documentElement,'PATRON_EXCEEDS_CHECKOUT_COUNT');
127                                                         removeCSSClass(document.documentElement,'PATRON_EXCEEDS_OVERDUE_COUNT');
128                                                         removeCSSClass(document.documentElement,'PATRON_EXCEEDS_FINES');
129                                                         removeCSSClass(document.documentElement,'NO_PENALTIES');
130                                                         removeCSSClass(document.documentElement,'ONE_PENALTY');
131                                                         removeCSSClass(document.documentElement,'MULTIPLE_PENALTIES');
132                                                         removeCSSClass(document.documentElement,'PATRON_HAS_ALERT');
133                                                         removeCSSClass(document.documentElement,'PATRON_BARRED');
134                                                         removeCSSClass(document.documentElement,'PATRON_INACTIVE');
135                                                         removeCSSClass(document.documentElement,'PATRON_EXPIRED');
136                                                         removeCSSClass(document.documentElement,'PATRON_HAS_INVALID_DOB');
137                                                         removeCSSClass(document.documentElement,'PATRON_JUVENILE');
138                                                         removeCSSClass(document.documentElement,'PATRON_HAS_INVALID_ADDRESS');
139                                                         removeCSSClass(document.documentElement,'PATRON_AGE_GE_65');
140                                                         removeCSSClass(document.documentElement,'PATRON_AGE_LT_65');
141                                                         removeCSSClass(document.documentElement,'PATRON_AGE_GE_24');
142                                                         removeCSSClass(document.documentElement,'PATRON_AGE_LT_24');
143                                                         removeCSSClass(document.documentElement,'PATRON_AGE_GE_21');
144                                                         removeCSSClass(document.documentElement,'PATRON_AGE_LT_21');
145                                                         removeCSSClass(document.documentElement,'PATRON_AGE_GE_18');
146                                                         removeCSSClass(document.documentElement,'PATRON_AGE_LT_18');
147                                                         removeCSSClass(document.documentElement,'PATRON_AGE_GE_13');
148                                                         removeCSSClass(document.documentElement,'PATRON_AGE_LT_13');
149                                                         removeCSSClass(document.documentElement,'PATRON_NET_ACCESS_1');
150                                                         removeCSSClass(document.documentElement,'PATRON_NET_ACCESS_2');
151                                                         removeCSSClass(document.documentElement,'PATRON_NET_ACCESS_3');
152                                                 }
153                                         ],
154                                         'cmd_patron_refresh' : [
155                                                 ['command'],
156                                                 function(ev) {
157                             try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_refresh" ) ); } catch(E) {};
158                                                         obj.network.simple_request(
159                                                                 'RECALCULATE_STANDING_PENALTIES',
160                                                                 [ ses(), obj.patron.id() ]
161                                                         );
162                                                         obj.refresh_all();
163                                                 }
164                                         ],
165                                         'cmd_patron_checkout' : [
166                                                 ['command'],
167                                                 spawn_checkout_interface
168                                         ],
169                                         'cmd_patron_items' : [
170                                                 ['command'],
171                                                 function(ev) {
172                             try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_items" ) ); } catch(E) {};
173                                                         obj.reset_nav_styling('cmd_patron_items');
174                                                         var frame = obj.right_deck.set_iframe(
175                                                                 urls.XUL_PATRON_ITEMS,
176                                                                 //+ '?patron_id=' + window.escape( obj.patron.id() ),
177                                                                 {},
178                                                                 {
179                                                                         'patron_id' : obj.patron.id(),
180                                                                         'on_list_change' : function(b) {
181                                                                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
182                                                                                 obj.summary_window.g.summary.controller.render('patron_checkouts');
183                                                                                 obj.summary_window.g.summary.controller.render('patron_standing_penalties');
184                                                                                 obj.summary_window.g.summary.controller.render('patron_bill');
185                                                                                 obj.bill_window.g.bills.refresh(true);
186                                                                         },
187                                                                         'url_prefix' : xulG.url_prefix,
188                                                                         'new_tab' : xulG.new_tab
189                                                                 }
190                                                         );
191                                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
192                                                         obj.items_window = get_contentWindow(frame);
193                                                 }
194                                         ],
195                                         'cmd_patron_edit' : [
196                                                 ['command'],
197                                                 function(ev) {
198                                 try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_edit" ) ); } catch(E) {};
199                                                                 obj.reset_nav_styling('cmd_patron_edit');
200
201                                                                 function spawn_search(s) {
202                                                                         obj.error.sdump('D_TRACE', $("commonStrings").getFormattedString('staff.patron.display.cmd_patron_edit.edit_search', [js2JSON(s)]) ); 
203                                                                         obj.OpenILS.data.stash_retrieve();
204                                                                         var loc = xulG.url_prefix(urls.XUL_PATRON_DISPLAY);
205                                                                         //loc += '?doit=1&query=' + window.escape(js2JSON(s));
206                                                                         xulG.new_tab( loc, {}, { 'doit' : 1, 'query' : s } );
207                                                                 }
208
209                                                                 function spawn_editor(p) {
210                                                                         var url = urls.XUL_PATRON_EDIT;
211                                                                         //var param_count = 0;
212                                                                         //for (var i in p) {
213                                                                         //      if (param_count++ == 0) url += '?'; else url += '&';
214                                                                         //      url += i + '=' + window.escape(p[i]);
215                                                                         //}
216                                                                         var loc = xulG.url_prefix( urls.XUL_REMOTE_BROWSER ); // + '?url=' + window.escape( url );
217                                                                         xulG.new_tab(
218                                                                                 loc, 
219                                                                                 {}, 
220                                                                                 { 
221                                                                                         'url' : url,
222                                                                                         'show_print_button' : true , 
223                                                                                         'tab_name' : $("patronStrings").getString('staff.patron.display.spawn_editor.editing_related_patron'),
224                                                                                         'passthru_content_params' : {
225                                                                                                 'spawn_search' : spawn_search,
226                                                                                                 'spawn_editor' : spawn_editor,
227                                                                                                 'url_prefix' : xulG.url_prefix,
228                                                                                                 'new_tab' : xulG.new_tab,
229                                                                                                 'params' : p
230                                                                                         }
231                                                                                 }
232                                                                         );
233                                                                 }
234
235                                                         obj.right_deck.set_iframe(
236                                                                 urls.XUL_REMOTE_BROWSER + '?patron_edit=1',
237                                                                 //+ '?url=' + window.escape( 
238                                                                 //      urls.XUL_PATRON_EDIT
239                                                                 //      + '?ses=' + window.escape( ses() )
240                                                                 //      + '&usr=' + window.escape( obj.patron.id() )
241                                                                 //),
242                                                                 {}, {
243                                                                         'url' : urls.XUL_PATRON_EDIT,
244                                                                         'show_print_button' : true,
245                                                                         'passthru_content_params' : {
246                                                                                 'params' : {
247                                                                                         'ses' : ses(),
248                                                                                         'usr' : obj.patron.id()
249                                                                                 },
250                                                                                 'on_save' : function(p) {
251                                                                                         try {
252                                                                                                 if (obj.barcode) obj.barcode = p.card().barcode();
253                                                                                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
254                                                                                                 //obj.summary_window.g.summary.retrieve();
255                                                                                                 obj.refresh_all();
256                                                                                         } catch(E) {
257                                                                                                 alert(E);
258                                                                                         }
259                                                                                 },
260                                                                                 'spawn_search' : spawn_search,
261                                                                                 'spawn_editor' : spawn_editor,
262                                                                                 'url_prefix' : xulG.url_prefix,
263                                                                                 'new_tab' : xulG.new_tab
264                                                                         }
265                                                                 }
266                                                         );
267                                                 }
268                                         ],
269                     'cmd_patron_other' : [
270                                                 ['command'],
271                                                 function(ev) {
272                             try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_other" ) ); } catch(E) {};
273                                                         obj.reset_nav_styling('cmd_patron_other');
274                             try { document.getElementById('PatronNavBar_other').firstChild.showPopup(); } catch(E) {};
275                         }
276                     ],
277                                         'cmd_patron_info' : [
278                                                 ['command'],
279                                                 function(ev) {
280                                                         obj.right_deck.set_iframe(
281                                                                 urls.XUL_PATRON_INFO, // + '?patron_id=' + window.escape( obj.patron.id() ),
282                                                                 {},
283                                                                 {
284                                                                         'patron_id' : obj.patron.id(),
285                                                                         'url_prefix' : xulG.url_prefix,
286                                                                         'new_tab' : xulG.new_tab
287                                                                 }
288                                                         );
289                                                 }
290                                         ],
291                     'cmd_patron_alert' : [
292                         ['command'],
293                         function(ev) {
294                             if (obj.msg_url) {
295                                 obj.right_deck.set_iframe('data:text/html,'+obj.msg_url,{},{});
296                             } else {
297                                 obj.right_deck.set_iframe('data:text/html,<h1>' + $("patronStrings").getString('staff.patron.display.no_alerts_or_messages') + '</h1>',{},{});
298                             }
299                         }
300                     ],
301                                         'cmd_patron_exit' : [
302                                                 ['command'],
303                                                 function(ev) {
304                                                         xulG.set_tab(urls.XUL_PATRON_BARCODE_ENTRY,{},{});
305                                                 }
306                                         ],
307                                         'cmd_patron_holds' : [
308                                                 ['command'],
309                                                 function(ev) {
310                             try {
311                                 try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_holds" ) ); } catch(E) {};
312                                 obj.reset_nav_styling('cmd_patron_holds');
313                                 obj.right_deck.set_iframe(
314                                     urls.XUL_PATRON_HOLDS,      
315                                     //+ '?patron_id=' + window.escape( obj.patron.id() ),
316                                     {},
317                                     {
318                                         'display_window' : window,
319                                         'patron_id' : obj.patron.id(),
320                                         'patron_barcode' : obj.patron.card().barcode(),
321                                         'on_list_change' : function(h) {
322                                             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
323                                             //obj.summary_window.g.summary.controller.render('patron_holds');
324                                             //obj.summary_window.g.summary.controller.render('patron_standing_penalties');
325                                             obj.refresh_all();
326                                         },
327                                         'url_prefix' : xulG.url_prefix,
328                                         'new_tab' : xulG.new_tab
329                                     }
330                                 );
331                             } catch(E) {
332                                 alert(E);
333                             }
334                                                 }
335                                         ],
336                                         'cmd_patron_bills' : [
337                                                 ['command'],
338                                                 function(ev) {
339                             try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible( document.getElementById("PatronNavBar_bills" ) ); } catch(E) {};
340                                                         obj.reset_nav_styling('cmd_patron_bills');
341                                                         var f = obj.right_deck.set_iframe(
342                                                                 urls.XUL_PATRON_BILLS,
343                                                                 //+ '?patron_id=' + window.escape( obj.patron.id() ),
344                                                                 {},
345                                                                 {
346                                                                         'patron_id' : obj.patron.id(),
347                                                                         'url_prefix' : xulG.url_prefix,
348                                                                         'on_money_change' : function(b) {
349                                                                                 //alert('test');
350                                                                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
351                                                                                 //obj.summary_window.g.summary.retrieve(true);
352                                                                                 //obj.items_window.g.items.retrieve(true);
353                                                                                 obj.refresh_all();
354                                                                         }
355                                                                 }
356                                                         );
357                                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
358                                                         obj.bill_window = get_contentWindow(f);
359                                                 }
360                                         ],
361                                         'patron_name' : [
362                                                 ['render'],
363                                                 function(e) {
364                                                         return function() { 
365                                                                 e.setAttribute('value',
366                                                                         ( obj.patron.prefix() ? obj.patron.prefix() + ' ' : '') + 
367                                                                         obj.patron.family_name() + ', ' + 
368                                                                         obj.patron.first_given_name() + ' ' +
369                                                                         ( obj.patron.second_given_name() ? obj.patron.second_given_name() + ' ' : '' ) +
370                                                                         ( obj.patron.suffix() ? obj.patron.suffix() : '')
371                                                                 );
372                                                                 JSAN.use('patron.util'); patron.util.set_penalty_css(obj.patron);
373                                                         };
374                                                 }
375                                         ],
376                                         'PatronNavBar' : [
377                                                 ['render'],
378                                                 function(e) {
379                                                         return function() {}
380                                                 }
381                                         ],
382                     'cmd_verify_credentials' : [
383                         ['command'],
384                         function() {
385                             var vframe = obj.right_deck.reset_iframe(
386                                 urls.XUL_VERIFY_CREDENTIALS,
387                                 {},
388                                 {
389                                     'barcode' : obj.patron.card().barcode(),
390                                     'usrname' : obj.patron.usrname()
391                                 }
392                             );
393                         } 
394                     ],
395                     'cmd_perm_editor' : [
396                         ['command'],
397                         function() {
398                              var frame = obj.right_deck.reset_iframe( urls.XUL_USER_PERM_EDITOR + '?ses=' + window.escape(ses()) + '&usr=' + obj.patron.id(), {}, {});
399                         }
400                     ],
401                     'cmd_standing_penalties' : [
402                         ['command'],
403                         function() {
404                             function penalty_interface() {
405                                 return obj.right_deck.reset_iframe(
406                                     urls.XUL_STANDING_PENALTIES,
407                                     {},
408                                     {
409                                         'patron' : obj.patron,
410                                         'refresh' : function() { 
411                                             obj.refresh_all(); 
412                                         }
413                                     }
414                                 );
415                             }
416                             penalty_interface();
417                         } 
418                     ]
419                                 }
420                         }
421                 );
422
423         var x = document.getElementById("PatronNavBar_checkout");
424         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
425         var x = document.getElementById("PatronNavBar_refresh");
426         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
427         var x = document.getElementById("PatronNavBar_items");
428         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
429         var x = document.getElementById("PatronNavBar_holds");
430         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
431         var x = document.getElementById("PatronNavBar_other");
432         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
433         var x = document.getElementById("PatronNavBar_edit");
434         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
435         var x = document.getElementById("PatronNavBar_bills");
436         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
437         var x = document.getElementById("PatronNavBar_exit");
438         x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
439
440                 if (obj.barcode || obj.id) {
441                         if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
442                                 try { window.xulG.set_tab_name($("patronStrings").getString('staff.patron.display.init.retrieving_patron')); } catch(E) { alert(E); }
443                         }
444
445                         obj.controller.view.PatronNavBar.selectedIndex = 1;
446                         JSAN.use('util.widgets'); 
447                         util.widgets.enable_accesskeys_in_node_and_children(
448                                 obj.controller.view.PatronNavBar.lastChild
449                         );
450                         util.widgets.disable_accesskeys_in_node_and_children(
451                                 obj.controller.view.PatronNavBar.firstChild
452                         );
453                         obj.controller.view.cmd_patron_refresh.setAttribute('disabled','true');
454                         obj.controller.view.cmd_patron_checkout.setAttribute('disabled','true');
455                         obj.controller.view.cmd_patron_items.setAttribute('disabled','true');
456                         obj.controller.view.cmd_patron_holds.setAttribute('disabled','true');
457                         obj.controller.view.cmd_patron_bills.setAttribute('disabled','true');
458                         obj.controller.view.cmd_patron_edit.setAttribute('disabled','true');
459                         obj.controller.view.patron_name.setAttribute('value', $("patronStrings").getString('staff.patron.display.init.retrieving'));
460                         document.documentElement.setAttribute('class','');
461                         var frame = obj.left_deck.set_iframe(
462                                 urls.XUL_PATRON_SUMMARY,
463                                 {},
464                                 {
465                     'display_window' : window,
466                                         'barcode' : obj.barcode,
467                                         'id' : obj.id,
468                     'refresh' : function() { obj.refresh_all(); },
469                                         'on_finished' : function(patron) {
470
471                                                 obj.patron = patron; obj.controller.render();
472
473                                                 obj.controller.view.cmd_patron_refresh.setAttribute('disabled','false');
474                                                 obj.controller.view.cmd_patron_checkout.setAttribute('disabled','false');
475                                                 obj.controller.view.cmd_patron_items.setAttribute('disabled','false');
476                                                 obj.controller.view.cmd_patron_holds.setAttribute('disabled','false');
477                                                 obj.controller.view.cmd_patron_bills.setAttribute('disabled','false');
478                                                 obj.controller.view.cmd_patron_edit.setAttribute('disabled','false');
479
480                                                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
481                                                         try { 
482                                                                 window.xulG.set_tab_name(
483                                                                         $("patronStrings").getString('staff.patron.display.tab_name')
484                                                                                 + ' ' + patron.family_name() + ', ' + patron.first_given_name() + ' ' 
485                                                                                 + (patron.second_given_name() ? patron.second_given_name() : '' ) 
486                                                                 ); 
487                                                         } catch(E) { 
488                                                                 obj.error.sdump('D_ERROR',E);
489                                                         }
490                                                 }
491
492                                                 if (!obj._checkout_spawned) {
493                                                         spawn_checkout_interface();
494                                                         obj._checkout_spawned = true;
495                                                 }
496
497                                                 obj.network.simple_request(
498                                                         'FM_AHR_COUNT_RETRIEVE.authoritative',
499                                                         [ ses(), patron.id() ],
500                                                         function(req) {
501                                                                 try {
502                                                                         var msg = ''; obj.stop_checkouts = false;
503                                                                         if (patron.alert_message())
504                                                                                 msg += $("patronStrings").getFormattedString('staff.patron.display.init.network_request.alert_message', [patron.alert_message()]);
505                                                                         //alert('obj.barcode = ' + obj.barcode);
506                                                                         if (obj.barcode) {
507                                                                                 if (patron.cards()) for (var i = 0; i < patron.cards().length; i++) {
508                                                                                         //alert('card #'+i+' == ' + js2JSON(patron.cards()[i]));
509                                                                                         if ( (patron.cards()[i].barcode()==obj.barcode) && ( ! get_bool(patron.cards()[i].active()) ) ) {
510                                                                                                 msg += $("patronStrings").getString('staff.patron.display.init.network_request.inactive_card');
511                                                                                                 obj.stop_checkouts = true;
512                                                                                         }
513                                                                                 }
514                                                                         }
515                                                                         if (get_bool(patron.barred())) {
516                                                                                 msg += $("patronStrings").getString('staff.patron.display.init.network_request.account_barred');
517                                                                                 obj.stop_checkouts = true;
518                                                                         }
519                                                                         if (!get_bool(patron.active())) {
520                                                                                 msg += $("patronStrings").getString('staff.patron.display.init.network_request.account_inactive');
521                                                                                 obj.stop_checkouts = true;
522                                                                         }
523                                                                         if (patron.expire_date()) {
524                                                                                 var now = new Date();
525                                                                                 now = now.getTime()/1000;
526
527                                                                                 var expire_parts = patron.expire_date().substr(0,10).split('-');
528                                                                                 expire_parts[1] = expire_parts[1] - 1;
529
530                                                                                 var expire = new Date();
531                                                                                 expire.setFullYear(expire_parts[0], expire_parts[1], expire_parts[2]);
532                                                                                 expire = expire.getTime()/1000
533
534                                                                                 if (expire < now) {
535                                                                                         msg += $("patronStrings").getString('staff.patron.display.init.network_request.account_expired');
536                                                                                 obj.stop_checkouts = true;
537                                                                                 }
538                                                                         }
539                                                                     var penalties = obj.patron.standing_penalties();
540                                                                     for (var i = 0; i < penalties.length; i++) {
541                                         if (penalties[i].standing_penalty().block_list()) {
542                                             msg += obj.OpenILS.data.hash.aou[ penalties[i].org_unit() ].shortname() + ' : ' + penalties[i].standing_penalty().label() + '<br/>';
543                                         }
544                                     }
545                                                                         var holds = req.getResultObject();
546                                                                         if (holds.ready && holds.ready > 0) {
547                                                                                 msg += $("patronStrings").getFormattedString('staff.patron.display.init.holds_ready', [holds.ready]);
548                                                                         }
549                                                                         if (msg) {
550                                                                                 if (msg != obj.old_msg) {
551                                                                                         //obj.error.yns_alert(msg,'Alert Message','OK',null,null,'Check here to confirm this message.');
552                                                                                         document.documentElement.firstChild.focus();
553                                                                                         var data_url = window.escape("<img src='" + xulG.url_prefix('/xul/server/skin/media/images/stop_sign.png') + "'/>" + '<h1>'
554                                                                                                 + $("patronStrings").getString('staff.patron.display.init.network_request.window_title') + '</h1><blockquote><p>' + msg + '</p>\r\n\r\n<pre>'
555                                                                                                 + $("patronStrings").getString('staff.patron.display.init.network_request.window_message') + '</pre></blockquote>');
556                                                                                         obj.right_deck.set_iframe('data:text/html,'+data_url,{},{});
557                                                                                         obj.old_msg = msg;
558                                             obj.msg_url = data_url;
559                                                                                 } else {
560                                                                                         obj.error.sdump('D_TRACE',$("patronStrings").getFormattedString('staff.patron.display.init.network_request.dump_error_message', [msg]));
561                                                                                 }
562                                                                         }
563                                                                         if (obj.stop_checkouts && obj.checkout_window) {
564                                                                                 setTimeout( function() {
565                                                                                         try {
566                                                                                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
567                                                                                                 obj.checkout_window.g.checkout.check_disable();
568                                                                                         } catch(E) { }
569                                                                                 }, 1000);
570                                                                         }
571                                                                 } catch(E) {
572                                                                         obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.display.init.network_request.error_showing_alert'),E);
573                                                                 }
574                                                         }
575                                                 );
576
577                                         },
578                                         'on_error' : function(E) {
579                                                 try {
580                                                         var error;
581                                                         if (typeof E.ilsevent != 'undefined') {
582                                                                 error = E.textcode;
583                                                         } else {
584                                                                 error = js2JSON(E).substr(0,100);
585                                                         }
586                                                         location.href = urls.XUL_PATRON_BARCODE_ENTRY + '?error=' + window.escape(error);
587                                                 } catch(F) {
588                                                         alert(F);
589                                                 }
590                                         }
591                                 }
592                         );
593                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
594                         obj.summary_window = get_contentWindow(frame);
595                 } else {
596                         obj.render_search_form(params);
597                 }
598         },
599
600         'reset_nav_styling' : function(btn) {
601         try {
602             this.controller.view.cmd_patron_checkout.setAttribute('style','');
603             this.controller.view.cmd_patron_items.setAttribute('style','');
604             this.controller.view.cmd_patron_edit.setAttribute('style','');
605             this.controller.view.cmd_patron_other.setAttribute('style','');
606             this.controller.view.cmd_patron_holds.setAttribute('style','');
607             this.controller.view.cmd_patron_bills.setAttribute('style','');
608             this.controller.view[ btn ].setAttribute('style','background: blue; color: white;');
609         } catch(E) {
610             alert(E);
611         }
612         },
613
614         'render_search_form' : function(params) {
615                 var obj = this;
616                         if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
617                                 try { window.xulG.set_tab_name($("patronStrings").getString('staff.patron.display.render_search_form.patron_search')); } catch(E) { alert(E); }
618                         }
619
620                         obj.controller.view.PatronNavBar.selectedIndex = 0;
621                         obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','true');
622                         obj.controller.view.cmd_patron_merge.setAttribute('disabled','true');
623                         obj.controller.view.cmd_search_form.setAttribute('disabled','true');
624
625                     var horizontal_interface = String( obj.OpenILS.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
626                         var loc = horizontal_interface ? urls.XUL_PATRON_HORIZONTAL_SEARCH_FORM : urls.XUL_PATRON_SEARCH_FORM; 
627                         var my_xulG = {
628                                 'clear_left_deck' : function() {
629                                         setTimeout( function() {
630                                                 obj.left_deck.clear_all_except(loc);
631                                                 obj.render_search_form(params);
632                                         }, 0);
633                                 },
634                                 'on_submit' : function(query) {
635                                         obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','true');
636                                 obj.controller.view.cmd_patron_merge.setAttribute('disabled','true');
637                                         var list_frame = obj.right_deck.reset_iframe(
638                                                 urls.XUL_PATRON_SEARCH_RESULT, // + '?' + query,
639                                                 {},
640                                                 {
641                                                         'query' : query,
642                                                         'on_select' : function(list) {
643                                                                 if (!list) return;
644                                                                 if (list.length < 1) return;
645                                                                 obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','false');
646                                                                 if (list.length > 1) obj.controller.view.cmd_patron_merge.setAttribute('disabled','false');
647                                                                 obj.controller.view.cmd_search_form.setAttribute('disabled','false');
648                                                                 obj.retrieve_ids = list;
649                                                                 obj.controller.view.patron_name.setAttribute('value',$("patronStrings").getString('staff.patron.display.init.retrieving'));
650                                                                 document.documentElement.setAttribute('class','');
651                                                                 setTimeout(
652                                                                         function() {
653                                                                                 var frame = obj.left_deck.set_iframe(
654                                                                                         urls.XUL_PATRON_SUMMARY + '?id=' + window.escape(list[0]),
655                                                                                         {},
656                                                                                         {
657                                                                                                 //'id' : list[0],
658                                                                                                 'on_finished' : function(patron) {
659                                                                                                         obj.patron = patron;
660                                                                                                         obj.controller.render();
661                                                                                                 }
662                                                                                         }
663                                                                                 );
664                                                                                 netscape.security.PrivilegeManager.enablePrivilege(
665                                                                                         "UniversalXPConnect"
666                                                                                 );
667                                                                                 obj.summary_window = get_contentWindow(frame);
668                                                                                 obj.patron = obj.summary_window.g.summary.patron;
669                                                                                 obj.controller.render('patron_name');
670                                                                         }, 0
671                                                                 );
672                                                         }
673                                                 }
674                                         );
675                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
676                                         obj.search_result = get_contentWindow(list_frame);
677                                 }
678                         };
679
680                         if (params['query']) {
681                                 my_xulG.query = JSON2js(params['query']);
682                                 if (params.doit) my_xulG.doit = 1;
683                         }
684
685                         var form_frame = obj.left_deck.set_iframe(
686                                 loc,
687                                 {},
688                                 my_xulG
689                         );
690                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
691                         obj.search_window = get_contentWindow(form_frame);
692                         obj._checkout_spawned = true;
693         },
694
695         '_checkout_spawned' : false,
696
697         'refresh_deck' : function(url) {
698                 var obj = this;
699                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
700                 for (var i = 0; i < obj.right_deck.node.childNodes.length; i++) {
701                         try {
702                                 var f = obj.right_deck.node.childNodes[i];
703                                 var w = get_contentWindow(f);
704                                 if (url) {
705                                         if (w.location.href == url) w.refresh(true);
706                                 } else {
707                                         if (typeof w.refresh == 'function') {
708                                                 w.refresh(true);
709                                         }
710                                 }
711
712                         } catch(E) {
713                                 obj.error.sdump('D_ERROR','refresh_deck: ' + E + '\n');
714                         }
715                 }
716         },
717         
718         'refresh_all' : function() {
719                 var obj = this;
720                 obj.controller.view.patron_name.setAttribute('value', $("patronStrings").getString('staff.patron.display.init.retrieving'));
721                 document.documentElement.setAttribute('class','');
722                 try { obj.summary_window.refresh(); } catch(E) { obj.error.sdump('D_ERROR', E + '\n'); }
723                 try { obj.refresh_deck(); } catch(E) { obj.error.sdump('D_ERROR', E + '\n'); }
724         },
725 }
726
727 dump('exiting patron/display.js\n');