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