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');
172 for (var i = 0; i < obj.selection_list.length; i++) {
173 var circ_id = obj.selection_list[i].circ_id;
174 var copy_id = obj.selection_list[i].copy_id;
176 var blob = obj.network.simple_request('FM_ACP_DETAILS',[ses(),copy_id]);
177 if (blob.circ) circ_id = blob.circ.id();
179 if (!circ_id) continue;
180 circ.util.backdate_post_checkin( circ_id );
184 'sel_mark_items_damaged' : [
188 JSAN.use('cat.util'); JSAN.use('util.functional');
189 cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
195 JSAN.use('cat.util');
196 cat.util.add_copies_to_bucket(obj.selection_list);
199 'checkin_barcode_entry_textbox' : [
202 if (ev.keyCode && ev.keyCode == 13) {
207 'checkin_effective_date_label' : [
211 obj.controller.view.checkin_effective_datepicker.value =
212 util.date.formatted_date(new Date(),'%F');
216 'checkin_effective_datepicker' : [
219 if (ev.target.nodeName == 'datepicker') {
221 if ( ev.target.dateValue > new Date() ) throw(document.getElementById('circStrings').getString('staff.circ.future_date'));
222 var x = document.getElementById('background');
224 if ( ev.target.value == util.date.formatted_date(new Date(),'%F') ) {
225 //addCSSClass(x,'checkin_screen_normal');
226 removeCSSClass(x,'checkin_screen_backdating');
227 removeCSSClass(document.getElementById('background'),'checkin_screen_do_not_alert_on_precat');
228 removeCSSClass(document.getElementById('background'),'checkin_screen_suppress_holds_and_transits');
229 removeCSSClass(document.getElementById('background'),'checkin_screen_amnesty_mode');
230 removeCSSClass(document.getElementById('background'),'checkin_screen_checkin_auto_print_slips');
231 document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
233 addCSSClass(x,'checkin_screen_backdating');
234 //removeCSSClass(x,'checkin_screen_normal');
235 document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getFormattedString('staff.circ.backdated_checkin', [ev.target.value]));
239 var x = document.getElementById('background');
241 //addCSSClass(x,'checkin_screen_normal');
242 removeCSSClass(x,'checkin_screen_backdating');
243 removeCSSClass(document.getElementById('background'),'checkin_screen_do_not_alert_on_precat');
244 removeCSSClass(document.getElementById('background'),'checkin_screen_suppress_holds_and_transits');
245 removeCSSClass(document.getElementById('background'),'checkin_screen_amnesty_mode');
246 removeCSSClass(document.getElementById('background'),'checkin_screen_checkin_auto_print_slips');
247 document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
249 dump('checkin:effective_date: ' + E + '\n');
250 ev.target.disabled = true;
251 //alert(document.getElementById('circStrings').getFormattedString('staff.circ.backdate.exception', [E]));
252 ev.target.value = util.date.formatted_date(new Date(),'%F');
253 ev.target.disabled = false;
254 JSAN.use('util.sound'); var sound = new util.sound(); sound.bad();
262 function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
264 'cmd_checkin_submit_barcode' : [
270 'cmd_checkin_print' : [
274 'template' : 'checkin'
279 'cmd_csv_to_clipboard' : [ ['command'], function() {
280 obj.list.dump_csv_to_clipboard();
281 obj.controller.view.checkin_barcode_entry_textbox.focus();
283 'cmd_csv_to_printer' : [ ['command'], function() {
284 obj.list.dump_csv_to_printer();
285 obj.controller.view.checkin_barcode_entry_textbox.focus();
287 'cmd_csv_to_file' : [ ['command'], function() {
288 obj.list.dump_csv_to_file( { 'defaultFileName' : 'checked_in.txt' } );
289 obj.controller.view.checkin_barcode_entry_textbox.focus();
291 'cmd_do_not_alert_on_precat' : [ ['command'], function(ev) {
292 dump('in cmd_do_not_alert_on_precat\n');
293 var bg = document.getElementById('background');
294 var cb = document.getElementById('do_not_alert_on_precat');
295 var ind = document.getElementById('do_not_alert_on_precat_indicator');
296 var cn = 'checkin_screen_do_not_alert_on_precat';
297 if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
298 ind.hidden = cb.getAttribute('checked') != 'true';
299 document.getElementById('checkin_barcode_entry_textbox').focus();
302 'cmd_suppress_holds_and_transits' : [ ['command'], function(ev) {
303 dump('in cmd_suppress_holds_and_transits\n');
304 var bg = document.getElementById('background');
305 var cb = document.getElementById('suppress_holds_and_transits');
306 var ind = document.getElementById('suppress_holds_and_transits_indicator');
307 var cn = 'checkin_screen_suppress_holds_and_transits';
308 if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
309 ind.hidden = cb.getAttribute('checked') != 'true';
310 document.getElementById('checkin_barcode_entry_textbox').focus();
313 'cmd_amnesty_mode' : [ ['command'], function(ev) {
314 dump('in cmd_amnesty_mode\n');
315 var bg = document.getElementById('background');
316 var cb = document.getElementById('amnesty_mode');
317 var ind = document.getElementById('amnesty_mode_indicator');
318 var cn = 'checkin_screen_amnesty_mode';
319 if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
320 ind.hidden = cb.getAttribute('checked') != 'true';
321 document.getElementById('checkin_barcode_entry_textbox').focus();
324 'cmd_checkin_auto_print_slips' : [ ['command'], function(ev) {
325 dump('in cmd_checkin_auto_print_slips\n');
326 var bg = document.getElementById('background');
327 var cb = document.getElementById('checkin_auto_print_slips');
328 var ind = document.getElementById('checkin_auto_print_slips_indicator');
329 var cn = 'checkin_screen_checkin_auto_print_slips';
330 if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
331 ind.hidden = cb.getAttribute('checked') != 'true';
332 document.getElementById('checkin_barcode_entry_textbox').focus();
338 this.controller.render();
339 this.controller.view.checkin_barcode_entry_textbox.focus();
343 'gen_list_retrieve_row_func' : function() {
345 return function(params) {
347 var row = params.row;
348 if (typeof params.on_retrieve == 'function') params.on_retrieve(row);
350 if (row.my.mbts && ( document.getElementById('no_change_label') || document.getElementById('fine_tally') ) ) {
351 var bill = row.my.mbts;
352 if (Number(bill.balance_owed()) == 0) { return; }
353 if (document.getElementById('no_change_label')) {
354 var m = document.getElementById('no_change_label').getAttribute('value');
355 document.getElementById('no_change_label').setAttribute(
357 m + document.getElementById('circStrings').getFormattedString('staff.circ.utils.billable.amount', [row.my.acp.barcode(), util.money.sanitize(bill.balance_owed())]) + ' '
359 document.getElementById('no_change_label').setAttribute('hidden','false');
361 if (document.getElementById('fine_tally')) {
362 var amount = Number( document.getElementById('fine_tally').getAttribute('amount') ) + Number( bill.balance_owed() );
363 document.getElementById('fine_tally').setAttribute('amount',amount);
364 document.getElementById('fine_tally').setAttribute(
366 document.getElementById('circStrings').getFormattedString('staff.circ.utils.fine_tally_text', [ util.money.sanitize( amount ) ])
368 document.getElementById('fine_tally').setAttribute('hidden','false');
373 alert('Error in checkin.js, list_retrieve_row(): ' + E);
379 'test_barcode' : function(bc) {
381 var x = document.getElementById('strict_barcode');
382 if (x && x.checked != true) return true;
383 var good = util.barcode.check(bc);
387 if ( 1 == obj.error.yns_alert(
388 document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
389 document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
390 document.getElementById('circStrings').getString('staff.circ.cancel'),
391 document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
393 document.getElementById('circStrings').getString('staff.circ.confirm'),
394 '/xul/server/skin/media/images/bad_barcode.png'
403 'checkin' : function() {
406 var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
407 if (!barcode) return;
409 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
411 var backdate = obj.controller.view.checkin_effective_datepicker.value;
412 var auto_print = document.getElementById('checkin_auto_print_slips');
413 if (auto_print) auto_print = auto_print.getAttribute('checked') == 'true';
414 JSAN.use('circ.util');
417 'disable_textbox' : function() {
418 obj.controller.view.checkin_barcode_entry_textbox.disabled = true;
419 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'true');
421 'enable_textbox' : function() {
422 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
423 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
425 'checkin_result' : function(checkin) {
426 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
427 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
428 obj.checkin2(checkin,backdate);
431 var suppress_holds_and_transits = document.getElementById('suppress_holds_and_transits');
432 if (suppress_holds_and_transits) suppress_holds_and_transits = suppress_holds_and_transits.getAttribute('checked') == 'true';
433 if (suppress_holds_and_transits) params.noop = 1;
434 var amnesty_mode = document.getElementById('amnesty_mode');
435 if (amnesty_mode) amnesty_mode = amnesty_mode.getAttribute('checked') == 'true';
436 if (amnesty_mode) params.void_overdues = 1;
437 circ.util.checkin_via_barcode(
444 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.exception', [E]), E);
445 if (typeof obj.on_failure == 'function') {
448 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
449 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.external') + '\n');
450 window.xulG.on_failure(E);
452 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.no_external') + '\n');
458 'checkin2' : function(checkin,backdate) {
461 if (!checkin) return obj.on_failure(); /* circ.util.checkin handles errors and returns null currently */
462 if (checkin.ilsevent == 7010 /* COPY_ALERT_MESSAGE */
463 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
464 || checkin.ilsevent == -1 /* offline */
465 || checkin.ilsevent == 1502 /* ASSET_COPY_NOT_FOUND */
466 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
467 || checkin.ilsevent == 7009 /* CIRC_CLAIMS_RETURNED */
468 || checkin.ilsevent == 7011 /* COPY_STATUS_LOST */
469 || checkin.ilsevent == 7012 /* COPY_STATUS_MISSING */) return obj.on_failure();
470 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 ) } );
471 if (checkin.circ && checkin.circ.checkin_time() == 'now') checkin.circ.checkin_time(backdate);
472 if (document.getElementById('trim_list')) {
473 var x = document.getElementById('trim_list');
474 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
478 'retrieve_id' : retrieve_id,
481 'circ' : checkin.circ,
482 'mbts' : checkin.circ ? checkin.circ.billable_transaction().summary() : null,
483 'mvr' : checkin.record,
484 'acp' : checkin.copy,
485 'au' : checkin.patron,
486 'status' : checkin.status,
487 'route_to' : checkin.route_to,
488 'message' : checkin.message
494 obj.list.node.view.selection.select(0);
496 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
498 if (typeof obj.on_checkin == 'function') {
499 obj.on_checkin(checkin);
501 if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
502 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.external') + '\n');
503 window.xulG.on_checkin(checkin);
505 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.no_external') + '\n');
511 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin2.exception', [E]));
512 if (typeof obj.on_failure == 'function') {
515 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
516 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.external') + '\n');
517 window.xulG.on_failure(E);
519 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.no_external') + '\n');
525 'on_checkin' : function() {
526 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
527 this.controller.view.checkin_barcode_entry_textbox.select();
528 this.controller.view.checkin_barcode_entry_textbox.value = '';
529 this.controller.view.checkin_barcode_entry_textbox.focus();
532 'on_failure' : function() {
533 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
534 this.controller.view.checkin_barcode_entry_textbox.select();
535 this.controller.view.checkin_barcode_entry_textbox.focus();
538 'spawn_copy_editor' : function() {
542 JSAN.use('util.functional');
544 var list = obj.selection_list;
546 list = util.functional.map_list(
553 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
559 dump('exiting circ.checkin.js\n');