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_backdate.setAttribute('disabled','true');
56 obj.controller.view.sel_opac.setAttribute('disabled','true');
57 obj.controller.view.sel_patron.setAttribute('disabled','true');
58 obj.controller.view.sel_last_patron.setAttribute('disabled','true');
59 obj.controller.view.sel_copy_details.setAttribute('disabled','true');
60 obj.controller.view.sel_bucket.setAttribute('disabled','true');
61 obj.controller.view.sel_spine.setAttribute('disabled','true');
62 obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
63 obj.controller.view.sel_clip.setAttribute('disabled','true');
64 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
66 obj.controller.view.sel_edit.setAttribute('disabled','false');
67 obj.controller.view.sel_backdate.setAttribute('disabled','false');
68 obj.controller.view.sel_opac.setAttribute('disabled','false');
69 obj.controller.view.sel_patron.setAttribute('disabled','false');
70 obj.controller.view.sel_last_patron.setAttribute('disabled','false');
71 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
72 obj.controller.view.sel_bucket.setAttribute('disabled','false');
73 obj.controller.view.sel_spine.setAttribute('disabled','false');
74 obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
75 obj.controller.view.sel_clip.setAttribute('disabled','false');
76 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
85 JSAN.use('util.controller'); obj.controller = new util.controller();
89 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
94 obj.controller.view.checkin_barcode_entry_textbox.focus();
101 obj.spawn_copy_editor();
110 JSAN.use('cat.util');
111 cat.util.spawn_spine_editor(obj.selection_list);
117 JSAN.use('cat.util');
118 cat.util.show_in_opac(obj.selection_list);
121 'sel_transit_abort' : [
124 JSAN.use('circ.util');
125 circ.util.abort_transits(obj.selection_list);
131 JSAN.use('circ.util');
132 circ.util.show_last_few_circs(obj.selection_list);
135 'sel_last_patron' : [
139 for (var i = 0; i < obj.selection_list.length; i++) {
140 var circs = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),obj.selection_list[i].copy_id,1]);
141 if (circs.length > 0) {
142 patrons[circs[0].usr()] = 1;
144 alert(document.getElementById('circStrings').getFormattedString('staff.circ.item_no_circs', [obj.selection_list[i].barcode]));
147 for (var i in patrons) {
148 xulG.new_patron_tab({},{'id' : i});
152 'sel_copy_details' : [
155 JSAN.use('circ.util');
156 for (var i = 0; i < obj.selection_list.length; i++) {
157 circ.util.show_copy_details( obj.selection_list[i].copy_id );
164 JSAN.use('circ.util');
165 for (var i = 0; i < obj.selection_list.length; i++) {
166 var circ_id = obj.selection_list[i].circ_id;
167 var copy_id = obj.selection_list[i].copy_id;
169 var blob = obj.network.simple_request('FM_ACP_DETAILS',[ses(),copy_id]);
170 if (blob.circ) circ_id = blob.circ.id();
172 if (!circ_id) continue;
173 circ.util.backdate_post_checkin( circ_id );
177 'sel_mark_items_damaged' : [
181 JSAN.use('cat.util'); JSAN.use('util.functional');
182 cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
188 JSAN.use('cat.util');
189 cat.util.add_copies_to_bucket(obj.selection_list);
192 'checkin_barcode_entry_textbox' : [
195 if (ev.keyCode && ev.keyCode == 13) {
200 'checkin_effective_date_label' : [
204 obj.controller.view.checkin_effective_datepicker.value =
205 util.date.formatted_date(new Date(),'%F');
209 'checkin_effective_datepicker' : [
212 if (ev.target.nodeName == 'datepicker') {
214 if ( ev.target.dateValue > new Date() ) throw(document.getElementById('circStrings').getString('staff.circ.future_date'));
215 var x = document.getElementById('background');
217 if ( ev.target.value == util.date.formatted_date(new Date(),'%F') ) {
218 x.setAttribute('style','background-color: green');
219 document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
221 x.setAttribute('style','background-color: red');
222 document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getFormattedString('staff.circ.backdated_checkin', [ev.target.value]));
227 var x = document.getElementById('background');
229 x.setAttribute('style','background-color: green');
230 document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
232 dump('checkin:effective_date: ' + E + '\n');
233 ev.target.disabled = true;
234 //alert(document.getElementById('circStrings').getFormattedString('staff.circ.backdate.exception', [E]));
235 ev.target.value = util.date.formatted_date(new Date(),'%F');
236 ev.target.disabled = false;
237 JSAN.use('util.sound'); var sound = new util.sound(); sound.bad();
245 function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
247 'cmd_checkin_submit_barcode' : [
253 'cmd_checkin_print' : [
257 'template' : 'checkin'
262 'cmd_csv_to_clipboard' : [ ['command'], function() {
263 obj.list.dump_csv_to_clipboard();
264 obj.controller.view.checkin_barcode_entry_textbox.focus();
266 'cmd_csv_to_printer' : [ ['command'], function() {
267 obj.list.dump_csv_to_printer();
268 obj.controller.view.checkin_barcode_entry_textbox.focus();
270 'cmd_csv_to_file' : [ ['command'], function() {
271 obj.list.dump_csv_to_file( { 'defaultFileName' : 'checked_in.txt' } );
272 obj.controller.view.checkin_barcode_entry_textbox.focus();
277 this.controller.render();
278 this.controller.view.checkin_barcode_entry_textbox.focus();
282 'test_barcode' : function(bc) {
284 var x = document.getElementById('strict_barcode');
285 if (x && x.checked != true) return true;
286 var good = util.barcode.check(bc);
290 if ( 1 == obj.error.yns_alert(
291 document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
292 document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
293 document.getElementById('circStrings').getString('staff.circ.cancel'),
294 document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
296 document.getElementById('circStrings').getString('staff.circ.confirm'),
297 '/xul/server/skin/media/images/bad_barcode.png'
306 'checkin' : function() {
309 var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
310 if (!barcode) return;
312 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
314 var backdate = obj.controller.view.checkin_effective_datepicker.value;
315 var auto_print = document.getElementById('checkin_auto');
316 if (auto_print) auto_print = auto_print.getAttribute('checked') == 'true';
317 JSAN.use('circ.util');
318 circ.util.checkin_via_barcode(
322 'disable_textbox' : function() {
323 obj.controller.view.checkin_barcode_entry_textbox.disabled = true;
324 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'true');
326 'enable_textbox' : function() {
327 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
328 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
330 'checkin_result' : function(checkin) {
331 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
332 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
333 obj.checkin2(checkin,backdate);
340 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.exception', [E]));
341 if (typeof obj.on_failure == 'function') {
344 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
345 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.external') + '\n');
346 window.xulG.on_failure(E);
348 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.no_external') + '\n');
354 'checkin2' : function(checkin,backdate) {
357 if (!checkin) return obj.on_failure(); /* circ.util.checkin handles errors and returns null currently */
358 if (checkin.ilsevent == 7010 /* COPY_ALERT_MESSAGE */
359 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
360 || checkin.ilsevent == -1 /* offline */
361 || checkin.ilsevent == 1502 /* ASSET_COPY_NOT_FOUND */
362 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
363 || checkin.ilsevent == 7009 /* CIRC_CLAIMS_RETURNED */
364 || checkin.ilsevent == 7011 /* COPY_STATUS_LOST */
365 || checkin.ilsevent == 7012 /* COPY_STATUS_MISSING */) return obj.on_failure();
366 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 ) } );
367 if (checkin.circ && checkin.circ.checkin_time() == 'now') checkin.circ.checkin_time(backdate);
368 if (document.getElementById('trim_list')) {
369 var x = document.getElementById('trim_list');
370 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
374 'retrieve_id' : retrieve_id,
377 'circ' : checkin.circ,
378 'mvr' : checkin.record,
379 'acp' : checkin.copy,
380 'status' : checkin.status,
381 'route_to' : checkin.route_to,
382 'message' : checkin.message
386 //I could override map_row_to_column here
389 obj.list.node.view.selection.select(0);
391 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
393 if (typeof obj.on_checkin == 'function') {
394 obj.on_checkin(checkin);
396 if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
397 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.external') + '\n');
398 window.xulG.on_checkin(checkin);
400 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.no_external') + '\n');
406 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin2.exception', [E]));
407 if (typeof obj.on_failure == 'function') {
410 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
411 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.external') + '\n');
412 window.xulG.on_failure(E);
414 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.no_external') + '\n');
420 'on_checkin' : function() {
421 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
422 this.controller.view.checkin_barcode_entry_textbox.select();
423 this.controller.view.checkin_barcode_entry_textbox.value = '';
424 this.controller.view.checkin_barcode_entry_textbox.focus();
427 'on_failure' : function() {
428 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
429 this.controller.view.checkin_barcode_entry_textbox.select();
430 this.controller.view.checkin_barcode_entry_textbox.focus();
433 'spawn_copy_editor' : function() {
437 JSAN.use('util.functional');
439 var list = obj.selection_list;
441 list = util.functional.map_list(
448 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
454 dump('exiting circ.checkin.js\n');