1 dump('entering circ.checkin.js\n');
3 if (typeof circ == 'undefined') circ = {};
4 circ.checkin = function (params) {
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');
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;
14 circ.checkin.prototype = {
16 'selection_list' : [],
18 'init' : function( params ) {
22 JSAN.use('circ.util'); JSAN.use('patron.util');
23 var columns = circ.util.columns(
25 'barcode' : { 'hidden' : false },
26 'title' : { 'hidden' : false },
27 'location' : { 'hidden' : false },
28 'call_number' : { 'hidden' : false },
29 'status' : { 'hidden' : false },
30 'route_to' : { 'hidden' : false },
31 'alert_message' : { 'hidden' : false },
32 'checkin_time' : { 'hidden' : false }
35 'except_these' : [ 'uses', 'checkin_time_full' ]
38 patron.util.columns( { 'family_name' : { 'hidden' : 'false' } } )
41 patron.util.mbts_columns( {}, { 'except_these' : [ 'total_paid', 'total_owed', 'xact_start', 'xact_finish', 'xact_type' ] } )
43 ).sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
45 JSAN.use('util.list'); obj.list = new util.list('checkin_list');
49 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
50 'retrieve_row' : obj.gen_list_retrieve_row_func(),
51 'on_select' : function(ev) {
53 JSAN.use('util.functional');
54 var sel = obj.list.retrieve_selection();
55 obj.selection_list = util.functional.map_list(
57 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
59 obj.error.sdump('D_TRACE', 'circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
60 if (obj.selection_list.length == 0) {
61 obj.controller.view.sel_edit.setAttribute('disabled','true');
62 obj.controller.view.sel_backdate.setAttribute('disabled','true');
63 obj.controller.view.sel_opac.setAttribute('disabled','true');
64 obj.controller.view.sel_patron.setAttribute('disabled','true');
65 obj.controller.view.sel_last_patron.setAttribute('disabled','true');
66 obj.controller.view.sel_copy_details.setAttribute('disabled','true');
67 obj.controller.view.sel_bucket.setAttribute('disabled','true');
68 obj.controller.view.sel_spine.setAttribute('disabled','true');
69 obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
70 obj.controller.view.sel_clip.setAttribute('disabled','true');
71 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
73 obj.controller.view.sel_edit.setAttribute('disabled','false');
74 obj.controller.view.sel_backdate.setAttribute('disabled','false');
75 obj.controller.view.sel_opac.setAttribute('disabled','false');
76 obj.controller.view.sel_patron.setAttribute('disabled','false');
77 obj.controller.view.sel_last_patron.setAttribute('disabled','false');
78 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
79 obj.controller.view.sel_bucket.setAttribute('disabled','false');
80 obj.controller.view.sel_spine.setAttribute('disabled','false');
81 obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
82 obj.controller.view.sel_clip.setAttribute('disabled','false');
83 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
92 JSAN.use('util.controller'); obj.controller = new util.controller();
96 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
100 obj.list.clipboard();
101 obj.controller.view.checkin_barcode_entry_textbox.focus();
108 obj.spawn_copy_editor();
117 JSAN.use('cat.util');
118 cat.util.spawn_spine_editor(obj.selection_list);
124 JSAN.use('cat.util');
125 cat.util.show_in_opac(obj.selection_list);
128 'sel_transit_abort' : [
131 JSAN.use('circ.util');
132 circ.util.abort_transits(obj.selection_list);
138 JSAN.use('circ.util');
139 circ.util.show_last_few_circs(obj.selection_list);
142 'sel_last_patron' : [
146 for (var i = 0; i < obj.selection_list.length; i++) {
147 var circs = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),obj.selection_list[i].copy_id,1]);
148 if (circs.length > 0) {
149 patrons[circs[0].usr()] = 1;
151 alert(document.getElementById('circStrings').getFormattedString('staff.circ.item_no_circs', [obj.selection_list[i].barcode]));
154 for (var i in patrons) {
155 xulG.new_patron_tab({},{'id' : i});
159 'sel_copy_details' : [
162 JSAN.use('circ.util');
163 for (var i = 0; i < obj.selection_list.length; i++) {
164 circ.util.show_copy_details( obj.selection_list[i].copy_id );
171 JSAN.use('circ.util');
173 for (var i = 0; i < obj.selection_list.length; i++) {
174 var circ_id = obj.selection_list[i].circ_id;
175 var copy_id = obj.selection_list[i].copy_id;
177 var blob = obj.network.simple_request('FM_ACP_DETAILS',[ses(),copy_id]);
178 if (blob.circ) circ_id = blob.circ.id();
180 if (!circ_id) continue;
181 circ_ids.push( circ_id );
183 circ.util.backdate_post_checkin( circ_ids );
186 'sel_mark_items_damaged' : [
190 JSAN.use('cat.util'); JSAN.use('util.functional');
191 cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
197 JSAN.use('cat.util');
198 cat.util.add_copies_to_bucket(obj.selection_list);
201 'checkin_barcode_entry_textbox' : [
204 if (ev.keyCode && ev.keyCode == 13) {
209 'checkin_effective_date_label' : [
213 obj.controller.view.checkin_effective_datepicker.value =
214 util.date.formatted_date(new Date(),'%F');
218 'checkin_effective_datepicker' : [
221 if (ev.target.nodeName == 'datepicker') {
223 if ( ev.target.dateValue > new Date() ) throw(document.getElementById('circStrings').getString('staff.circ.future_date'));
224 var x = document.getElementById('background');
226 if ( ev.target.value == util.date.formatted_date(new Date(),'%F') ) {
227 //addCSSClass(x,'checkin_screen_normal');
228 removeCSSClass(x,'checkin_screen_backdating');
229 removeCSSClass(document.getElementById('background'),'checkin_screen_do_not_alert_on_precat');
230 removeCSSClass(document.getElementById('background'),'checkin_screen_suppress_holds_and_transits');
231 removeCSSClass(document.getElementById('background'),'checkin_screen_amnesty_mode');
232 removeCSSClass(document.getElementById('background'),'checkin_screen_checkin_auto_print_slips');
233 document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
235 addCSSClass(x,'checkin_screen_backdating');
236 //removeCSSClass(x,'checkin_screen_normal');
237 document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getFormattedString('staff.circ.backdated_checkin', [ev.target.value]));
241 var x = document.getElementById('background');
243 //addCSSClass(x,'checkin_screen_normal');
244 removeCSSClass(x,'checkin_screen_backdating');
245 removeCSSClass(document.getElementById('background'),'checkin_screen_do_not_alert_on_precat');
246 removeCSSClass(document.getElementById('background'),'checkin_screen_suppress_holds_and_transits');
247 removeCSSClass(document.getElementById('background'),'checkin_screen_amnesty_mode');
248 removeCSSClass(document.getElementById('background'),'checkin_screen_checkin_auto_print_slips');
249 document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
251 dump('checkin:effective_date: ' + E + '\n');
252 ev.target.disabled = true;
253 //alert(document.getElementById('circStrings').getFormattedString('staff.circ.backdate.exception', [E]));
254 ev.target.value = util.date.formatted_date(new Date(),'%F');
255 ev.target.disabled = false;
256 JSAN.use('util.sound'); var sound = new util.sound(); sound.bad();
264 function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
266 'cmd_checkin_submit_barcode' : [
272 'cmd_checkin_print' : [
276 'template' : 'checkin'
281 'cmd_csv_to_clipboard' : [ ['command'], function() {
282 obj.list.dump_csv_to_clipboard();
283 obj.controller.view.checkin_barcode_entry_textbox.focus();
285 'cmd_csv_to_printer' : [ ['command'], function() {
286 obj.list.dump_csv_to_printer();
287 obj.controller.view.checkin_barcode_entry_textbox.focus();
289 'cmd_csv_to_file' : [ ['command'], function() {
290 obj.list.dump_csv_to_file( { 'defaultFileName' : 'checked_in.txt' } );
291 obj.controller.view.checkin_barcode_entry_textbox.focus();
293 'cmd_do_not_alert_on_precat' : [ ['command'], function(ev) {
294 dump('in cmd_do_not_alert_on_precat\n');
295 var bg = document.getElementById('background');
296 var cb = document.getElementById('do_not_alert_on_precat');
297 var ind = document.getElementById('do_not_alert_on_precat_indicator');
298 var cn = 'checkin_screen_do_not_alert_on_precat';
299 if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
300 ind.hidden = cb.getAttribute('checked') != 'true';
301 document.getElementById('checkin_barcode_entry_textbox').focus();
304 'cmd_suppress_holds_and_transits' : [ ['command'], function(ev) {
305 dump('in cmd_suppress_holds_and_transits\n');
306 var bg = document.getElementById('background');
307 var cb = document.getElementById('suppress_holds_and_transits');
308 var ind = document.getElementById('suppress_holds_and_transits_indicator');
309 var cn = 'checkin_screen_suppress_holds_and_transits';
310 if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
311 ind.hidden = cb.getAttribute('checked') != 'true';
312 document.getElementById('checkin_barcode_entry_textbox').focus();
315 'cmd_amnesty_mode' : [ ['command'], function(ev) {
316 dump('in cmd_amnesty_mode\n');
317 var bg = document.getElementById('background');
318 var cb = document.getElementById('amnesty_mode');
319 var ind = document.getElementById('amnesty_mode_indicator');
320 var cn = 'checkin_screen_amnesty_mode';
321 if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
322 ind.hidden = cb.getAttribute('checked') != 'true';
323 document.getElementById('checkin_barcode_entry_textbox').focus();
326 'cmd_checkin_auto_print_slips' : [ ['command'], function(ev) {
327 dump('in cmd_checkin_auto_print_slips\n');
328 var bg = document.getElementById('background');
329 var cb = document.getElementById('checkin_auto_print_slips');
330 var ind = document.getElementById('checkin_auto_print_slips_indicator');
331 var cn = 'checkin_screen_checkin_auto_print_slips';
332 if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
333 ind.hidden = cb.getAttribute('checked') != 'true';
334 document.getElementById('checkin_barcode_entry_textbox').focus();
340 this.controller.render();
341 this.controller.view.checkin_barcode_entry_textbox.focus();
345 'gen_list_retrieve_row_func' : function() {
347 return function(params) {
349 var row = params.row;
350 if (typeof params.on_retrieve == 'function') params.on_retrieve(row);
352 if (row.my.mbts && ( document.getElementById('no_change_label') || document.getElementById('fine_tally') ) ) {
353 var bill = row.my.mbts;
354 if (Number(bill.balance_owed()) == 0) { return; }
355 if (document.getElementById('no_change_label')) {
356 var m = document.getElementById('no_change_label').getAttribute('value');
357 document.getElementById('no_change_label').setAttribute(
359 m + document.getElementById('circStrings').getFormattedString('staff.circ.utils.billable.amount', [row.my.acp.barcode(), util.money.sanitize(bill.balance_owed())]) + ' '
361 document.getElementById('no_change_label').setAttribute('hidden','false');
363 if (document.getElementById('fine_tally')) {
364 var amount = Number( document.getElementById('fine_tally').getAttribute('amount') ) + Number( bill.balance_owed() );
365 document.getElementById('fine_tally').setAttribute('amount',amount);
366 document.getElementById('fine_tally').setAttribute(
368 document.getElementById('circStrings').getFormattedString('staff.circ.utils.fine_tally_text', [ util.money.sanitize( amount ) ])
370 document.getElementById('fine_tally').setAttribute('hidden','false');
375 alert('Error in checkin.js, list_retrieve_row(): ' + E);
381 'test_barcode' : function(bc) {
383 var x = document.getElementById('strict_barcode');
384 if (x && x.checked != true) return true;
385 var good = util.barcode.check(bc);
389 if ( 1 == obj.error.yns_alert(
390 document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
391 document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
392 document.getElementById('circStrings').getString('staff.circ.cancel'),
393 document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
395 document.getElementById('circStrings').getString('staff.circ.confirm'),
396 '/xul/server/skin/media/images/bad_barcode.png'
405 'checkin' : function() {
408 var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
409 if (!barcode) return;
411 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
413 var backdate = obj.controller.view.checkin_effective_datepicker.value;
414 var auto_print = document.getElementById('checkin_auto_print_slips');
415 if (auto_print) auto_print = auto_print.getAttribute('checked') == 'true';
416 JSAN.use('circ.util');
419 'disable_textbox' : function() {
420 obj.controller.view.checkin_barcode_entry_textbox.disabled = true;
421 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'true');
423 'enable_textbox' : function() {
424 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
425 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
427 'checkin_result' : function(checkin) {
428 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
429 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
430 obj.checkin2(checkin,backdate);
433 var suppress_holds_and_transits = document.getElementById('suppress_holds_and_transits');
434 if (suppress_holds_and_transits) suppress_holds_and_transits = suppress_holds_and_transits.getAttribute('checked') == 'true';
435 if (suppress_holds_and_transits) params.noop = 1;
436 var amnesty_mode = document.getElementById('amnesty_mode');
437 if (amnesty_mode) amnesty_mode = amnesty_mode.getAttribute('checked') == 'true';
438 if (amnesty_mode) params.void_overdues = 1;
439 circ.util.checkin_via_barcode(
446 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.exception', [E]), E);
447 if (typeof obj.on_failure == 'function') {
450 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
451 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.external') + '\n');
452 window.xulG.on_failure(E);
454 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.no_external') + '\n');
460 'checkin2' : function(checkin,backdate) {
463 if (!checkin) return obj.on_failure(); /* circ.util.checkin handles errors and returns null currently */
464 if (checkin.ilsevent == 7010 /* COPY_ALERT_MESSAGE */
465 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
466 || checkin.ilsevent == -1 /* offline */
467 || checkin.ilsevent == 1502 /* ASSET_COPY_NOT_FOUND */
468 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
469 || checkin.ilsevent == 7009 /* CIRC_CLAIMS_RETURNED */
470 || checkin.ilsevent == 7011 /* COPY_STATUS_LOST */
471 || checkin.ilsevent == 7012 /* COPY_STATUS_MISSING */) return obj.on_failure();
472 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 ) } );
473 if (checkin.circ && checkin.circ.checkin_time() == 'now') checkin.circ.checkin_time(backdate);
474 if (document.getElementById('trim_list')) {
475 var x = document.getElementById('trim_list');
476 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
480 'retrieve_id' : retrieve_id,
483 'circ' : checkin.circ,
484 'mbts' : checkin.circ ? checkin.circ.billable_transaction().summary() : null,
485 'mvr' : checkin.record,
486 'acp' : checkin.copy,
487 'au' : checkin.patron,
488 'status' : checkin.status,
489 'route_to' : checkin.route_to,
490 'message' : checkin.message
496 obj.list.node.view.selection.select(0);
498 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
500 if (typeof obj.on_checkin == 'function') {
501 obj.on_checkin(checkin);
503 if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
504 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.external') + '\n');
505 window.xulG.on_checkin(checkin);
507 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.no_external') + '\n');
513 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin2.exception', [E]));
514 if (typeof obj.on_failure == 'function') {
517 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
518 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.external') + '\n');
519 window.xulG.on_failure(E);
521 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.no_external') + '\n');
527 'on_checkin' : function() {
528 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
529 this.controller.view.checkin_barcode_entry_textbox.select();
530 this.controller.view.checkin_barcode_entry_textbox.value = '';
531 this.controller.view.checkin_barcode_entry_textbox.focus();
534 'on_failure' : function() {
535 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
536 this.controller.view.checkin_barcode_entry_textbox.select();
537 this.controller.view.checkin_barcode_entry_textbox.focus();
540 'spawn_copy_editor' : function() {
544 JSAN.use('util.functional');
546 var list = obj.selection_list;
548 list = util.functional.map_list(
555 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
561 dump('exiting circ.checkin.js\n');