COPY_NEEDED_FOR_HOLD
[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 }
10
11 circ.checkout.prototype = {
12
13         'init' : function( params ) {
14
15                 var obj = this;
16
17                 obj.patron_id = params['patron_id'];
18                 obj.patron = obj.network.simple_request('FM_AU_RETRIEVE_VIA_ID',[ses(),obj.patron_id]);
19
20                 JSAN.use('circ.util');
21                 var columns = circ.util.columns( 
22                         { 
23                                 'barcode' : { 'hidden' : false },
24                                 'title' : { 'hidden' : false },
25                                 'due_date' : { 'hidden' : false },
26                         } 
27                 );
28
29                 JSAN.use('util.list'); obj.list = new util.list('checkout_list');
30                 obj.list.init(
31                         {
32                                 'columns' : columns,
33                                 'map_row_to_column' : circ.util.std_map_row_to_column(),
34                                 'on_select' : function() {
35                                         var sel = obj.list.retrieve_selection();
36                                         document.getElementById('clip_button').disabled = sel.length < 1;
37                                 }
38                         }
39                 );
40                 
41                 JSAN.use('util.controller'); obj.controller = new util.controller();
42                 obj.controller.init(
43                         {
44                                 'control_map' : {
45                                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
46                                         'sel_clip' : [
47                                                 ['command'],
48                                                 function() { obj.list.clipboard(); }
49                                         ],
50                                         'checkout_menu_placeholder' : [
51                                                 ['render'],
52                                                 function(e) {
53                                                         return function() {
54                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional'); JSAN.use('util.fm_utils');
55                                                                 var items = [ [ 'Barcode:' , 'barcode' ] ].concat(
56                                                                         util.functional.map_list(
57                                                                                 util.functional.filter_list(
58                                                                                         obj.data.list.cnct,
59                                                                                         function(o) {
60                                                                                                 return util.fm_utils.compare_aou_a_is_b_or_ancestor(o.owning_lib(), obj.data.list.au[0].ws_ou());
61                                                                                         }
62                                                                                 ).sort(
63
64                                                                                         function(a,b) {
65                                                                                                 try { 
66                                                                                                         return util.fm_utils.sort_func_aou_by_depth_and_then_string(
67                                                                                                                 [ a.owning_lib(), a.name() ],
68                                                                                                                 [ b.owning_lib(), b.name() ]
69                                                                                                         );
70                                                                                                 } catch(E) {
71                                                                                                         alert('error in noncat sorting: ' + E);
72                                                                                                         return 0;
73                                                                                                 }
74                                                                                         }
75
76                                                                                 ),
77                                                                                 function(o) {
78                                                                                         return [ obj.data.hash.aou[ o.owning_lib() ].shortname() + ' : ' + o.name(), o.id() ];
79                                                                                 }
80                                                                         )
81                                                                 );
82                                                                 g.error.sdump('D_TRACE','items = ' + js2JSON(items));
83                                                                 util.widgets.remove_children( e );
84                                                                 var ml = util.widgets.make_menulist(
85                                                                         items
86                                                                 );
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 = '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_menu' : [
120                                                 ['change'],
121                                                 function(ev) { 
122                                                         try {
123                                                                 obj.check_date(ev.target);
124                                                                 ev.target.parentNode.setAttribute('style','');
125                                                         } catch(E) {
126                                                                 ev.target.parentNode.setAttribute('style','background-color: red');
127                                                                 alert(E + '\nUse this format: YYYY-MM-DD');
128                                                                 try {
129                                                                         ev.target.inputField.select();
130                                                                         ev.target.inputField.focus();
131                                                                 } catch(E) { /* this should work, let me try on other platforms */ 
132                                                                         obj.error.sdump('D_ERROR','menulist.inputField: ' + E);
133                                                                 }
134                                                         }
135                                                 }
136                                         ],
137                                         'cmd_broken' : [
138                                                 ['command'],
139                                                 function() { alert('Not Yet Implemented'); }
140                                         ],
141                                         'cmd_checkout_submit' : [
142                                                 ['command'],
143                                                 function() {
144                                                         var params = {}; var count = 1;
145
146                                                         if (obj.controller.view.checkout_menu.value == 'barcode' ||
147                                                                 obj.controller.view.checkout_menu.value == '') {
148                                                                 params.barcode = obj.controller.view.checkout_barcode_entry_textbox.value;
149                                                         } else {
150                                                                 params.noncat = 1;
151                                                                 params.noncat_type = obj.controller.view.checkout_menu.value;
152                                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
153                                                                 var r = window.prompt('Enter the number of ' + obj.data.hash.cnct[ params.noncat_type].name() + ' circulating:','1','Non-cataloged Items');
154                                                                 if (r) {
155                                                                         count = Number(r);
156                                                                         if (count > 0) {
157                                                                                 if (count > 99) {
158                                                                                         obj.error.yns_alert('You tried to circulate ' + count + ' ' + obj.data.hash.cnct[ params.noncat_type].name() + '.  The maximum is 99 per action.','Non-cataloged Circulation','OK',null,null,'Check here to confirm this message.');
159                                                                                         return;
160                                                                                 } else if (count > 20) {
161                                                                                         r = obj.error.yns_alert('Are you sure you want to circulate ' + count + ' ' + obj.data.hash.cnct[ params.noncat_type].name() + '?','Non-cataloged Circulation','Yes','No',null,'Check here to confirm this message.');
162                                                                                         if (r != 0) return;
163                                                                                 }
164                                                                         } else {
165                                                                                 r = obj.error.yns_alert('Error with non-cataloged checkout.  ' + r + ' is not a valid number.','Non-cataloged Circulation','Ok',null,null,'Check here to confirm this message.');
166                                                                                 return;
167                                                                         }
168                                                                 } else {
169                                                                         return;
170                                                                 }
171                                                         }
172                                                         for (var i = 0; i < count; i++) {
173                                                                 obj.checkout( params );
174                                                         }
175                                                 }
176                                         ],
177                                         'cmd_checkout_print' : [
178                                                 ['command'],
179                                                 function() {
180                                                         try {
181                                                                 obj.print();
182                                                         } catch(E) {
183                                                                 obj.error.standard_unexpected_error_alert('cmd_checkout_print',E);
184                                                         }
185
186                                                 }
187                                         ],
188                                         'cmd_checkout_reprint' : [
189                                                 ['command'],
190                                                 function() {
191                                                         JSAN.use('util.print'); var print = new util.print();
192                                                         print.reprint_last();
193                                                 }
194                                         ],
195                                         'cmd_checkout_done' : [
196                                                 ['command'],
197                                                 function() {
198                                                         try {
199                                                                 if (document.getElementById('checkout_auto').checked) {
200                                                                         obj.print(true,function() { 
201                                                                                 obj.list.clear();
202                                                                                 xulG.set_tab(urls.XUL_PATRON_BARCODE_ENTRY,{},{}); 
203                                                                         });
204                                                                 } else {
205                                                                         obj.print(false,function() {
206                                                                                 obj.list.clear();
207                                                                                 xulG.set_tab(urls.XUL_PATRON_BARCODE_ENTRY,{},{});
208                                                                         });
209                                                                 }
210                                                         } catch(E) {
211                                                                 obj.error.standard_unexpected_error_alert('cmd_checkout_done',E);
212                                                         }
213                                                 }
214                                         ],
215                                 }
216                         }
217                 );
218                 this.controller.render();
219                 //this.controller.view.checkout_barcode_entry_textbox.focus();
220
221                 this.check_disable();
222
223         },
224
225         'check_disable' : function() {
226                 var obj = this;
227                 try {
228                         if (typeof xulG.check_stop_checkouts == 'function') {
229                                 var disable = xulG.check_stop_checkouts();
230                                 if (disable) {
231                                         document.getElementById('checkout_submit_barcode_button').disabled = true;
232                                         document.getElementById('checkout_done').disabled = true;
233                                         obj.controller.view.checkout_menu.disabled = true;
234                                         obj.controller.view.checkout_barcode_entry_textbox.disabled = true;
235                                 } else {
236                                         document.getElementById('checkout_submit_barcode_button').disabled = false;
237                                         document.getElementById('checkout_done').disabled = false;
238                                         obj.controller.view.checkout_menu.disabled = false;
239                                         obj.controller.view.checkout_barcode_entry_textbox.disabled = false;
240                                 }
241                         }
242                 } catch(E) {
243                         obj.error.standard_unexpected_error_alert('Error determining whether to disable checkout.',E);
244                 }
245         },
246
247         'print' : function(silent,f) {
248                 var obj = this;
249                 try {
250                         dump( js2JSON( obj.list.dump_with_keys() ) + '\n' );
251                         obj.list.on_all_fleshed = function() {
252                                 try {
253                                         var params = { 
254                                                 'patron' : obj.patron, 
255                                                 'lib' : obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ],
256                                                 'staff' : obj.data.list.au[0],
257                                                 'header' : obj.data.print_list_templates.checkout.header,
258                                                 'line_item' : obj.data.print_list_templates.checkout.line_item,
259                                                 'footer' : obj.data.print_list_templates.checkout.footer,
260                                                 'type' : obj.data.print_list_templates.checkout.type,
261                                                 'list' : obj.list.dump_with_keys(),
262                                         };
263                                         if (silent) params.no_prompt = true;
264                                         JSAN.use('util.print'); var print = new util.print();
265                                         print.tree_list( params );
266                                         setTimeout(function(){obj.list.on_all_fleshed = null;if (typeof f == 'function') f();},0);
267                                 } catch(E) {
268                                         obj.error.standard_unexpected_error_alert('print',E);
269                                 }
270                         }
271                         obj.list.full_retrieve();
272                 } catch(E) {
273                         obj.error.standard_unexpected_error_alert('print',E);
274                 }
275         },
276
277         'check_date' : function(node) {
278                 JSAN.use('util.date');
279                 try {
280                         if (node.value == 'Normal') return true;
281                         var pattern = node.value.match(/Today \+ (\d+) days/);
282                         if (pattern) {
283                                 var today = new Date();
284                                 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*pattern[1] );
285                                 node.value = util.date.formatted_date(todayPlus,"%F");
286                         }
287                         if (! util.date.check('YYYY-MM-DD',node.value) ) { throw('Invalid Date'); }
288                         if (util.date.check_past('YYYY-MM-DD',node.value) ) { throw('Due date needs to be after today.'); }
289                         if ( util.date.formatted_date(new Date(),'%F') == node.value) { throw('Due date needs to be after today.'); }
290                         return true;
291                 } catch(E) {
292                         throw(E);
293                 }
294         },
295
296         'checkout' : function(params) {
297                 var obj = this;
298
299                 try { obj.check_date(obj.controller.view.checkout_duedate_menu); } catch(E) { return; }
300                 if (obj.controller.view.checkout_duedate_menu.value != 'Normal') {
301                         params.due_date = obj.controller.view.checkout_duedate_menu.value;
302                 }
303
304                 if (! (params.barcode||params.noncat)) return;
305
306                 /**********************************************************************************************************************/
307                 /* This does the actual checkout/renewal, but is called after a permit test further below */
308                 function check_out(params) {
309
310                         var checkout = obj.network.request(
311                                 api.CHECKOUT.app,
312                                 api.CHECKOUT.method,
313                                 [ ses(), params ]
314                         );
315
316                         if (checkout.ilsevent == 0) {
317
318                                 if (!checkout.payload) checkout.payload = {};
319
320                                 if (!checkout.payload.circ) {
321                                         checkout.payload.circ = new aoc();
322                                         /*********************************************************************************************/
323                                         /* Non Cat */
324                                         if (checkout.payload.noncat_circ) {
325                                                 checkout.payload.circ.circ_lib( checkout.payload.noncat_circ.circ_lib() );
326                                                 checkout.payload.circ.circ_staff( checkout.payload.noncat_circ.staff() );
327                                                 checkout.payload.circ.usr( checkout.payload.noncat_circ.patron() );
328                                                 
329                                                 JSAN.use('util.date');
330                                                 var c = checkout.payload.noncat_circ.circ_time();
331                                                 var d = c == "now" ? new Date() : util.date.db_date2Date( c );
332                                                 var t =obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ];
333                                                 var cd = t.circ_duration() || "14 days";
334                                                 var i = util.date.interval_to_seconds( cd ) * 1000;
335                                                 d.setTime( Date.parse(d) + i );
336                                                 checkout.payload.circ.due_date( util.date.formatted_date(d,'%F') );
337
338                                         }
339                                 }
340
341                                 if (!checkout.payload.record) {
342                                         checkout.payload.record = new mvr();
343                                         /*********************************************************************************************/
344                                         /* Non Cat */
345                                         if (checkout.payload.noncat_circ) {
346                                                 checkout.payload.record.title(
347                                                         obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ].name()
348                                                 );
349                                         }
350                                 }
351
352                                 if (!checkout.payload.copy) {
353                                         checkout.payload.copy = new acp();
354                                         checkout.payload.copy.barcode( '' );
355                                 }
356
357                                 /*********************************************************************************************/
358                                 /* Override mvr title/author with dummy title/author for Pre cat */
359                                 if (checkout.payload.copy.dummy_title())  checkout.payload.record.title( checkout.payload.copy.dummy_title() );
360                                 if (checkout.payload.copy.dummy_author())  checkout.payload.record.author( checkout.payload.copy.dummy_author() );
361
362                                 obj.list.append(
363                                         {
364                                                 'row' : {
365                                                         'my' : {
366                                                         'circ' : checkout.payload.circ,
367                                                         'mvr' : checkout.payload.record,
368                                                         'acp' : checkout.payload.copy
369                                                         }
370                                                 }
371                                         //I could override map_row_to_column here
372                                         }
373                                 );
374                                 if (typeof obj.on_checkout == 'function') {
375                                         obj.on_checkout(checkout.payload);
376                                 }
377                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_list_change == 'function') {
378                                         window.xulG.on_list_change(checkout.payload);
379                                 } else {
380                                         obj.error.sdump('D_CIRC','circ.checkout: No external .on_checkout()\n');
381                                 }
382
383                         } else {
384                                 throw(checkout);
385                         }
386                 }
387
388                 /**********************************************************************************************************************/
389                 /* Permissibility test before checkout */
390                 try {
391
392                         params.patron = obj.patron_id;
393
394                         var permit = obj.network.request(
395                                 api.CHECKOUT_PERMIT.app,
396                                 api.CHECKOUT_PERMIT.method,
397                                 [ ses(), params ],
398                                 null,
399                                 {
400                                         'title' : 'Override Checkout Failure?',
401                                         'overridable_events' : [ 
402                                                 1212 /* PATRON_EXCEEDS_OVERDUE_COUNT */,
403                                                 1213 /* PATRON_BARRED */,
404                                                 1215 /* CIRC_EXCEEDS_COPY_RANGE */,
405                                                 7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */,
406                                                 7003 /* COPY_CIRC_NOT_ALLOWED */,
407                                                 7004 /* COPY_NOT_AVAILABLE */, 
408                                                 7006 /* COPY_IS_REFERENCE */, 
409                                                 7007 /* COPY_NEEDED_FOR_HOLD */, 
410                                                 7010 /* COPY_ALERT_MESSAGE */,
411                                                 7013 /* PATRON_EXCEEDS_FINES */,
412                                         ],
413                                         'text' : {
414                                                 '7004' : function(r) {
415                                                         //return obj.data.hash.ccs[ r.payload ].name();
416                                                         return r.payload.status().name();
417                                                         //return r.payload.name();
418                                                         //return r.payload;
419                                                 },
420                                                 '7010' : function(r) {
421                                                         return r.payload;
422                                                 },
423                                         }
424                                 }
425                         );
426
427                         if (!permit) throw(permit);
428
429                         function test_event(list,ev) {
430                                 if (typeof list.ilsevent != 'undefined' ) {
431                                         if (list.ilsevent == ev) {
432                                                 return list;
433                                         } else {
434                                                 return false;
435                                         }
436                                 } else {
437                                         for (var i = 0; i < list.length; i++) {
438                                                 if (typeof list[i].ilsevent != 'undefined') {
439                                                         if (list[i].ilsevent == ev) return list[i];
440                                                 }
441                                         }
442                                         return false;
443                                 }
444                         }
445
446                         /**********************************************************************************************************************/
447                         /* Normal case, proceed with checkout */
448                         if (permit.ilsevent == 0) {
449
450                                 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
451                                 params.permit_key = permit.payload;
452                                 check_out( params );
453
454                         /**********************************************************************************************************************/
455                         /* Item not cataloged or barcode mis-scan.  Prompt for pre-cat option */
456                         } else {
457                         
458                                 var found_handled = false; var found_not_handled = false; var msg = ''; 
459
460                                 if (test_event(permit,1202 /* ITEM_NOT_CATALOGED */)) {
461
462                                         if ( 1 == obj.error.yns_alert(
463                                                 'Mis-scan or non-cataloged item.  Checkout as a pre-cataloged item?',
464                                                 'Alert',
465                                                 'Cancel',
466                                                 'Pre-Cat',
467                                                 null,
468                                                 'Check here to confirm this action'
469                                         ) ) {
470
471                                                 obj.data.dummy_title = ''; obj.data.dummy_author = ''; obj.data.stash('dummy_title','dummy_author');
472                                                 JSAN.use('util.window'); var win = new util.window();
473                                                 win.open(urls.XUL_PRE_CAT, 'dummy_fields', 'chrome,resizable,modal');
474                                                 obj.data.stash_retrieve();
475
476                                                 params.permit_key = permit.payload;
477                                                 params.dummy_title = obj.data.dummy_title;
478                                                 params.dummy_author = obj.data.dummy_author;
479                                                 params.precat = 1;
480
481                                                 if (params.dummy_title != '') { check_out( params ); } else { throw('Checkout cancelled'); }
482                                         } 
483                                 };
484
485                                 var test_permit;
486                                 if (typeof permit.ilsevent != 'undefined') { test_permit = [ permit ]; } else { test_permit = permit; }
487
488                                 var stop_checkout = false;
489                                 for (var i = 0; i < test_permit.length; i++) {
490                                         switch(test_permit[i].ilsevent) {
491                                                 case 1217 /* PATRON_INACTIVE */ :
492                                                 case 1224 /* PATRON_ACCOUNT_EXPIRED */ :
493                                                         stop_checkout = true;
494                                                 break;
495                                         }
496                                 }
497
498                                 for (var i = 0; i < test_permit.length; i++) {
499                                         dump('found [' + test_permit[i].ilsevent + ']\n');
500                                         switch(test_permit[i].ilsevent) {
501                                                 case 1212 /* PATRON_EXCEEDS_OVERDUE_COUNT */ :
502                                                         found_handled = true;
503                                                 break;
504                                                 case 1213 /* PATRON_BARRED */ :
505                                                         found_handled = true;
506                                                 break;
507                                                 case 1215 /* CIRC_EXCEEDS_COPY_RANGE */ :
508                                                         found_handled = true;
509                                                 break;
510                                                 case 1217 /* PATRON_INACTIVE */ :
511                                                         found_handled = true;
512                                                         msg += 'This account is inactive and may not circulate items.\n';
513                                                         obj.error.yns_alert(msg,'Check Out Failed','OK',null,null,'Check here to confirm this message');
514                                                 break;
515                                                 case 1224 /* PATRON_ACCOUNT_EXPIRED */ :
516                                                         found_handled = true;
517                                                         msg += 'This account has expired  and may not circulate items.\n';
518                                                         obj.error.yns_alert(msg,'Check Out Failed','OK',null,null,'Check here to confirm this message');
519                                                 break;
520                                                 case 7013 /* PATRON_EXCEEDS_FINES */ :
521                                                         found_handled = true;
522                                                 break;
523                                                 case 7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */ :
524                                                         found_handled = true;
525                                                 break;
526                                                 case 7003 /* COPY_CIRC_NOT_ALLOWED */ :
527                                                         found_handled = true;
528                                                 break;
529                                                 case 7004 /* COPY_NOT_AVAILABLE */ :
530                                                         msg += test_permit[i].desc + '\n' + 'Copy status = ' + ( test_permit[i].payload.status().name() ) + '\n';
531                                                         found_handled = true;
532                                                 break;
533                                                 case 7006 /* COPY_IS_REFERENCE */ :
534                                                         msg += test_permit[i].desc + '\n';
535                                                         found_handled = true;
536                                                 break;
537                                                 case 7007 /* COPY_NEEDED_FOR_HOLD */ :
538                                                         msg += test_permit[i].desc + '\n';
539                                                         found_handled = true;
540                                                 break;
541                                                 case 7009 /* CIRC_CLAIMS_RETURNED */ :
542                                                         msg += test_permit[i].desc + '\n';
543                                                         obj.error.yns_alert(msg,'Check Out Failed','OK',null,null,'Check here to confirm this message');
544                                                         found_handled = true;
545                                                 break;
546                                                 case 7010 /* COPY_ALERT_MESSAGE */ :
547                                                         msg += test_permit[i].desc + '\n' + 'Alert Message = ' + test_permit[i].payload + '\n';
548                                                         found_handled = true;
549                                                 break;
550                                                 case 1202 /* ITEM_NOT_CATALOGED */ :
551                                                         found_handled = true;
552                                                 break;
553                                                 case 5000 /* PERM_FAILURE */ :
554                                                         msg += test_permit[i].desc + '\n' + 'Permission Denied = ' + test_permit[i].ilsperm + '\n';
555                                                         found_handled = true;
556                                                 break;
557                                                 case 1702 /* OPEN_CIRCULATION_EXISTS */ :
558                                                         msg += test_permit[i].desc + '\n';
559                                                         found_handled = true;
560
561                                                         var my_copy = obj.network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[params.barcode]);
562                                                         if (typeof my_copy.ilsevent != 'undefined') throw(my_copy);
563                                                         var my_circ = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),my_copy.id(),1]);
564                                                         if (typeof my_circ.ilsevent != 'undefined') throw(my_copy);
565                                                         my_circ = my_circ[0];
566                                                         var due_date = my_circ.due_date() ? my_circ.due_date().substr(0,10) : null;
567                                                         JSAN.use('util.date'); var today = util.date.formatted_date(new Date(),'%F');
568                                                         if (due_date) if (today > due_date) msg += '\nThis item was due on ' + due_date + '.\n';
569                                                         if (! stop_checkout ) {
570                                                                 var r = obj.error.yns_alert(msg,'Check Out Failed','Cancel','Checkin then Checkout', due_date ? (today > due_date ? 'Forgiving Checkin then Checkout' : null) : null,'Check here to confirm this message');
571                                                                 JSAN.use('circ.util');
572                                                                 switch(r) {
573                                                                         case 1:
574                                                                                 circ.util.checkin_via_barcode( ses(), params.barcode );
575                                                                                 obj.checkout(params);
576                                                                         break;
577                                                                         case 2:
578                                                                                 circ.util.checkin_via_barcode( ses(), params.barcode, due_date );
579                                                                                 obj.checkout(params);
580                                                                         break;
581                                                                 }
582                                                         } else {
583                                                                 obj.error.yns_alert(msg,'Check Out Failed','OK',null,null,'Check here to confirm this message');
584                                                         }
585                                                 break;
586                                                 case 7014 /* COPY_IN_TRANSIT */ :
587                                                         msg += test_permit[i].desc + '\n';
588                                                         found_handled = true;
589                                                         if (! stop_checkout ) {
590                                                                 var r = obj.error.yns_alert(msg,'Check Out Failed','Cancel','Abort Transit then Checkout',null,'Check here to confirm this message');
591                                                                 switch(r) {
592                                                                         case 1:
593                                                                                 var robj = obj.network.simple_request('FM_ATC_VOID',[ ses(), { 'barcode' : params.barcode } ]);
594                                                                                 if (typeof robj.ilsevent == 'undefined') {
595                                                                                         obj.checkout(params);
596                                                                                 } else {
597                                                                                         switch(robj.ilsevent) {
598                                                                                                 case 1225 /* TRANSIT_ABORT_NOT_ALLOWED */ :
599                                                                                                         alert(robj.desc);
600                                                                                                 break;
601                                                                                                 case 5000 /* PERM_FAILURE */ :
602                                                                                                 break;
603                                                                                                 default:
604                                                                                                         throw(robj);
605                                                                                                 break;
606                                                                                         }
607                                                                                 }
608                                                                         break;
609                                                                 }
610                                                         } else {
611                                                                 obj.error.yns_alert(msg,'Check Out Failed','OK',null,null,'Check here to confirm this message');
612                                                         }
613                                                 break;
614                                                 case -1 /* NETWORK_FAILURE */ :
615                                                         msg += 'There was a network failure.\n';
616                                                         found_handled = true;
617                                                         obj.error.yns_alert(msg,'Check Out Failed','OK',null,null,'Check here to confirm this message');
618                                                 break;
619                                                 default:
620                                                         msg += 'FIXME: ' + js2JSON(test_permit[i]) + '\n';
621                                                         found_not_handled = true;
622                                                 break;
623                                         }
624                                 }
625                                 
626                                 if (found_not_handled) {
627                                         obj.error.standard_unexpected_error_alert(msg,permit);
628                                 }
629
630                                 obj.controller.view.checkout_barcode_entry_textbox.select();
631                                 obj.controller.view.checkout_barcode_entry_textbox.focus();
632                         }
633
634                 } catch(E) {
635                         if (typeof E.ilsevent != 'undefined' && E.ilsevent == -1) {
636                                 obj.error.standard_network_error_alert('Check Out Failed.  If you wish to use the offline interface, in the top menubar select Circulation -> Offline Interface');
637                         } else {
638                                 obj.error.standard_unexpected_error_alert('Check Out Failed',E);
639                         }
640                         if (typeof obj.on_failure == 'function') {
641                                 obj.on_failure(E);
642                         }
643                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
644                                 obj.error.sdump('D_CIRC','circ.checkout: Calling external .on_failure()\n');
645                                 window.xulG.on_failure(E);
646                         } else {
647                                 obj.error.sdump('D_CIRC','circ.checkout: No external .on_failure()\n');
648                         }
649                 }
650
651         },
652
653         'on_checkout' : function() {
654                 this.controller.view.checkout_menu.selectedIndex = 0;
655                 this.controller.view.checkout_barcode_entry_textbox.disabled = false;
656                 this.controller.view.checkout_barcode_entry_textbox.value = '';
657                 this.controller.view.checkout_barcode_entry_textbox.focus();
658                 document.getElementById('duedate_hbox').hidden = false;
659         },
660
661         'on_failure' : function() {
662                 this.controller.view.checkout_barcode_entry_textbox.select();
663                 this.controller.view.checkout_barcode_entry_textbox.focus();
664         }
665 }
666
667 dump('exiting circ.checkout.js\n');