]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkin.js
Floating Groups
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / checkin.js
1 dump('entering circ.checkin.js\n');
2
3 if (typeof circ == 'undefined') circ = {};
4 circ.checkin = 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('util.barcode');
9     JSAN.use('util.date');
10     this.OpenILS = {}; JSAN.use('OpenILS.data'); this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
11     this.data = this.OpenILS.data;
12 }
13
14 circ.checkin.prototype = {
15
16     'selection_list' : [],
17     'row_map' : {},
18
19     'init' : function( params ) {
20
21         var obj = this;
22
23         JSAN.use('circ.util'); JSAN.use('patron.util');
24         var columns = circ.util.columns( 
25             { 
26                 'barcode' : { 'hidden' : false },
27                 'title' : { 'hidden' : false },
28                 'location' : { 'hidden' : false },
29                 'status' : { 'hidden' : false },
30                 'route_to' : { 'hidden' : false },
31                 'alert_message' : { 'hidden' : false },
32                 'checkin_time' : { 'hidden' : false }
33             },
34             {
35                 'except_these' : [ 'uses', 'checkin_time_full' ]
36             }
37         ).concat(
38             patron.util.columns( { 'family_name' : { 'hidden' : 'false' } } )
39
40         ).concat(
41             patron.util.mbts_columns( {}, { 'except_these' : [ 'total_paid', 'total_owed', 'xact_start', 'xact_finish', 'xact_type' ] } )
42
43         ).sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
44
45         JSAN.use('util.list'); obj.list = new util.list('checkin_list');
46         obj.list.init(
47             {
48                 'columns' : columns,
49                 'retrieve_row' : obj.gen_list_retrieve_row_func(),
50                 'on_select' : function(ev) {
51                     try {
52                         JSAN.use('util.functional');
53                         var sel = obj.list.retrieve_selection();
54                         obj.selection_list = util.functional.map_list(
55                             sel,
56                             function(o) { 
57                                 if (o.getAttribute('retrieve_id')) {
58                                     try {
59                                         var p = JSON2js(o.getAttribute('retrieve_id')); 
60                                         p.unique_row_counter = o.getAttribute('unique_row_counter'); 
61                                         o.setAttribute('id','_checkin_list_row_'+p.unique_row_counter);
62                                         return p; 
63                                     } catch(E) {
64                                         return -1;
65                                     }
66                                 } else {
67                                     return -1;
68                                 }
69                             }
70                         );
71                         obj.selection_list = util.functional.filter_list(
72                             obj.selection_list,
73                             function(o) {
74                                 return o != -1;
75                             }
76                         );
77                         obj.error.sdump('D_TRACE', 'circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
78                         if (obj.selection_list.length == 0) {
79                             obj.controller.view.sel_edit.setAttribute('disabled','true');
80                             obj.controller.view.sel_backdate.setAttribute('disabled','true');
81                             obj.controller.view.sel_opac.setAttribute('disabled','true');
82                             obj.controller.view.sel_opac_holds.setAttribute('disabled','true');
83                             obj.controller.view.sel_patron.setAttribute('disabled','true');
84                             obj.controller.view.sel_last_patron.setAttribute('disabled','true');
85                             obj.controller.view.sel_copy_details.setAttribute('disabled','true');
86                             obj.controller.view.sel_bucket.setAttribute('disabled','true');
87                             obj.controller.view.sel_spine.setAttribute('disabled','true');
88                             obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
89                             obj.controller.view.sel_clip.setAttribute('disabled','true');
90                             obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
91                             obj.controller.view.sel_mark_missing_pieces.setAttribute('disabled','true');
92                         } else {
93                             obj.controller.view.sel_edit.setAttribute('disabled','false');
94                             obj.controller.view.sel_backdate.setAttribute('disabled','false');
95                             obj.controller.view.sel_opac.setAttribute('disabled','false');
96                             obj.controller.view.sel_opac_holds.setAttribute('disabled','false');
97                             obj.controller.view.sel_patron.setAttribute('disabled','false');
98                             obj.controller.view.sel_last_patron.setAttribute('disabled','false');
99                             obj.controller.view.sel_copy_details.setAttribute('disabled','false');
100                             obj.controller.view.sel_bucket.setAttribute('disabled','false');
101                             obj.controller.view.sel_spine.setAttribute('disabled','false');
102                             obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
103                             obj.controller.view.sel_clip.setAttribute('disabled','false');
104                             obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
105                             obj.controller.view.sel_mark_missing_pieces.setAttribute('disabled','false');
106                         }
107
108                         // This is for updating that label in the upper left of the UI that shows Item already checked-in, etc.
109                         // Our purpose here is to show the bill amount associated with a specific transaction whenever that
110                         // transaction is selected in the list
111                         if (obj.selection_list.length == 1) {
112                             var unique_row_counter = obj.selection_list[0].unique_row_counter;
113                             var node = $('_checkin_list_row_'+unique_row_counter);
114                             if (node && node.getAttribute('no_change_label_label')) {
115                                 $('no_change_label').setAttribute('unique_row_counter',unique_row_counter);
116                                 $('no_change_label').setAttribute('value',node.getAttribute('no_change_label_label'));
117                                 $('no_change_label').setAttribute('onclick',node.getAttribute('no_change_label_click'));
118                                 $('no_change_label').setAttribute('hidden','false');
119                                 addCSSClass($('no_change_label'),'click_link'); 
120                             }
121                         }
122                     } catch(E) {
123                         alert('FIXME: ' + E);
124                     }
125                 }
126             }
127         );
128         
129         JSAN.use('util.controller'); obj.controller = new util.controller();
130         obj.controller.init(
131             {
132                 'control_map' : {
133                     'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
134                     'sel_clip' : [
135                         ['command'],
136                         function() { 
137                             obj.list.clipboard(); 
138                             obj.controller.view.checkin_barcode_entry_textbox.focus();
139                         }
140                     ],
141                     'sel_edit' : [
142                         ['command'],
143                         function() {
144                             try {
145                                 obj.spawn_copy_editor();
146                             } catch(E) {
147                                 alert(E);
148                             }
149                         }
150                     ],
151                     'sel_spine' : [
152                         ['command'],
153                         function() {
154                             JSAN.use('cat.util');
155                             cat.util.spawn_spine_editor(obj.selection_list);
156                         }
157                     ],
158                     'sel_opac' : [
159                         ['command'],
160                         function() {
161                             JSAN.use('cat.util');
162                             cat.util.show_in_opac(obj.selection_list);
163                         }
164                     ],
165                     'sel_opac_holds' : [
166                         ['command'],
167                         function() {
168                             JSAN.use('cat.util');
169                             cat.util.show_in_opac(obj.selection_list,{default_view:'hold_browser'});
170                         }
171                     ],
172                     'sel_transit_abort' : [
173                         ['command'],
174                         function() {
175                             JSAN.use('circ.util');
176                             circ.util.abort_transits(obj.selection_list);
177                         }
178                     ],
179                     'sel_patron' : [
180                         ['command'],
181                         function() {
182                             JSAN.use('circ.util');
183                             circ.util.show_last_few_circs(obj.selection_list);
184                         }
185                     ],
186                     'sel_last_patron' : [
187                         ['command'],
188                         function() {
189                             var patrons = {};
190                             for (var i = 0; i < obj.selection_list.length; i++) {
191                                 var circs = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),obj.selection_list[i].copy_id,1]);
192                                 if (circs.length > 0) {
193                                     patrons[circs[0].usr()] = 1;
194                                 } else {
195                                     alert(document.getElementById('circStrings').getFormattedString('staff.circ.item_no_circs', [obj.selection_list[i].barcode]));
196                                 }
197                             }
198                             for (var i in patrons) {
199                                 xulG.new_patron_tab({},{'id' : i});
200                             }
201                         }
202                     ],
203                     'sel_copy_details' : [
204                         ['command'],
205                         function() {
206                             JSAN.use('circ.util');
207                             circ.util.item_details_new(
208                                 util.functional.map_list(
209                                     obj.selection_list,
210                                     function(o) { return o.barcode; }
211                                 )
212                             );
213                         }
214                     ],
215                     'sel_backdate' : [
216                         ['command'],
217                         function() {
218                             try {
219                                 JSAN.use('circ.util');
220                                 var circ_ids = []; var circ_row_map = {};
221                                 for (var i = 0; i < obj.selection_list.length; i++) {
222                                     var circ_id = obj.selection_list[i].circ_id; 
223                                     var copy_id = obj.selection_list[i].copy_id; 
224                                     if (!circ_id) {
225                                         var blob = obj.network.simple_request('FM_ACP_DETAILS',[ses(),copy_id]);
226                                         if (blob.circ) circ_id = blob.circ.id();
227                                     }
228                                     if (!circ_id) continue;
229                                     if (! circ_row_map[ circ_id ]) { circ_row_map[ circ_id ] = []; }
230                                     circ_row_map[ circ_id ].push( obj.selection_list[i].unique_row_counter );
231                                     circ_ids.push( circ_id );
232                                 }
233                                 var robj = circ.util.backdate_post_checkin( circ_ids );
234                                 if (robj.complete) {
235                                     var bad_circs = {};
236                                     for (var i = 0; i < robj.bad_circs.length; i++) {
237                                         bad_circs[ robj.bad_circs[i].circ_id ] = robj.bad_circs[i].result;
238                                     }
239                                     for (var circ_id in circ_row_map) {
240                                         var row_array = circ_row_map[circ_id];
241                                         for (var i = 0; i < row_array.length; i++) {
242                                             var row_data = obj.row_map[ row_array[i] ];
243                                             if (row_data.row.my.circ) {
244                                                 if (bad_circs[ circ_id ]) {
245                                                     row_data.row_properties = 'backdate_failed';
246                                                 } else {
247                                                     row_data.row_properties = 'backdate_succeeded';
248                                                     row_data.row.my.circ.checkin_time( robj.backdate );
249                                                 }
250                                             }
251                                             obj.list.refresh_row( row_data );
252                                         } 
253                                     }
254                                 }
255                             } catch(E) {
256                                 alert('Error in checkin.js, sel_backdate: ' + E);
257                             }
258                         }
259                     ],
260                     'sel_mark_items_damaged' : [
261                         ['command'],
262                         function() {
263                             var funcs = [];
264                             JSAN.use('cat.util'); JSAN.use('util.functional');
265                             cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
266                         }
267                     ],
268                     'sel_mark_missing_pieces' : [
269                         ['command'],
270                         function() {
271                             var funcs = [];
272                             JSAN.use('cat.util'); JSAN.use('util.functional');
273                             cat.util.mark_item_as_missing_pieces( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
274                         }
275                     ],
276                     'sel_bucket' : [
277                         ['command'],
278                         function() {
279                             JSAN.use('cat.util');
280                             cat.util.add_copies_to_bucket(obj.selection_list);
281                         }
282                     ],
283                     'checkin_barcode_entry_textbox' : [
284                         ['keypress'],
285                         function(ev) {
286                             if (ev.keyCode && ev.keyCode == 13) {
287                                 obj.checkin();
288                             }
289                         }
290                     ],
291                     'checkin_effective_date_label' : [
292                         ['render'],
293                         function(e) {
294                             return function() {
295                                 obj.controller.view.checkin_effective_datepicker.value =
296                                     util.date.formatted_date(new Date(),'%F');
297                             };
298                         }
299                     ],
300                     'checkin_effective_datepicker' : [
301                         ['change'],
302                         function(ev) {
303                             if (ev.target.nodeName == 'datepicker') {
304                                 try {
305                                     if ( ev.target.dateValue > new Date() ) throw(document.getElementById('circStrings').getString('staff.circ.future_date'));
306                                     var x = document.getElementById('background');
307                                     if (x) {
308                                         if ( ev.target.value == util.date.formatted_date(new Date(),'%F') ) {
309                                             //addCSSClass(x,'checkin_screen_normal');
310                                             removeCSSClass(x,'checkin_screen_backdating');
311                                             removeCSSClass(document.getElementById('background'),'checkin_screen_do_not_alert_on_precat');
312                                             removeCSSClass(document.getElementById('background'),'checkin_screen_suppress_holds_and_transits');
313                                             removeCSSClass(document.getElementById('background'),'checkin_screen_amnesty_mode');
314                                             removeCSSClass(document.getElementById('background'),'checkin_screen_checkin_auto_print_slips');
315                                             document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
316                                         } else {
317                                             addCSSClass(x,'checkin_screen_backdating');
318                                             //removeCSSClass(x,'checkin_screen_normal');
319                                             document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getFormattedString('staff.circ.backdated_checkin', [ev.target.value]));
320                                         }
321                                     }
322                                 } catch(E) {
323                                     var x = document.getElementById('background');
324                                     if (x) {
325                                         //addCSSClass(x,'checkin_screen_normal');
326                                         removeCSSClass(x,'checkin_screen_backdating');
327                                         removeCSSClass(document.getElementById('background'),'checkin_screen_do_not_alert_on_precat');
328                                         removeCSSClass(document.getElementById('background'),'checkin_screen_suppress_holds_and_transits');
329                                         removeCSSClass(document.getElementById('background'),'checkin_screen_amnesty_mode');
330                                         removeCSSClass(document.getElementById('background'),'checkin_screen_checkin_auto_print_slips');
331                                         document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
332                                     }
333                                     dump('checkin:effective_date: ' + E + '\n');
334                                     ev.target.disabled = true;
335                                     //alert(document.getElementById('circStrings').getFormattedString('staff.circ.backdate.exception', [E]));
336                                     ev.target.value = util.date.formatted_date(new Date(),'%F');
337                                     ev.target.disabled = false;
338                                     JSAN.use('util.sound'); var sound = new util.sound(); sound.bad();
339                                     
340                                 }
341                             }
342                         }
343                     ],
344                     'cmd_broken' : [
345                         ['command'],
346                         function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
347                     ],
348                     'cmd_checkin_submit_barcode' : [
349                         ['command'],
350                         function() {
351                             obj.checkin();
352                         }
353                     ],
354                     'cmd_checkin_print' : [
355                         ['command'],
356                         function() {
357                             var p = { 
358                                 'printer_context' : 'receipt',
359                                 'template' : 'checkin'
360                             };
361                             obj.list.print(p);
362                         }
363                     ],
364                     'cmd_csv_to_clipboard' : [ ['command'], function() { 
365                         obj.list.dump_csv_to_clipboard(); 
366                         obj.controller.view.checkin_barcode_entry_textbox.focus();
367                     } ],
368                     'cmd_csv_to_printer' : [ ['command'], function() { 
369                         obj.list.dump_csv_to_printer(); 
370                         obj.controller.view.checkin_barcode_entry_textbox.focus();
371                     } ],
372                     'cmd_csv_to_file' : [ ['command'], function() { 
373                         obj.list.dump_csv_to_file( { 'defaultFileName' : 'checked_in.txt' } ); 
374                         obj.controller.view.checkin_barcode_entry_textbox.focus();
375                     } ],
376                     'cmd_do_not_alert_on_precat' : [ ['command'], function(ev) {
377                         dump('in cmd_do_not_alert_on_precat\n');
378                         var bg = document.getElementById('background');
379                         var cb = document.getElementById('do_not_alert_on_precat');
380                         var ind = document.getElementById('do_not_alert_on_precat_indicator');
381                         var cn = 'checkin_screen_do_not_alert_on_precat';
382                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
383                         ind.hidden = cb.getAttribute('checked') != 'true'; 
384                         document.getElementById('checkin_barcode_entry_textbox').focus();
385                         return true;
386                     } ],
387                     'cmd_suppress_holds_and_transits' : [ ['command'], function(ev) {
388                         dump('in cmd_suppress_holds_and_transits\n');
389                         var bg = document.getElementById('background');
390                         var cb = document.getElementById('suppress_holds_and_transits');
391                         var ind = document.getElementById('suppress_holds_and_transits_indicator');
392                         var cn = 'checkin_screen_suppress_holds_and_transits';
393                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
394                         ind.hidden = cb.getAttribute('checked') != 'true'; 
395                         document.getElementById('checkin_barcode_entry_textbox').focus();
396                         return true;
397                     } ],
398                     'cmd_amnesty_mode' : [ ['command'], function(ev) {
399                         dump('in cmd_amnesty_mode\n');
400                         var bg = document.getElementById('background');
401                         var cb = document.getElementById('amnesty_mode');
402                         var ind = document.getElementById('amnesty_mode_indicator');
403                         var cn = 'checkin_screen_amnesty_mode';
404                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
405                         ind.hidden = cb.getAttribute('checked') != 'true'; 
406                         document.getElementById('checkin_barcode_entry_textbox').focus();
407                         return true;
408                     } ],
409                     'cmd_checkin_auto_print_slips' : [ ['command'], function(ev) {
410                         dump('in cmd_checkin_auto_print_slips\n');
411                         var bg = document.getElementById('background');
412                         var cb = document.getElementById('checkin_auto_print_slips');
413                         var ind = document.getElementById('checkin_auto_print_slips_indicator');
414                         var cn = 'checkin_screen_checkin_auto_print_slips';
415                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
416                         ind.hidden = cb.getAttribute('checked') != 'true'; 
417                         document.getElementById('checkin_barcode_entry_textbox').focus();
418                         return true;
419                     } ],
420                     'cmd_checkin_clear_shelf_expired' : [ ['command'], function(ev) {
421                         dump('in cmd_checkin_clear_shelf_expired\n');
422                         var bg = document.getElementById('background');
423                         var cb = document.getElementById('checkin_clear_shelf_expired');
424                         var ind = document.getElementById('checkin_clear_shelf_expired_indicator');
425                         var cn = 'checkin_screen_checkin_clear_shelf_expired';
426                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
427                         ind.hidden = cb.getAttribute('checked') != 'true'; 
428                         document.getElementById('checkin_barcode_entry_textbox').focus();
429                         return true;
430                     } ],
431                     'cmd_checkin_auto_retarget' : [ ['command'], function(ev) {
432                         dump('in cmd_checkin_auto_retarget\n');
433                         var bg = document.getElementById('background');
434                         var cb = document.getElementById('checkin_auto_retarget');
435                         var cb2 = document.getElementById('checkin_auto_retarget_all');
436                         var ind = document.getElementById('checkin_auto_retarget_indicator');
437                         var ind2 = document.getElementById('checkin_auto_retarget_all_indicator');
438                         var cn = 'checkin_screen_checkin_auto_retarget';
439                         var cn2 = 'checkin_screen_checkin_auto_retarget_all';
440                         if (cb.getAttribute('checked') == 'true') {
441                             if(cb2.getAttribute('checked') == 'true') {
442                                 removeCSSClass(bg,cn);
443                                 addCSSClass(bg,cn2);
444                                 ind.hidden = true;
445                                 ind2.hidden = false;
446                             } else {
447                                 addCSSClass(bg,cn);
448                                 removeCSSClass(bg,cn2);
449                                 ind.hidden = false;
450                                 ind2.hidden = true;
451                             }
452                         } else {
453                             removeCSSClass(bg,cn);
454                             removeCSSClass(bg,cn2);
455                             ind.hidden = true;
456                             ind2.hidden = true;
457                         }
458                         document.getElementById('checkin_barcode_entry_textbox').focus();
459                         return true;
460                     } ],
461                     'cmd_checkin_local_hold_as_transit' : [ ['command'], function(ev) {
462                         dump('in cmd_checkin_local_hold_as_transit\n');
463                         var bg = document.getElementById('background');
464                         var cb = document.getElementById('checkin_local_hold_as_transit');
465                         var ind = document.getElementById('checkin_local_hold_as_transit_indicator');
466                         var cn = 'checkin_screen_checkin_local_hold_as_transit';
467                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
468                         ind.hidden = cb.getAttribute('checked') != 'true'; 
469                         document.getElementById('checkin_barcode_entry_textbox').focus();
470                         return true;
471
472                     } ],
473                     'cmd_checkin_manual_float' : [ ['command'], function(ev) {
474                         dump('in cmd_checkin_manual_float\n');
475                         var bg = document.getElementById('background');
476                         var cb = document.getElementById('checkin_manual_float');
477                         var ind = document.getElementById('checkin_manual_float_indicator');
478                         var cn = 'checkin_screen_checkin_manual_float';
479                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
480                         ind.hidden = cb.getAttribute('checked') != 'true'; 
481                         document.getElementById('checkin_barcode_entry_textbox').focus();
482                         return true;
483
484                     } ]
485                 }
486             }
487         );
488         this.controller.render();
489         this.controller.view.checkin_barcode_entry_textbox.focus();
490
491     },
492
493     'update_no_change_label' : function (node,row) {
494         var obj = this;
495         var no_change_label = document.getElementById('no_change_label');
496         var incumbent_row = no_change_label.getAttribute('unique_row_counter');
497         var incoming_row = node.getAttribute('unique_row_counter');
498         if (!incumbent_row) { incumbent_row = incoming_row; }
499         if (row.my.mbts && ( no_change_label || document.getElementById('fine_tally') ) ) {
500             var bill = row.my.mbts;
501             if (Number(bill.balance_owed()) == 0) { return; }
502             if (no_change_label) {
503                 var msg = incumbent_row != incoming_row
504                     ? '' // clear out label if for a different transaction
505                     : no_change_label.getAttribute('value');
506                 var new_msg = document.getElementById('circStrings').getFormattedString(
507                     'staff.circ.utils.billable.amount', [
508                         row.my.acp.barcode(),
509                         util.money.sanitize(bill.balance_owed())
510                     ]
511                 );
512                 no_change_label.setAttribute(
513                     'value', 
514                     msg.indexOf(new_msg) > -1 ? msg : msg + new_msg + '  '
515                 );
516                 no_change_label.setAttribute('hidden','false');
517                 no_change_label.setAttribute('onclick','xulG.new_patron_tab({},{"id" : '+bill.usr()+', "show" : "bills" })');
518                 no_change_label.setAttribute('unique_row_counter',incoming_row);
519                 addCSSClass(no_change_label,'click_link'); 
520                 node.setAttribute('no_change_label_label', no_change_label.getAttribute('value'));
521                 node.setAttribute('no_change_label_click', no_change_label.getAttribute('onclick'));
522             }
523         }
524     },
525
526     'gen_list_retrieve_row_func' : function() {
527         var obj = this;
528         return function(params) {
529             try {
530                 var row = params.row;
531                 if (typeof params.on_retrieve == 'function') params.on_retrieve(row);
532                 obj.update_no_change_label(params.treeitem_node,row);
533                 var bill = row.my.mbts;
534                 if (bill && document.getElementById('fine_tally') && ! row.already_tallied) {
535                     params.row.already_tallied = true;
536                     var amount = util.money.cents_as_dollars(
537                         Number( util.money.dollars_float_to_cents_integer( document.getElementById('fine_tally').getAttribute('amount') ) ) 
538                         + Number( util.money.dollars_float_to_cents_integer( bill.balance_owed() ) )
539                     );
540                     document.getElementById('fine_tally').setAttribute('amount',amount);
541                     document.getElementById('fine_tally').setAttribute(
542                         'value',
543                         document.getElementById('circStrings').getFormattedString('staff.circ.utils.fine_tally_text', [ util.money.sanitize( amount ) ])
544                     );
545                     document.getElementById('fine_tally').setAttribute('hidden','false');
546                 }
547             } catch(E) {
548                 alert('Error in checkin.js, list_retrieve_row(): ' + E);
549             }
550             return row;
551         };
552     },
553
554     'test_barcode' : function(bc) {
555         var obj = this;
556         var x = document.getElementById('strict_barcode');
557         if (x && x.checked != true) return true;
558         var good = util.barcode.check(bc);
559         if (good) {
560             return true;
561         } else {
562             if ( 1 == obj.error.yns_alert(
563                         document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
564                         document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
565                         document.getElementById('circStrings').getString('staff.circ.cancel'),
566                         document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
567                         null,
568                         document.getElementById('circStrings').getString('staff.circ.confirm'),
569                         '/xul/server/skin/media/images/bad_barcode.png'
570             ) ) {
571                 return true;
572             } else {
573                 return false;
574             }
575         }
576     },
577
578     'checkin' : function() {
579         var obj = this;
580         try {
581             var textbox = obj.controller.view.checkin_barcode_entry_textbox;
582             var async = false;
583             var async_checkbox = document.getElementById('async_checkin');
584             if (async_checkbox) { async = async_checkbox.getAttribute('checked') == 'true'; }
585             var barcode = textbox.value;
586             if (async) {
587                 textbox.value = ''; textbox.focus();
588             }
589             if (obj.data.list.cbc.length > 0) { // skip barcode completion lookups if none configured
590                 // Auto-complete the barcode, items only
591                 var barcode_object = xulG.get_barcode(window, 'asset', barcode);
592                 // user_false means the user selected "None of the above", abort before other prompts/errors
593                 if(barcode_object == "user_false") return;
594                 // Got a barcode without an error? Use it. Otherwise fall through.
595                 if(barcode_object && typeof barcode_object.ilsevent == 'undefined')
596                     barcode = barcode_object.barcode;
597             }
598             if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
599             var placeholder_item = new acp();
600             placeholder_item.barcode( barcode );
601             var row_params = obj.list.append( { 
602                     'row' : {
603                         'my' : { 
604                             'acp' : placeholder_item
605                         } 
606                     },
607                     'to_top' : true,
608                     'flesh_immediately' : !async,
609                     'on_append' : function(rparams) { obj.row_map[ rparams.unique_row_counter ] = rparams; },
610                     'on_remove' : function(unique_row_counter) { delete obj.row_map[ unique_row_counter ]; }
611             } );
612             
613             var backdate = obj.controller.view.checkin_effective_datepicker.value;
614             var auto_print = document.getElementById('checkin_auto_print_slips');
615             if (auto_print) auto_print = auto_print.getAttribute('checked') == 'true';
616             JSAN.use('circ.util');
617             var params = { 
618                 'barcode' : barcode,
619                 'disable_textbox' : function() { 
620                     if (!async) {
621                         textbox.blur();
622                         textbox.disabled = true; 
623                         textbox.setAttribute('disabled', 'true'); 
624                     }
625                 },
626                 'enable_textbox' : function() { 
627                     textbox.disabled = false; 
628                     textbox.setAttribute('disabled', 'false'); 
629                     textbox.focus();
630                 },
631                 'checkin_result' : function(checkin) {
632                     textbox.disabled = false;
633                     textbox.focus();
634                     //obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false'); 
635                     obj.checkin2(checkin,backdate,row_params);
636                 },
637                 'info_blurb' : function(text) {
638                     try { row_params.row.my.acp.alert_message( text ); } catch(E) {dump('error: ' + E + '\n');}
639                 }
640             }; 
641             var suppress_holds_and_transits = document.getElementById('suppress_holds_and_transits');
642             if (suppress_holds_and_transits) suppress_holds_and_transits = suppress_holds_and_transits.getAttribute('checked') == 'true';
643             if (suppress_holds_and_transits) params.noop = 1;
644             var amnesty_mode = document.getElementById('amnesty_mode');
645             if (amnesty_mode) amnesty_mode = amnesty_mode.getAttribute('checked') == 'true';
646             if (amnesty_mode) params.void_overdues = 1;
647             var clear_shelf_expired_holds = document.getElementById('checkin_clear_shelf_expired');
648             if (clear_shelf_expired_holds) clear_shelf_expired_holds = clear_shelf_expired_holds.getAttribute('checked') == 'true';
649             if (clear_shelf_expired_holds) params.clear_expired = 1;
650             var auto_retarget = document.getElementById('checkin_auto_retarget');
651             if (auto_retarget) auto_retarget = auto_retarget.getAttribute('checked') == 'true';
652             if (auto_retarget) {
653                 var retarget_all = document.getElementById('checkin_auto_retarget_all');
654                 if (retarget_all) retarget_all = retarget_all.getAttribute('checked') == 'true';
655                 if (retarget_all) params.retarget_mode = 'retarget.all';
656                 else params.retarget_mode = 'retarget';
657             }
658             var hold_as_transit = document.getElementById('checkin_local_hold_as_transit');
659             if (hold_as_transit) hold_as_transit = hold_as_transit.getAttribute('checked') == 'true';
660             if (hold_as_transit) params.hold_as_transit = 1;
661             var manual_float = document.getElementById('checkin_manual_float');
662             if (manual_float) manual_float = manual_float.getAttribute('checked') == 'true';
663             if (manual_float) params.manual_float = 1;
664             circ.util.checkin_via_barcode(
665                 ses(), 
666                 params,
667                 backdate, 
668                 auto_print,
669                 async
670             );
671         } catch(E) {
672             obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.exception', [E]), E);
673             if (typeof obj.on_failure == 'function') {
674                 obj.on_failure(E);
675             }
676             if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
677                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.external') + '\n');
678                 window.xulG.on_failure(E);
679             } else {
680                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.no_external') + '\n');
681             }
682         }
683
684     },
685
686     'checkin2' : function(checkin,backdate,row_params) {
687         var obj = this;
688         try {
689             if (!checkin) {/* circ.util.checkin used to be sole handler of errors and returns null currently */
690                 obj.list.refresh_row( row_params ); /* however, let's refresh the row because we're shoving error text into the dummy placeholder item's alert_message field  */
691                 return obj.on_failure();
692             }
693             if (checkin.ilsevent == 7010 /* COPY_ALERT_MESSAGE */
694                 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
695                 || checkin.ilsevent == -1 /* offline */
696                 || checkin.ilsevent == 1502 /* ASSET_COPY_NOT_FOUND */
697                 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
698                 || checkin.ilsevent == 7009 /* CIRC_CLAIMS_RETURNED */ 
699                 || checkin.ilsevent == 7011 /* COPY_STATUS_LOST */ 
700                 || checkin.ilsevent == 7025 /* COPY_STATUS_LONG_OVERDUE */ 
701                 || checkin.ilsevent == 7012 /* COPY_STATUS_MISSING */) {
702                 obj.list.refresh_row( row_params ); 
703                 return obj.on_failure();
704             }
705             var retrieve_id = js2JSON( { 'circ_id' : checkin.circ ? checkin.circ.id() : null , 'copy_id' : checkin.copy.id(), 'barcode' : checkin.copy.barcode(), 'doc_id' : (typeof checkin.record != 'undefined' ? ( typeof checkin.record.ilsevent == 'undefined' ? checkin.record.doc_id() : null ) : null ) } );
706             if (checkin.circ && checkin.circ.checkin_time() == 'now') checkin.circ.checkin_time(backdate);
707             if (document.getElementById('trim_list')) {
708                 var x = document.getElementById('trim_list');
709                 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
710             }
711             row_params['retrieve_id'] = retrieve_id;
712             row_params['row'] =  {
713                 'already_tallied' : false,
714                 'my' : {
715                     'circ' : checkin.circ,
716                     'mbts' : checkin.circ ? checkin.circ.billable_transaction().summary() : null,
717                     'mvr' : checkin.record,
718                     'acp' : checkin.copy,
719                     'acn' : checkin.volume,
720                     'au' : checkin.patron,
721                     'status' : checkin.status,
722                     'route_to' : checkin.route_to,
723                     'message' : checkin.message
724                 }
725             };
726             obj.list.refresh_row( row_params );
727             obj.list.node.view.selection.select(0);
728
729             JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
730
731             if (typeof obj.on_checkin == 'function') {
732                 obj.on_checkin(checkin);
733             }
734             if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
735                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.external') + '\n');
736                 window.xulG.on_checkin(checkin);
737             } else {
738                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.no_external') + '\n');
739             }
740
741             return true;
742
743         } catch(E) {
744             obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin2.exception', [E]));
745             if (typeof obj.on_failure == 'function') {
746                 obj.on_failure(E);
747             }
748             if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
749                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.external') + '\n');
750                 window.xulG.on_failure(E);
751             } else {
752                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.no_external') + '\n');
753             }
754         }
755
756     },
757
758     'on_checkin' : function() {
759         var async = false;
760         var async_checkbox = document.getElementById('async_checkin');
761         if (async_checkbox) { async = async_checkbox.getAttribute('checked') == 'true'; }
762         if (!async) {
763             this.controller.view.checkin_barcode_entry_textbox.disabled = false;
764             this.controller.view.checkin_barcode_entry_textbox.select();
765             this.controller.view.checkin_barcode_entry_textbox.value = '';
766             this.controller.view.checkin_barcode_entry_textbox.focus();
767         }
768     },
769
770     'on_failure' : function() {
771         var async = false;
772         var async_checkbox = document.getElementById('async_checkin');
773         if (async_checkbox) { async = async_checkbox.getAttribute('checked') == 'true'; }
774         if (!async) {
775             this.controller.view.checkin_barcode_entry_textbox.disabled = false;
776             this.controller.view.checkin_barcode_entry_textbox.select();
777             this.controller.view.checkin_barcode_entry_textbox.focus();
778         }
779     },
780     
781     'spawn_copy_editor' : function() {
782
783         var obj = this;
784
785         JSAN.use('util.functional');
786
787         var list = obj.selection_list;
788
789         list = util.functional.map_list(
790             list,
791             function (o) {
792                 return o.copy_id;
793             }
794         );
795
796         JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
797
798     }
799
800 }
801
802 dump('exiting circ.checkin.js\n');