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