30dcec2853497b9fa3855d268ff399433a7e566e
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / circ / checkout.js
1 dump('entering circ.checkout.js\n');
2
3 if (typeof circ == 'undefined') { circ = {}; }
4 circ.checkout = function (params) {
5
6     JSAN.use('util.error'); this.error = new util.error();
7     JSAN.use('util.network'); this.network = new util.network();
8     JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
9     JSAN.use('util.money');
10     JSAN.use('util.barcode');
11 };
12
13 circ.checkout.prototype = {
14
15     'init' : function( params ) {
16
17         var obj = this;
18
19         obj.patron_id = params.patron_id;
20
21         obj.auto_override_events = [];
22
23         JSAN.use('circ.util');
24         var columns = circ.util.columns( 
25             { 
26                 'barcode' : { 'hidden' : false },
27                 'title' : { 'hidden' : false },
28                 'due_date' : { 'hidden' : false }
29             } 
30         );
31
32         JSAN.use('util.list'); obj.list = new util.list('checkout_list');
33         obj.list.init(
34             {
35                 'columns' : columns,
36                 'on_select' : function() {
37                     var sel = obj.list.retrieve_selection();
38                     document.getElementById('clip_button').disabled = sel.length < 1;
39                 }
40             }
41         );
42         
43         JSAN.use('util.controller'); obj.controller = new util.controller();
44         obj.controller.init(
45             {
46                 'control_map' : {
47                     'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
48                     'sel_clip' : [
49                         ['command'],
50                         function() { obj.list.clipboard(); }
51                     ],
52                     'checkout_menu_placeholder' : [
53                         ['render'],
54                         function(e) {
55                             return function() {
56                                 JSAN.use('util.widgets'); JSAN.use('util.functional'); JSAN.use('util.fm_utils');
57                                 var items = [ [ document.getElementById('circStrings').getString('staff.circ.checkout.barcode') , 'barcode' ] ].concat(
58                                     util.functional.map_list(
59                                         util.functional.filter_list(
60                                             obj.data.list.my_cnct,
61                                             function(o) {
62                                                 return util.fm_utils.compare_aou_a_is_b_or_ancestor(o.owning_lib(), obj.data.list.au[0].ws_ou());
63                                             }
64                                         ).sort(
65
66                                             function(a,b) {
67                                                 try { 
68                                                     return util.fm_utils.sort_func_aou_by_depth_and_then_string(
69                                                         [ a.owning_lib(), a.name() ],
70                                                         [ b.owning_lib(), b.name() ]
71                                                     );
72                                                 } catch(E) {
73                                                     alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkout.sorting.exception', [E]));
74                                                     return 0;
75                                                 }
76                                             }
77
78                                         ),
79                                         function(o) {
80                                             return [ obj.data.hash.aou[ o.owning_lib() ].shortname() + ' : ' + o.name(), o.id() ];
81                                         }
82                                     )
83                                 );
84                                 g.error.sdump('D_TRACE','items = ' + js2JSON(items));
85                                 util.widgets.remove_children( e );
86                                 var ml = util.widgets.make_menulist(items);
87                                 e.appendChild( ml );
88                                 ml.setAttribute('id','checkout_menulist');
89                                 ml.setAttribute('accesskey','');
90                                 ml.addEventListener(
91                                     'command',
92                                     function(ev) {
93                                         var tb = obj.controller.view.checkout_barcode_entry_textbox;
94                                         var db = document.getElementById('duedate_hbox');
95                                         if (ev.target.value == 'barcode') {
96                                             db.hidden = false;
97                                             tb.disabled = false;
98                                             tb.value = '';
99                                             tb.focus();
100                                         } else {
101                                             db.hidden = true;
102                                             tb.disabled = true;
103                                             tb.value = document.getElementById('circStrings').getString('staff.circ.non_cataloged');
104                                         }
105                                     }, false
106                                 );
107                                 obj.controller.view.checkout_menu = ml;
108                             };
109                         }
110                     ],
111                     'checkout_barcode_entry_textbox' : [
112                         ['keypress'],
113                         function(ev) {
114                             if (ev.keyCode && ev.keyCode == 13) {
115                                 obj.checkout( { barcode: ev.target.value } );
116                             }
117                         }
118                     ],
119                     'checkout_duedate_datepicker' : [
120                         ['change'],
121                         function(ev) { 
122                             try {
123                                 document.getElementById('checkout_duedate_checkbox').checked = true;
124                                 if (obj.check_date(ev.target)) {
125                                     ev.target.parentNode.setAttribute('style','');
126                                 } else {
127                                     ev.target.parentNode.setAttribute('style','background-color: red');
128                                 }
129                             } catch(E) {
130                                 alert('Error in checkout.js, checkout_duedate_datepicker @change: ' + E);
131                             }
132                         }
133                     ],
134                     'cmd_broken' : [
135                         ['command'],
136                         function() { alert(document.getElementById('circStrings').getString('staff.circ.checkout.unimplemented')); }
137                     ],
138                     'cmd_checkout_submit' : [
139                         ['command'],
140                         function() {
141                             var params = {}; var count = 1;
142
143                             if (obj.controller.view.checkout_menu.value == 'barcode' ||
144                                 obj.controller.view.checkout_menu.value === '') {
145                                 params.barcode = obj.controller.view.checkout_barcode_entry_textbox.value;
146                             } else {
147                                 params.noncat = 1;
148                                 params.noncat_type = obj.controller.view.checkout_menu.value;
149                                 var r = window.prompt(
150                                     document.getElementById('circStrings').getFormattedString('staff.circ.checkout.cmd_checkout_submit.msg', [obj.data.hash.cnct[params.noncat_type].name()]),
151                                     '1',
152                                     document.getElementById('circStrings').getString('staff.circ.checkout.cmd_checkout_submit.title')
153                                 );
154                                 if (r) {
155                                     count = Number(r);
156                                     if (count > 0) {
157                                         if (count > 99) {
158                                             obj.error.yns_alert(
159                                                 document.getElementById('circStrings').getFormattedString('staff.circ.checkout.cmd_checkout_submit.too_many.msg', [count, obj.data.hash.cnct[params.noncat_type].name()]),
160                                                 document.getElementById('circStrings').getString('staff.circ.checkout.cmd_checkout_submit.too_many.title'),
161                                                 document.getElementById('circStrings').getString('staff.circ.checkout.ok.btn'),
162                                                 null,
163                                                 null,
164                                                 document.getElementById('circStrings').getString('staff.circ.confirm')
165                                             );
166                                             return;
167                                         } else if (count > 20) {
168                                             r = obj.error.yns_alert(
169                                                 document.getElementById('circStrings').getFormattedString('staff.circ.checkout.cmd_checkout_submit.confirm.msg', [count, obj.data.hash.cnct[params.noncat_type].name()]),
170                                                 document.getElementById('circStrings').getString('staff.circ.checkout.cmd_checkout_submit.confirm.title'),
171                                                 document.getElementById('circStrings').getString('staff.circ.checkout.yes.btn'),
172                                                 document.getElementById('circStrings').getString('staff.circ.checkout.no.btn'),
173                                                 null,
174                                                 document.getElementById('circStrings').getString('staff.circ.confirm')
175                                             );
176                                             if (r !== 0) { return; }
177                                         }
178                                     } else {
179                                         r = obj.error.yns_alert(
180                                             document.getElementById('circStrings').getFormattedString('staff.circ.checkout.cmd_checkout_submit.non_numeric.msg', [r]),
181                                             document.getElementById('circStrings').getString('staff.circ.checkout.cmd_checkout_submit.non_numeric.title'),
182                                             document.getElementById('circStrings').getString('staff.circ.checkout.ok.btn'),
183                                             null,
184                                             null,
185                                             document.getElementById('circStrings').getString('staff.circ.confirm')
186                                         );
187                                         return;
188                                     }
189                                 } else {
190                                     return;
191                                 }
192                             }
193                             for (var i = 0; i < count; i++) {
194                                 obj.checkout( params );
195                             }
196                         }
197                     ],
198                     'cmd_checkout_print' : [
199                         ['command'],
200                         function() {
201                             try {
202                                 obj.print();
203                             } catch(E) {
204                                 obj.error.standard_unexpected_error_alert('cmd_checkout_print',E);
205                             }
206
207                         }
208                     ],
209                     'cmd_checkout_export' : [
210                         ['command'],
211                         function() {
212                             try {
213                                 obj.export_list();
214                             } catch(E) {
215                                 obj.error.standard_unexpected_error_alert('cmd_checkout_export',E); 
216                             }
217                         }
218                     ],
219
220
221                     'cmd_checkout_reprint' : [
222                         ['command'],
223                         function() {
224                             JSAN.use('util.print'); var print = new util.print();
225                             print.reprint_last();
226                         }
227                     ],
228                     'cmd_checkout_done' : [
229                         ['command'],
230                         function() {
231                             try {
232                                 var no_print_prompting = obj.data.hash.aous['circ.staff_client.do_not_auto_attempt_print'];
233                                 if (no_print_prompting) {
234                                     if (no_print_prompting.indexOf( "Checkout" ) > -1) {
235                                         obj.list.clear();
236                                         xulG.set_tab(urls.XUL_PATRON_BARCODE_ENTRY,{},{}); 
237                                         return;
238                                     }
239                                 }
240                                 if (document.getElementById('checkout_auto').checked) {
241                                     obj.print(true,function() { 
242                                         obj.list.clear();
243                                         xulG.set_tab(urls.XUL_PATRON_BARCODE_ENTRY,{},{}); 
244                                     });
245                                 } else {
246                                     obj.print(false,function() {
247                                         obj.list.clear();
248                                         xulG.set_tab(urls.XUL_PATRON_BARCODE_ENTRY,{},{});
249                                     });
250                                 }
251                             } catch(E) {
252                                 obj.error.standard_unexpected_error_alert('cmd_checkout_done',E);
253                             }
254                         }
255                     ]
256                 }
257             }
258         );
259         this.controller.render();
260         //this.controller.view.checkout_barcode_entry_textbox.focus();
261
262         this.check_disable();
263
264         var robj = obj.network.simple_request(
265             'FM_CIRC_COUNT_RETRIEVE_VIA_USER.authoritative',
266             [ ses(), obj.patron_id ]
267         );
268         obj.items_out_count = (robj.out + robj.overdue + robj.claims_returned + robj.long_overdue );
269
270     },
271
272     'check_disable' : function() {
273         var obj = this;
274         try {
275             if (typeof xulG.check_stop_checkouts == 'function') {
276                 var disable = xulG.check_stop_checkouts();
277                 if (disable) {
278                     document.getElementById('checkout_submit_barcode_button').disabled = true;
279                     document.getElementById('checkout_done').disabled = true;
280                     document.getElementById('checkout_duedate_checkbox').disabled = true;
281                     document.getElementById('checkout_duedate_timepicker').disabled = true;
282                     obj.controller.view.checkout_menu.disabled = true;
283                     obj.controller.view.checkout_barcode_entry_textbox.disabled = true;
284                     obj.controller.view.checkout_duedate_datepicker.disabled = true;
285                 } else {
286                     document.getElementById('checkout_submit_barcode_button').disabled = false;
287                     document.getElementById('checkout_done').disabled = false;
288                     document.getElementById('checkout_duedate_checkbox').disabled = false;
289                     document.getElementById('checkout_duedate_timepicker').disabled = false;
290                     obj.controller.view.checkout_menu.disabled = false;
291                     obj.controller.view.checkout_barcode_entry_textbox.disabled = false;
292                     obj.controller.view.checkout_duedate_datepicker.disabled = false;
293                 }
294             }
295         } catch(E) {
296             obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.checkout.disable.error'),E);
297         }
298     },
299
300     'print' : function(silent,f) {
301         var obj = this;
302         try {
303             obj.patron = obj.network.simple_request('FM_AU_FLESHED_RETRIEVE_VIA_ID',[ses(),obj.patron_id]);
304             var params = { 
305                 'patron' : obj.patron, 
306                 'lib' : obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ],
307                 'staff' : obj.data.list.au[0],
308                 'data' : {
309                     'balance_owed' : util.money.sanitize( obj.most_recent_balance_owed ),
310                 },
311                 'printer_context' : 'receipt',
312                 'template' : 'checkout',
313                 'callback' : function() {
314                     setTimeout(
315                         function(){
316                             if (typeof f == 'function') { 
317                                 setTimeout( 
318                                     function() {
319                                         f();
320                                     }, 1000
321                                 );
322                             } 
323                         }, 1000
324                     );
325                 }
326             };
327             if (silent) { params.no_prompt = true; }
328             obj.list.print(params);
329         } catch(E) {
330             obj.error.standard_unexpected_error_alert('print',E);
331         }
332     },
333     
334     'export_list' : function(silent,f) {
335         var obj = this;
336         try {
337             obj.list.dump_csv_to_clipboard();
338         } catch(E) {
339             obj.error.standard_unexpected_error_alert('export',E);
340         }
341     },
342
343     'check_date' : function(node) {
344         var obj = this;
345         JSAN.use('util.date');
346         try {
347             obj.controller.view.checkout_barcode_entry_textbox.setAttribute('disabled','false');
348             obj.controller.view.checkout_barcode_entry_textbox.disabled = false;
349             obj.controller.view.cmd_checkout_submit.setAttribute('disabled','false');
350             obj.controller.view.cmd_checkout_submit.disabled = false;
351             try {
352                 if (util.date.check_past('YYYY-MM-DD',node.value) ) {
353                     obj.controller.view.checkout_barcode_entry_textbox.setAttribute('disabled','true');
354                     obj.controller.view.cmd_checkout_submit.setAttribute('disabled','true');
355                     return false;
356                 }
357             }
358             catch (E) {
359                     obj.controller.view.checkout_barcode_entry_textbox.setAttribute('disabled','true');
360                     obj.controller.view.cmd_checkout_submit.setAttribute('disabled','true');
361                     return false;
362             }
363             return true;
364         } catch(E) {
365             throw(E);
366         }
367     },
368
369     '_checkout_pending_hash' : {},
370
371     '_checkout' : function(params,permit) {
372         var obj = this;
373         try {
374         
375             /**********************************************************************************************************************/
376             /* This handles the return value of the checkout/renewal */
377             function _checkout_callback(req,x) {
378                 try {
379
380                     if (params.barcode) { 
381                         delete obj._checkout_pending_hash[ params.barcode ];
382                     }
383
384                     var checkout = req.getResultObject();
385
386                     if (checkout.ilsevent === '0') {
387         
388                         if (!checkout.payload) { checkout.payload = {}; }
389         
390                         if (!checkout.payload.circ) {
391                             checkout.payload.circ = new aoc();
392                             /*********************************************************************************************/
393                             /* Non Cat */
394                             if (checkout.payload.noncat_circ) {
395                                 checkout.payload.circ.circ_lib( checkout.payload.noncat_circ.circ_lib() );
396                                 checkout.payload.circ.circ_staff( checkout.payload.noncat_circ.staff() );
397                                 checkout.payload.circ.usr( checkout.payload.noncat_circ.patron() );
398                                 checkout.payload.circ.due_date( checkout.payload.noncat_circ.duedate() );
399                             }
400                         }
401     
402                         if (!checkout.payload.record) {
403                             checkout.payload.record = new mvr();
404                             /*********************************************************************************************/
405                             /* Non Cat */
406                             if (checkout.payload.noncat_circ) {
407                                 checkout.payload.record.title(
408                                     obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ].name()
409                                 );
410                             }
411                         }
412             
413                         if (!checkout.payload.copy) {
414                             checkout.payload.copy = new acp();
415                             checkout.payload.copy.barcode( '' );
416                         }
417             
418                         /*********************************************************************************************/
419                         /* Override mvr title/author with dummy title/author for Pre cat */
420                         if (checkout.payload.copy.dummy_title()) {
421                             checkout.payload.record.title( checkout.payload.copy.dummy_title() );
422                         }
423                         if (checkout.payload.copy.dummy_author()) {
424                             checkout.payload.record.author( checkout.payload.copy.dummy_author() );
425                         }
426            
427                         if (checkout.payload.patron_money) {
428                             obj.most_recent_balance_owed = checkout.payload.patron_money.balance_owed();
429                         }
430  
431                         obj.list.append(
432                             {
433                                 'row' : {
434                                     'my' : {
435                                     'circ' : checkout.payload.circ,
436                                     'mvr' : checkout.payload.record,
437                                     'acp' : checkout.payload.copy,
438                                     'acn' : checkout.payload.volume
439                                     }
440                                 },
441                                 'to_top' : true
442                             //I could override map_row_to_column here
443                             }
444                         );
445                         var is_renewal = (
446                             get_bool(checkout.payload.circ.opac_renewal())
447                             ||get_bool(checkout.payload.circ.phone_renewal())
448                             ||get_bool(checkout.payload.circ.desk_renewal())
449                         );
450                         try {
451                             obj.error.work_log(
452                                 document.getElementById('circStrings').getFormattedString(
453                                         is_renewal
454                                         ? 'staff.circ.work_log_renew.message'
455                                         : 'staff.circ.work_log_checkout.message',
456                                     [
457                                         ses('staff_usrname'),
458                                         xulG.patron.family_name(),
459                                         xulG.patron.card().barcode(),
460                                         checkout.payload.copy.barcode()
461                                     ]
462                                 ), {
463                                     'au_id' : xulG.patron.id(),
464                                     'au_family_name' : xulG.patron.family_name(),
465                                     'au_barcode' : xulG.patron.card().barcode(),
466                                     'acp_barcode' : checkout.payload.copy.barcode()
467                                 }
468                             );
469                         } catch(E) {
470                             obj.error.sdump('D_ERROR','Error with work_logging in server/circ/checkout.js, _checkout:' + E);
471                         }
472                         document.getElementById('msg_area').removeChild(x);
473                         /*
474                         if (typeof obj.on_checkout == 'function') {
475                             obj.on_checkout(checkout.payload);
476                         }
477                         */
478                         if (typeof window.xulG == 'object' && typeof window.xulG.on_list_change == 'function') {
479                             window.xulG.on_list_change(checkout.payload,is_renewal);
480                         } else {
481                             obj.error.sdump('D_CIRC','circ.checkout: No external .on_checkout()\n');
482                         }
483         
484                     } else {
485                         // Should get here with failed renewals
486                         switch(Number(checkout.ilsevent)) {
487                             case null /* custom event */ : 
488                             case 5000 /* PERM_FAILURE */: 
489                             case 1212 /* PATRON_EXCEEDS_OVERDUE_COUNT */ : 
490                             case 1213 /* PATRON_BARRED */ : 
491                             case 1215 /* CIRC_EXCEEDS_COPY_RANGE */ : 
492                             case 1224 /* PATRON_ACCOUNT_EXPIRED */ : 
493                             case 1232 /* ITEM_DEPOSIT_REQUIRED */ : 
494                             case 1233 /* ITEM_RENTAL_FEE_REQUIRED */ : 
495                             case 1234 /* ITEM_DEPOSIT_PAID */ : 
496                             case 1500 /* ACTION_CIRCULATION_NOT_FOUND */ : 
497                             case 7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */ : 
498                             case 7003 /* COPY_CIRC_NOT_ALLOWED */ : 
499                             case 7004 /* COPY_NOT_AVAILABLE */ : 
500                             case 7006 /* COPY_IS_REFERENCE */ : 
501                             case 7007 /* COPY_NEEDED_FOR_HOLD */ : 
502                             case 7008 /* MAX_RENEWALS_REACHED */ : 
503                             case 7009 /* CIRC_CLAIMS_RETURNED */ : 
504                             case 7010 /* COPY_ALERT_MESSAGE */ : 
505                             case 7013 /* PATRON_EXCEEDS_FINES */ : 
506                                 x.setAttribute('style','color: red');
507                                 x.setAttribute('value', document.getElementById('circStrings').getFormattedString('staff.circ.checkout.barcode.failed', [params.barcode]));
508                                 if (typeof params.noncat == 'undefined') { obj.items_out_count--; }
509                             break;
510                             default: throw(checkout);
511                         }
512                     }
513         
514                 } catch(E) {
515                     x.setAttribute('style','color: red');
516                     x.setAttribute('value', document.getElementById('circStrings').getFormattedString('staff.circ.checkout.barcode.failed', [params.barcode]));
517                     if (typeof params.noncat == 'undefined') { obj.items_out_count--; }
518                     obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkout.barcode.failed.alert', ['#3']),E);
519                 }
520             }
521
522             /**********************************************************************************************************************/
523             /* This used to do the actual checkout/renewal */
524         
525             var x = document.createElement('label');
526             x.setAttribute('style','color: green');
527             if (params.barcode) {
528                 x.setAttribute('value',document.getElementById('circStrings').getFormattedString('staff.circ.checkout.barcode.pending', [params.barcode]));
529             } else {
530                 x.setAttribute('value',document.getElementById('circStrings').getString('staff.circ.checkout.non_cataloged.pending'));
531             }
532             document.getElementById('msg_area').appendChild(x);
533
534             /*
535             obj.network.request(
536                 api.CHECKOUT.app,
537                 api.CHECKOUT.method,
538                 [ ses(), params, obj.items_out_count ],
539                 function(req) {
540                     _checkout_callback(req,x);
541                 }
542             );
543             */
544             
545             if (typeof params.noncat == 'undefined') { obj.items_out_count++; }
546            
547            /* new */
548             _checkout_callback({ 'getResultObject' : function() { return permit; } },x);
549
550         } catch(E) {
551             x.setAttribute('style','color: red');
552             x.setAttribute('value', document.getElementById('circStrings').getFormattedString('staff.circ.checkout.barcode.failed', [params.barcode]));
553             if (typeof params.noncat == 'undefined') { obj.items_out_count--; }
554             obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkout.barcode.failed.alert', ['#2']),E);
555         }
556     },
557
558
559     'test_barcode' : function(bc) {
560         var obj = this;
561         var x = document.getElementById('strict_barcode');
562         if (x && x.checked !== true) { return true; }
563         var good = util.barcode.check(bc);
564         if (good) {
565             return true;
566         } else {
567             if ( 1 == obj.error.yns_alert(
568                         document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
569                         document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
570                         document.getElementById('circStrings').getString('staff.circ.cancel'),
571                         document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
572                         null,
573                         document.getElementById('circStrings').getString('staff.circ.confirm'),
574                         '/xul/server/skin/media/images/bad_barcode.png'
575                 )
576             ) {
577                 return true;
578             } else {
579                 return false;
580             }
581         }
582     },
583
584     'checkout' : function(params) {
585         var obj = this;
586
587         JSAN.use('util.date');
588         if (document.getElementById('checkout_duedate_checkbox').checked) {
589             if (! obj.check_date(obj.controller.view.checkout_duedate_datepicker)) return;
590             var tp = document.getElementById('checkout_duedate_timepicker');
591             var dp = obj.controller.view.checkout_duedate_datepicker;
592             var tp_date = tp.dateValue;
593             var dp_date = dp.dateValue;
594             dp_date.setHours( tp_date.getHours() );
595             dp_date.setMinutes( tp_date.getMinutes() );
596
597             params.due_date = util.date.formatted_date(dp_date,'%{iso8601}');
598         }
599
600         if (typeof obj.on_checkout == 'function') { obj.on_checkout(params); }
601
602         if (! (params.barcode||params.noncat)) { return; }
603
604         if (params.barcode) {
605             // Default is "just items"
606             var barcode_context = 'asset';
607             // Add actor (can be any string that includes 'actor') if looking up patrons at checkout
608             if(String( obj.data.hash.aous['circ.staff_client.actor_on_checkout'] ) == 'true')
609                 barcode_context += '-actor';
610             // Auto-complete the barcode
611             var in_barcode = xulG.get_barcode(window, barcode_context, params.barcode);
612             // user_false is "None of the above selected", don't error out/fall through as they already said no
613             if(in_barcode == "user_false") return;
614             // We have a barcode and there was no error?
615             if(in_barcode && typeof in_barcode.ilsevent == 'undefined') {
616                 // Check if it was an actor barcode (will never happen unless actor was added above)
617                 if(in_barcode.type == 'actor') {
618                     // Go to new patron (do not pass go, do not collect $200, do not prompt user)
619                     var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
620                     var loc = xulG.url_prefix( horizontal_interface ? 'XUL_PATRON_HORIZ_DISPLAY' : 'XUL_PATRON_DISPLAY' );
621                     xulG.set_tab( loc, {}, { 'barcode' : in_barcode.barcode } );
622                     return;
623                 }
624                 params.barcode = in_barcode.barcode;
625             }
626
627             if ( obj.test_barcode(params.barcode) ) { /* good */ } else { /* bad */ return; }
628
629             if (typeof obj._checkout_pending_hash[ params.barcode ] != 'undefined') {
630
631                 obj.error.sdump('D_CIRC','Redundant barcode scan == ' + params.barcode);
632                 return; // redundant barcode scan
633
634             } else {
635
636                 obj._checkout_pending_hash[ params.barcode ] = true;    
637
638             }
639         }
640
641
642         /**********************************************************************************************************************/
643         /* This used to be the Permissibility test before checkout */
644         try {
645
646             params.patron = obj.patron_id;
647
648             var permit = obj.network.simple_request(
649                 //api.CHECKOUT_PERMIT.app,
650                 'CHECKOUT_FULL',
651                 [ ses(), params, obj.items_out_count ],
652                 null,
653                 {
654                     'title' : document.getElementById('circStrings').getString('staff.circ.checkout.override.confirm'),
655                     'overridable_events' : [ 
656                         null /* custom event */,
657                         1212 /* PATRON_EXCEEDS_OVERDUE_COUNT */,
658                         1213 /* PATRON_BARRED */,
659                         1215 /* CIRC_EXCEEDS_COPY_RANGE */,
660                         1232 /* ITEM_DEPOSIT_REQUIRED */,
661                         1233 /* ITEM_RENTAL_FEE_REQUIRED */,
662                         7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */,
663                         7003 /* COPY_CIRC_NOT_ALLOWED */,
664                         7004 /* COPY_NOT_AVAILABLE */, 
665                         7006 /* COPY_IS_REFERENCE */, 
666                         7010 /* COPY_ALERT_MESSAGE */,
667                         7016 /* ITEM_ON_HOLDS_SHELF */,
668                         7013 /* PATRON_EXCEEDS_FINES */
669                     ],
670                     'report_override_on_events' : [ /* Allow auto-override of Patron overrides only */
671                         1212 /* PATRON_EXCEEDS_OVERDUE_COUNT */,
672                         1213 /* PATRON_BARRED */,
673                         7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */,
674                         7013 /* PATRON_EXCEEDS_FINES */
675                     ],
676                     'auto_override_these_events' : obj.auto_override_events,
677                     'text' : {
678                         '1212' : function(r) {
679                             return document.getElementById('circStrings').getString('staff.circ.checkout.override.will_auto');
680                         },
681                         '1213' : function(r) {
682                             return document.getElementById('circStrings').getString('staff.circ.checkout.override.will_auto');
683                         },
684                         '1232' : function(r) {
685                             return document.getElementById('circStrings').getString('staff.circ.checkout.override.item_deposit_required.warning');
686                         },
687                         '1233' : function(r) {
688                             return document.getElementById('circStrings').getString('staff.circ.checkout.override.item_rental_fee_required.warning');
689                         },
690                         '7002' : function(r) {
691                             return document.getElementById('circStrings').getString('staff.circ.checkout.override.will_auto');
692                         },
693                         '7004' : function(r) {
694                             try {
695                                 status_name = obj.data.hash.ccs[ r.payload.status() ].name();
696                                 return status_name;
697                             } catch (E) {
698                                 return "Could not retrieve the name of the current status for the copy";  // XXX
699                             }
700                         },
701                         '7010' : function(r) {
702                             return r.payload;
703                         },
704                         '7013' : function(r) {
705                             return document.getElementById('circStrings').getString('staff.circ.checkout.override.will_auto');
706                         }
707                     }
708                 }
709             );
710
711             if (!permit) { throw(permit); }
712
713             function test_event(list,ev) {
714                 if (typeof list.ilsevent != 'undefined' ) {
715                     if (list.ilsevent == ev) {
716                         return list;
717                     } else {
718                         return false;
719                     }
720                 } else {
721                     for (var i = 0; i < list.length; i++) {
722                         if (typeof list[i].ilsevent != 'undefined') {
723                             if (list[i].ilsevent == ev) { return list[i]; }
724                         }
725                     }
726                     return false;
727                 }
728             }
729
730             /**********************************************************************************************************************/
731             /* Normal case, proceed with checkout */
732             if (permit.ilsevent === '0') {
733                 if(permit._reported_events != 'undefined') {
734                     obj.auto_override_events = obj.auto_override_events.concat(permit._reported_events);
735                 }
736                 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
737                 params.permit_key = permit.payload;
738                 obj._checkout( params, permit ); 
739
740             /**********************************************************************************************************************/
741             /* Item not cataloged or barcode mis-scan.  Prompt for pre-cat option */
742             } else {
743             
744                 if (params.barcode) { delete obj._checkout_pending_hash[ params.barcode ];    }
745
746                 var found_handled = false; var found_not_handled = false; var msg = '';    
747
748                 if (test_event(permit,1202 /* ITEM_NOT_CATALOGED */)) {
749
750                     if ( 1 == obj.error.yns_alert(
751                         document.getElementById('circStrings').getString('staff.circ.checkout.not_cataloged.confirm'),
752                         document.getElementById('circStrings').getString('staff.circ.alert'),
753                         document.getElementById('circStrings').getString('staff.circ.cancel'),
754                         document.getElementById('circStrings').getString('staff.circ.pre_cataloged'),
755                         null,
756                         document.getElementById('circStrings').getString('staff.circ.confirm'),
757                         '/xul/server/skin/media/images/book_question.png'
758                     ) ) {
759
760                         obj.data.dummy_title = ''; obj.data.dummy_author = ''; obj.data.stash('dummy_title','dummy_author');
761                         JSAN.use('util.window'); var win = new util.window();
762                         win.open(urls.XUL_PRE_CAT, 'dummy_fields', 'chrome,resizable,modal');
763                         obj.data.stash_retrieve();
764
765                         params.permit_key = permit.payload;
766                         params.dummy_title = obj.data.precat_dummy_title;
767                         params.dummy_author = obj.data.precat_dummy_author;
768                         params.dummy_isbn = obj.data.precat_dummy_isbn;
769                         params.circ_modifier = obj.data.precat_circ_modifier;
770                         params.precat = 1;
771
772                         if (obj.data.precat_submit == 'go') { 
773                             //obj._checkout( params ); No real request method here anymore
774                             obj.checkout( params );
775                         } else {
776                             alert(document.getElementById('circStrings').getString('staff.circ.checkout.cancelled'));
777                         }
778                     }
779
780                     return;
781                 }
782
783                 var test_permit;
784                 if (typeof permit.ilsevent != 'undefined') { test_permit = [ permit ]; } else { test_permit = permit; }
785
786                 var stop_checkout = false;
787                 for (var i = 0; i < test_permit.length; i++) {
788                     switch(Number(test_permit[i].ilsevent)) {
789                         case 1216 /* PATRON_CARD_INACTIVE */ :
790                         case 1217 /* PATRON_INACTIVE */ :
791                         case 1224 /* PATRON_ACCOUNT_EXPIRED */ :
792                             stop_checkout = true;
793                         break;
794                     }
795                 }
796
797                 for (var i = 0; i < test_permit.length; i++) {
798                     dump('found [' + test_permit[i].ilsevent + ']\n');
799                     switch(test_permit[i].ilsevent == null || test_permit[i].ilsevent == '' ? null : Number(test_permit[i].ilsevent)) {
800                         case null /* custom event */ :
801                             found_handled = true;
802                         break;
803                         case 1212 /* PATRON_EXCEEDS_OVERDUE_COUNT */ :
804                             found_handled = true;
805                         break;
806                         case 1213 /* PATRON_BARRED */ :
807                             found_handled = true;
808                         break;
809                         case 1215 /* CIRC_EXCEEDS_COPY_RANGE */ :
810                             found_handled = true;
811                         break;
812                         case 1216 /* PATRON_CARD_INACTIVE */ :
813                             found_handled = true;
814                             msg += document.getElementById('circStrings').getString('staff.circ.checkout.card.inactive') + '\n';
815                             obj.error.yns_alert(
816                                 msg,
817                                 document.getElementById('circStrings').getString('staff.circ.checkout.barcode.check_out_failed'),
818                                 document.getElementById('circStrings').getString('staff.circ.checkout.ok.btn'),
819                                 null,
820                                 null,
821                                 document.getElementById('circStrings').getString('staff.circ.confirm.msg')
822                             );
823                         break;
824                         case 1217 /* PATRON_INACTIVE */ :
825                             found_handled = true;
826                             msg += document.getElementById('circStrings').getString('staff.circ.checkout.account.inactive') + '\n';
827                             obj.error.yns_alert(
828                                 msg,
829                                 document.getElementById('circStrings').getString('staff.circ.checkout.barcode.check_out_failed'),
830                                 document.getElementById('circStrings').getString('staff.circ.checkout.ok.btn'),
831                                 null,
832                                 null,
833                                 document.getElementById('circStrings').getString('staff.circ.confirm.msg')
834                             );
835                         break;
836                         case 1224 /* PATRON_ACCOUNT_EXPIRED */ :
837                             found_handled = true;
838                             msg += document.getElementById('circStrings').getString('staff.circ.checkout.account.expired') + '\n';
839                             obj.error.yns_alert(
840                                 msg,
841                                 document.getElementById('circStrings').getString('staff.circ.checkout.barcode.check_out_failed'),
842                                 document.getElementById('circStrings').getString('staff.circ.checkout.ok.btn'),
843                                 null,
844                                 null,
845                                 document.getElementById('circStrings').getString('staff.circ.confirm.msg')
846                             );
847                         break;
848                         case 1232 /* ITEM_DEPOSIT_REQUIRED */ :
849                         case 1233 /* ITEM_RENTAL_FEE_REQUIRED */ :
850                         case 7013 /* PATRON_EXCEEDS_FINES */ :
851                             found_handled = true;
852                         break;
853                         case 7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */ :
854                             found_handled = true;
855                         break;
856                         case 7003 /* COPY_CIRC_NOT_ALLOWED */ :
857                             found_handled = true;
858                         break;
859                         case 7004 /* COPY_NOT_AVAILABLE */ :
860                             msg += test_permit[i].desc + '\n' + document.getElementById('circStrings').getFormattedString('staff.circ.checkout.copy_status', [obj.data.hash.ccs [test_permit[i].payload.status() ].name()]) + '\n';
861                             found_handled = true;
862                         break;
863                         case 7006 /* COPY_IS_REFERENCE */ :
864                             msg += test_permit[i].desc + '\n';
865                             found_handled = true;
866                         break;
867                         case 7009 /* CIRC_CLAIMS_RETURNED */ :
868                             msg += test_permit[i].desc + '\n';
869                             obj.error.yns_alert(
870                                 msg,
871                                 document.getElementById('circStrings').getString('staff.circ.checkout.barcode.check_out_failed'),
872                                 document.getElementById('circStrings').getString('staff.circ.checkout.ok.btn'),
873                                 null,
874                                 null,
875                                 document.getElementById('circStrings').getString('staff.circ.confirm.msg')
876                             );
877                             found_handled = true;
878                         break;
879                         case 7010 /* COPY_ALERT_MESSAGE */ :
880                             msg += test_permit[i].desc + '\n' + document.getElementById('circStrings').getFormattedString('staff.circ.checkout.alert_message', [test_permit[i].payload]) + '\n';
881                             found_handled = true;
882                         break;
883                         case 7016 /* ITEM_ON_HOLDS_SHELF */ :
884                             msg += test_permit[i].desc + '\n';
885                             found_handled = true;
886                         break;
887                         case 1202 /* ITEM_NOT_CATALOGED */ :
888                             found_handled = true;
889                         break;
890                         case 5000 /* PERM_FAILURE */ :
891                             msg += test_permit[i].desc + '\n' + document.getElementById('circStrings').getFormattedString('staff.circ.checkout.permission_denied', [test_permit[i].ilsperm]) + '\n';
892                             found_handled = true;
893                         break;
894                         case 1702 /* OPEN_CIRCULATION_EXISTS */ :
895                             msg += test_permit[i].desc + '\n';
896                             found_handled = true;
897                             var foreign_circ = true;
898                             var my_circ; 
899
900                             var payload = test_permit[i].payload;
901                             if (payload) {
902                                 if (typeof payload.old_circ == 'object') {
903                                     foreign_circ = false;
904                                     my_circ = payload.old_circ;
905                                 }
906                             }
907
908                             if (foreign_circ) {
909                                 var my_copy = obj.network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[params.barcode]);
910                                 if (typeof my_copy.ilsevent != 'undefined') { throw(my_copy); }
911                                 my_circ = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),my_copy.id(),1]);
912                                 if (typeof my_circ.ilsevent != 'undefined') { throw(my_copy); }
913                                 my_circ = my_circ[0];
914                             }
915
916                             if (! stop_checkout ) {
917
918                                 var due_date = my_circ.due_date() ? util.date.formatted_date( my_circ.due_date(), '%F' ) : null;
919                                 JSAN.use('util.date'); var today = util.date.formatted_date(new Date(),'%F');
920                                 if (due_date) {
921                                     if (today > due_date) {
922                                         msg += (document.getElementById('circStrings').getFormattedString('staff.circ.checkout.item_due', [ util.date.formatted_date( my_circ.due_date(), '%{localized}' ) ]) + '\n');
923                                     }
924                                 }
925
926                                 if (foreign_circ) { // OFFER CANCEL, NORMAL CHECKIN, AND POSSIBLY FORGIVING-BACKDATED CHECKIN
927                                     if (msg.length) msg += ' / ';
928                                     msg+= document.getElementById('circStrings').getFormattedString('staff.circ.checkout.failed_to_patron_other', [ util.date.formatted_date( my_circ.create_time(), '%{localized_date}' ) ]);
929                                     var r = obj.error.yns_alert(
930                                         msg,
931                                         document.getElementById('circStrings').getString('staff.circ.checkout.barcode.check_out_failed'),
932                                         document.getElementById('circStrings').getString('staff.circ.cancel'),
933                                         document.getElementById('circStrings').getString('staff.circ.checkout.normal_checkin_then_checkout'),
934                                         due_date ? (today > due_date ? document.getElementById('circStrings').getString('staff.circ.checkout.forgiving_checkin_then_checkout') : null) : null,
935                                         document.getElementById('circStrings').getString('staff.circ.confirm.msg')
936                                     );
937                                     JSAN.use('circ.util');
938                                     switch(r) {
939                                         case 1:
940                                             circ.util.checkin_via_barcode( ses(), { 'barcode' : params.barcode, 'noop' : 1 } );
941                                             obj.checkout(params);
942                                         break;
943                                         case 2:
944                                             circ.util.checkin_via_barcode( ses(), { 'barcode' : params.barcode, 'noop' : 1 }, due_date );
945                                             obj.checkout(params);
946                                         break;
947                                     }
948                                 } else { // EITHER AUTO-RENEW OR OFFER CANCEL, NORMAL CHECKIN, AND RENEW
949                                     if (payload.auto_renew) {
950                                         circ.util.renew_via_barcode( { 'barcode': params.barcode, 'patron' : obj.patron_id }, function(r) {
951                                             try {
952                                                 params.renewal = true;
953                                                 obj._checkout( params, r[0] ); 
954                                             } catch(E) {
955                                                 alert('Error in checkout.js, RENEW 1: ' + E);
956                                             }
957                                         } );
958                                     } else {
959
960                                         // Include info about date of previous checkout in warning
961                                         if (msg.length) msg += ' / ';
962                                         var cko_d = util.date.formatted_date( my_circ.create_time(), '%{localized_date}' );
963                                         var cur_d = util.date.formatted_date( new Date(), '%{localized_date}');
964                                         if (cko_d == cur_d) {
965                                             msg+= document.getElementById('circStrings').getString('staff.circ.checkout.failed_to_patron_today');
966                                         } else {
967                                             msg+= document.getElementById('circStrings').getString('staff.circ.checkout.failed_to_patron_renew');
968                                         }
969
970                                         var r = obj.error.yns_alert(
971                                             msg,
972                                             document.getElementById('circStrings').getString('staff.circ.checkout.barcode.check_out_failed'),
973                                             document.getElementById('circStrings').getString('staff.circ.cancel'),
974                                             document.getElementById('circStrings').getString('staff.circ.checkout.normal_checkin_then_checkout'),
975                                             document.getElementById('circStrings').getString('staff.circ.checkout.offer_renewal'),
976                                             document.getElementById('circStrings').getString('staff.circ.confirm.msg')
977                                         );
978                                         JSAN.use('circ.util');
979                                         switch(r) {
980                                             case 1:
981                                                 circ.util.checkin_via_barcode( ses(), { 'barcode' : params.barcode, 'noop' : 1 } );
982                                                 obj.checkout(params);
983                                             break;
984                                             case 2:
985                                                 circ.util.renew_via_barcode( { 'barcode' : params.barcode, 'patron' : obj.patron_id }, function(r) {
986                                                     try {
987                                                         params.renewal = true;
988                                                         obj._checkout( params, r[0] ); 
989                                                     } catch(E) {
990                                                         alert('Error in checkout.js, RENEW 2: ' + E);
991                                                     }
992                                                 } );
993                                             break;
994                                         }
995                                     }
996                                 }
997                             } else {
998                                 obj.error.yns_alert(
999                                     msg,
1000                                     document.getElementById('circStrings').getString('staff.circ.checkout.barcode.check_out_failed'),
1001                                     document.getElementById('circStrings').getString('staff.circ.checkout.ok.btn'),
1002                                     null,
1003                                     null,
1004                                     document.getElementById('circStrings').getString('staff.circ.confirm.msg')
1005                                 );
1006                             }
1007                         break;
1008                         case 7014 /* COPY_IN_TRANSIT */ :
1009                             msg += test_permit[i].desc + '\n';
1010                             found_handled = true;
1011                             if (! stop_checkout ) {
1012                                 var r = obj.error.yns_alert(
1013                                     msg,
1014                                     document.getElementById('circStrings').getString('staff.circ.checkout.barcode.check_out_failed'),
1015                                     document.getElementById('circStrings').getString('staff.circ.cancel'),
1016                                     document.getElementById('circStrings').getString('staff.circ.checkout.abort_transit_then_checkout'),
1017                                     null,
1018                                     document.getElementById('circStrings').getString('staff.circ.confirm.msg')
1019                                 );
1020                                 if (r == 1) {
1021                                     var robj = obj.network.simple_request('FM_ATC_VOID',[ ses(), { 'barcode' : params.barcode } ]);
1022                                     if (typeof robj.ilsevent == 'undefined') {
1023                                         obj.checkout(params);
1024                                     } else {
1025                                         switch(Number(robj.ilsevent)) {
1026                                             case 1225 /* TRANSIT_ABORT_NOT_ALLOWED */ :
1027                                                 alert(robj.desc);
1028                                             break;
1029                                             case 5000 /* PERM_FAILURE */ :
1030                                             break;
1031                                             default:
1032                                                 throw(robj);
1033                                             break;
1034                                         }
1035                                     }
1036                                 }
1037                             } else {
1038                                 obj.error.yns_alert(
1039                                     msg,
1040                                     document.getElementById('circStrings').getString('staff.circ.checkout.barcode.check_out_failed'),
1041                                     document.getElementById('circStrings').getString('staff.circ.checkout.ok.btn'),
1042                                     null,
1043                                     null,
1044                                     document.getElementById('circStrings').getString('staff.circ.confirm.msg')
1045                                 );
1046                             }
1047                         break;
1048                         case -1 /* NETWORK_FAILURE */ :
1049                             msg += document.getElementById('circStrings').getString('staff.circ.checkout.network_failure') + '\n';
1050                             found_handled = true;
1051                             obj.error.yns_alert(
1052                                 msg,
1053                                 document.getElementById('circStrings').getString('staff.circ.checkout.barcode.check_out_failed'),
1054                                 document.getElementById('circStrings').getString('staff.circ.checkout.ok.btn'),
1055                                 null,
1056                                 null,
1057                                 document.getElementById('circStrings').getString('staff.circ.confirm.msg')
1058                             );
1059                         break;
1060                         default:
1061                             msg += 'FIXME: ' + js2JSON(test_permit[i]) + '\n';
1062                             found_not_handled = true;
1063                         break;
1064                     }
1065                 }
1066                 
1067                 if (found_not_handled) {
1068                     obj.error.standard_unexpected_error_alert(msg,permit);
1069                 }
1070
1071                 obj.controller.view.checkout_barcode_entry_textbox.select();
1072                 obj.controller.view.checkout_barcode_entry_textbox.focus();
1073             }
1074
1075         } catch(E) {
1076             if (params.barcode) { delete obj._checkout_pending_hash[ params.barcode ];    }
1077             if (typeof E.ilsevent != 'undefined' && E.ilsevent == -1) {
1078                 obj.error.standard_network_error_alert(document.getElementById('circStrings').getString('staff.circ.checkout.suggest_offline'));
1079             } else {
1080                 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.checkout.barcode.check_out_failed'),E);
1081             }
1082             if (typeof obj.on_failure == 'function') {
1083                 obj.on_failure(E);
1084             }
1085             if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
1086                 obj.error.sdump('D_CIRC','circ.checkout: Calling external .on_failure()\n');
1087                 window.xulG.on_failure(E);
1088             } else {
1089                 obj.error.sdump('D_CIRC','circ.checkout: No external .on_failure()\n');
1090             }
1091         }
1092
1093     },
1094
1095     'on_checkout' : function() {
1096         this.controller.view.checkout_menu.selectedIndex = 0;
1097         this.controller.view.checkout_barcode_entry_textbox.disabled = false;
1098         this.controller.view.checkout_barcode_entry_textbox.value = '';
1099         this.controller.view.checkout_barcode_entry_textbox.focus();
1100         document.getElementById('duedate_hbox').hidden = false;
1101     },
1102
1103     'on_failure' : function() {
1104         this.controller.view.checkout_barcode_entry_textbox.select();
1105         this.controller.view.checkout_barcode_entry_textbox.focus();
1106     }
1107 };
1108
1109 dump('exiting circ.checkout.js\n');