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');
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' ],
39 JSAN.use('util.list'); obj.list = new util.list('checkin_list');
43 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
44 'on_select' : function(ev) {
46 JSAN.use('util.functional');
47 var sel = obj.list.retrieve_selection();
48 obj.selection_list = util.functional.map_list(
50 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
52 obj.error.sdump('D_TRACE', 'circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
53 if (obj.selection_list.length == 0) {
54 obj.controller.view.sel_edit.setAttribute('disabled','true');
55 obj.controller.view.sel_opac.setAttribute('disabled','true');
56 obj.controller.view.sel_patron.setAttribute('disabled','true');
57 obj.controller.view.sel_last_patron.setAttribute('disabled','true');
58 obj.controller.view.sel_copy_details.setAttribute('disabled','true');
59 obj.controller.view.sel_bucket.setAttribute('disabled','true');
60 obj.controller.view.sel_spine.setAttribute('disabled','true');
61 obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
62 obj.controller.view.sel_clip.setAttribute('disabled','true');
63 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
65 obj.controller.view.sel_edit.setAttribute('disabled','false');
66 obj.controller.view.sel_opac.setAttribute('disabled','false');
67 obj.controller.view.sel_patron.setAttribute('disabled','false');
68 obj.controller.view.sel_last_patron.setAttribute('disabled','false');
69 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
70 obj.controller.view.sel_bucket.setAttribute('disabled','false');
71 obj.controller.view.sel_spine.setAttribute('disabled','false');
72 obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
73 obj.controller.view.sel_clip.setAttribute('disabled','false');
74 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
84 JSAN.use('util.controller'); obj.controller = new util.controller();
88 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
91 function() { obj.list.clipboard(); }
97 obj.spawn_copy_editor();
106 JSAN.use('cat.util');
107 cat.util.spawn_spine_editor(obj.selection_list);
113 JSAN.use('cat.util');
114 cat.util.show_in_opac(obj.selection_list);
117 'sel_transit_abort' : [
120 JSAN.use('circ.util');
121 circ.util.abort_transits(obj.selection_list);
127 JSAN.use('circ.util');
128 circ.util.show_last_few_circs(obj.selection_list);
131 'sel_last_patron' : [
135 for (var i = 0; i < obj.selection_list.length; i++) {
136 var circs = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),obj.selection_list[i].copy_id,1]);
137 if (circs.length > 0) {
138 patrons[circs[0].usr()] = 1;
140 alert(document.getElementById('circStrings').getFormattedString('staff.circ.item_no_circs', [obj.selection_list[i].barcode]));
143 for (var i in patrons) {
144 xulG.new_tab(urls.XUL_PATRON_DISPLAY,{},{'id' : i});
148 'sel_copy_details' : [
151 JSAN.use('circ.util');
152 for (var i = 0; i < obj.selection_list.length; i++) {
153 circ.util.show_copy_details( obj.selection_list[i].copy_id );
157 'sel_mark_items_damaged' : [
161 JSAN.use('cat.util'); JSAN.use('util.functional');
162 cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
168 JSAN.use('cat.util');
169 cat.util.add_copies_to_bucket(obj.selection_list);
172 'checkin_barcode_entry_textbox' : [
175 if (ev.keyCode && ev.keyCode == 13) {
180 'checkin_effective_date_label' : [
184 obj.controller.view.checkin_effective_date_textbox.value =
185 util.date.formatted_date(new Date(),'%F');
189 'checkin_effective_date_textbox' : [
192 if (ev.target.nodeName == 'textbox') {
195 var darray = ev.target.value.split('-');
196 var year = darray[0]; var month = darray[1]; var day = darray[2];
197 if ( (!year) || (year.length != 4) || (!Number(year)) ) flag = true;
198 if ( (!month) || (month.length !=2) || (!Number(month)) ) flag = true;
199 if ( (!day) || (day.length !=2) || (!Number(day)) ) flag = true;
201 throw('invalid date format');
203 var d = new Date( year, month - 1, day );
204 if (d.toString() == 'Invalid Date') throw(document.getElementById('circStrings').getString('staff.circ.invalid_date'));
205 if ( d > new Date() ) throw(document.getElementById('circStrings').getString('staff.circ.future_date'));
206 ev.target.value = util.date.formatted_date(d,'%F');
207 var x = document.getElementById('background');
209 if ( ev.target.value == util.date.formatted_date(new Date(),'%F') ) {
210 x.setAttribute('style','background-color: green');
211 document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
213 x.setAttribute('style','background-color: red');
214 document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getFormattedString('staff.circ.backdated_checkin', [ev.target.value]));
219 dump('checkin:effective_date: ' + E + '\n');
220 alert(document.getElementById('circStrings').getFormattedString('staff.circ.backdate.exception', [E]));
221 ev.target.value = util.date.formatted_date(new Date(),'%F');
228 function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
230 'cmd_checkin_submit_barcode' : [
236 'cmd_checkin_print' : [
240 'template' : 'checkin'
245 'cmd_checkin_export' : [
248 obj.list.dump_csv_to_clipboard();
252 'cmd_checkin_reprint' : [
255 JSAN.use('util.print'); var print = new util.print();
256 print.reprint_last();
259 'cmd_checkin_done' : [
267 this.controller.render();
268 this.controller.view.checkin_barcode_entry_textbox.focus();
272 'test_barcode' : function(bc) {
274 var x = document.getElementById('strict_barcode');
275 if (x && x.checked != true) return true;
276 var good = util.barcode.check(bc);
280 if ( 1 == obj.error.yns_alert(
281 document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
282 document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
283 document.getElementById('circStrings').getString('staff.circ.cancel'),
284 document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
286 document.getElementById('circStrings').getString('staff.circ.confirm'),
287 '/xul/server/skin/media/images/bad_barcode.png'
296 'checkin' : function() {
299 var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
300 if (!barcode) return;
302 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
304 var backdate = obj.controller.view.checkin_effective_date_textbox.value;
305 var auto_print = document.getElementById('checkin_auto');
306 if (auto_print) auto_print = auto_print.checked;
307 JSAN.use('circ.util');
308 circ.util.checkin_via_barcode(
309 ses(), { 'barcode' : barcode }, backdate, auto_print, {
310 'disable_textbox' : function() {
311 obj.controller.view.checkin_barcode_entry_textbox.disabled = true;
312 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'true');
314 'enable_textbox' : function() {
315 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
316 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
318 'checkin_result' : function(checkin) {
319 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
320 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
321 obj.checkin2(checkin,backdate);
326 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.exception', [E]));
327 if (typeof obj.on_failure == 'function') {
330 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
331 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.external') + '\n');
332 window.xulG.on_failure(E);
334 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.no_external') + '\n');
340 'checkin2' : function(checkin,backdate) {
343 if (!checkin) return obj.on_failure(); /* circ.util.checkin handles errors and returns null currently */
344 if (checkin.ilsevent == 7010 /* COPY_ALERT_MESSAGE */
345 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
346 || checkin.ilsevent == -1 /* offline */
347 || checkin.ilsevent == 1502 /* ASSET_COPY_NOT_FOUND */
348 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
349 || checkin.ilsevent == 7009 /* CIRC_CLAIMS_RETURNED */
350 || checkin.ilsevent == 7011 /* COPY_STATUS_LOST */
351 || checkin.ilsevent == 7012 /* COPY_STATUS_MISSING */) return obj.on_failure();
352 var retrieve_id = js2JSON( { '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 ) } );
353 if (checkin.circ && checkin.circ.checkin_time() == 'now') checkin.circ.checkin_time(backdate);
354 if (document.getElementById('trim_list')) {
355 var x = document.getElementById('trim_list');
356 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
360 'retrieve_id' : retrieve_id,
363 'circ' : checkin.circ,
364 'mvr' : checkin.record,
365 'acp' : checkin.copy,
366 'status' : checkin.status,
367 'route_to' : checkin.route_to,
368 'message' : checkin.message,
372 //I could override map_row_to_column here
375 obj.list.node.view.selection.select(0);
377 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
379 if (typeof obj.on_checkin == 'function') {
380 obj.on_checkin(checkin);
382 if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
383 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.external') + '\n');
384 window.xulG.on_checkin(checkin);
386 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.no_external') + '\n');
392 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin2.exception', [E]));
393 if (typeof obj.on_failure == 'function') {
396 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
397 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.external') + '\n');
398 window.xulG.on_failure(E);
400 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.no_external') + '\n');
406 'on_checkin' : function() {
407 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
408 this.controller.view.checkin_barcode_entry_textbox.select();
409 this.controller.view.checkin_barcode_entry_textbox.value = '';
410 this.controller.view.checkin_barcode_entry_textbox.focus();
413 'on_failure' : function() {
414 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
415 this.controller.view.checkin_barcode_entry_textbox.select();
416 this.controller.view.checkin_barcode_entry_textbox.focus();
419 'spawn_copy_editor' : function() {
423 JSAN.use('util.functional');
425 var list = obj.selection_list;
427 list = util.functional.map_list(
434 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
440 dump('exiting circ.checkin.js\n');