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_copy_details.setAttribute('disabled','true');
58 obj.controller.view.sel_bucket.setAttribute('disabled','true');
59 obj.controller.view.sel_spine.setAttribute('disabled','true');
60 obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
61 obj.controller.view.sel_clip.setAttribute('disabled','true');
62 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
64 obj.controller.view.sel_edit.setAttribute('disabled','false');
65 obj.controller.view.sel_opac.setAttribute('disabled','false');
66 obj.controller.view.sel_patron.setAttribute('disabled','false');
67 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
68 obj.controller.view.sel_bucket.setAttribute('disabled','false');
69 obj.controller.view.sel_spine.setAttribute('disabled','false');
70 obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
71 obj.controller.view.sel_clip.setAttribute('disabled','false');
72 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
82 JSAN.use('util.controller'); obj.controller = new util.controller();
86 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
89 function() { obj.list.clipboard(); }
95 obj.spawn_copy_editor();
104 JSAN.use('cat.util');
105 cat.util.spawn_spine_editor(obj.selection_list);
111 JSAN.use('cat.util');
112 cat.util.show_in_opac(obj.selection_list);
115 'sel_transit_abort' : [
118 JSAN.use('circ.util');
119 circ.util.abort_transits(obj.selection_list);
125 JSAN.use('circ.util');
126 circ.util.show_last_few_circs(obj.selection_list);
129 'sel_copy_details' : [
132 JSAN.use('circ.util');
133 for (var i = 0; i < obj.selection_list.length; i++) {
134 circ.util.show_copy_details( obj.selection_list[i].copy_id );
138 'sel_mark_items_damaged' : [
142 JSAN.use('cat.util'); JSAN.use('util.functional');
143 cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
149 JSAN.use('cat.util');
150 cat.util.add_copies_to_bucket(obj.selection_list);
153 'checkin_barcode_entry_textbox' : [
156 if (ev.keyCode && ev.keyCode == 13) {
161 'checkin_effective_date_label' : [
165 obj.controller.view.checkin_effective_date_textbox.value =
166 util.date.formatted_date(new Date(),'%F');
170 'checkin_effective_date_textbox' : [
173 if (ev.target.nodeName == 'textbox') {
176 var darray = ev.target.value.split('-');
177 var year = darray[0]; var month = darray[1]; var day = darray[2];
178 if ( (!year) || (year.length != 4) || (!Number(year)) ) flag = true;
179 if ( (!month) || (month.length !=2) || (!Number(month)) ) flag = true;
180 if ( (!day) || (day.length !=2) || (!Number(day)) ) flag = true;
182 throw('invalid date format');
184 var d = new Date( year, month - 1, day );
185 if (d.toString() == 'Invalid Date') throw('Invalid Date');
186 if ( d > new Date() ) throw('Future Date');
187 ev.target.value = util.date.formatted_date(d,'%F');
188 var x = document.getElementById('background');
190 if ( ev.target.value == util.date.formatted_date(new Date(),'%F') ) {
191 x.setAttribute('style','background-color: green');
192 document.getElementById('background-text').setAttribute('value','Check In / Process Item');
194 x.setAttribute('style','background-color: red');
195 document.getElementById('background-text').setAttribute('value','Backdated ' + ev.target.value + ' Check In');
200 dump('checkin:effective_date: ' + E + '\n');
201 alert('Problem setting backdate: ' + E);
202 ev.target.value = util.date.formatted_date(new Date(),'%F');
209 function() { alert('Not Yet Implemented'); }
211 'cmd_checkin_submit_barcode' : [
217 'cmd_checkin_print' : [
220 obj.list.on_all_fleshed = function() {
222 dump( js2JSON( obj.list.dump_with_keys() ) + '\n' );
223 obj.OpenILS.data.stash_retrieve();
224 var lib = obj.OpenILS.data.hash.aou[ obj.OpenILS.data.list.au[0].ws_ou() ];
228 'staff' : obj.OpenILS.data.list.au[0],
229 'header' : obj.OpenILS.data.print_list_templates.checkin.header,
230 'line_item' : obj.OpenILS.data.print_list_templates.checkin.line_item,
231 'footer' : obj.OpenILS.data.print_list_templates.checkin.footer,
232 'type' : obj.OpenILS.data.print_list_templates.checkin.type,
233 'list' : obj.list.dump_with_keys(),
235 JSAN.use('util.print'); var print = new util.print();
236 print.tree_list( p );
237 setTimeout(function(){obj.list.on_all_fleshed = null;},0);
242 obj.list.full_retrieve();
245 'cmd_checkin_reprint' : [
248 JSAN.use('util.print'); var print = new util.print();
249 print.reprint_last();
252 'cmd_checkin_done' : [
260 this.controller.render();
261 this.controller.view.checkin_barcode_entry_textbox.focus();
265 'test_barcode' : function(bc) {
267 var good = util.barcode.check(bc);
271 if ( 1 == obj.error.yns_alert(
272 'Bad checkdigit; possible mis-scan. Use this barcode ("' + bc + '") anyway?',
277 'Check here to confirm this action',
278 '/xul/server/skin/media/images/bad_barcode.png'
287 'checkin' : function() {
290 var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
291 if (!barcode) return;
293 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
295 var backdate = obj.controller.view.checkin_effective_date_textbox.value;
296 var auto_print = document.getElementById('checkin_auto');
297 if (auto_print) auto_print = auto_print.checked;
298 JSAN.use('circ.util');
299 circ.util.checkin_via_barcode(
300 ses(), { 'barcode' : barcode }, backdate, auto_print, {
301 'disable_textbox' : function() {
302 obj.controller.view.checkin_barcode_entry_textbox.disabled = true;
303 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'true');
305 'enable_textbox' : function() {
306 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
307 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
309 'checkin_result' : function(checkin) {
310 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
311 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
312 obj.checkin2(checkin,backdate);
317 obj.error.standard_unexpected_error_alert('Something went wrong in circ.util.checkin: ',E);
318 if (typeof obj.on_failure == 'function') {
321 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
322 obj.error.sdump('D_CIRC','circ.util.checkin: Calling external .on_failure()\n');
323 window.xulG.on_failure(E);
325 obj.error.sdump('D_CIRC','circ.util.checkin: No external .on_failure()\n');
331 'checkin2' : function(checkin,backdate) {
334 if (!checkin) return obj.on_failure(); /* circ.util.checkin handles errors and returns null currently */
335 if (checkin.ilsevent == 7010 /* COPY_ALERT_MESSAGE */
336 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
337 || checkin.ilsevent == -1 /* offline */
338 || checkin.ilsevent == 1502 /* ASSET_COPY_NOT_FOUND */
339 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
340 || checkin.ilsevent == 7009 /* CIRC_CLAIMS_RETURNED */
341 || checkin.ilsevent == 7011 /* COPY_STATUS_LOST */
342 || checkin.ilsevent == 7012 /* COPY_STATUS_MISSING */) return obj.on_failure();
343 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 ) } );
344 if (checkin.circ && checkin.circ.checkin_time() == 'now') checkin.circ.checkin_time(backdate);
345 if (document.getElementById('trim_list')) {
346 var x = document.getElementById('trim_list');
347 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
351 'retrieve_id' : retrieve_id,
354 'circ' : checkin.circ,
355 'mvr' : checkin.record,
356 'acp' : checkin.copy,
357 'status' : checkin.status,
358 'route_to' : checkin.route_to,
359 'message' : checkin.message,
363 //I could override map_row_to_column here
367 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
369 if (typeof obj.on_checkin == 'function') {
370 obj.on_checkin(checkin);
372 if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
373 obj.error.sdump('D_CIRC','circ.checkin: Calling external .on_checkin()\n');
374 window.xulG.on_checkin(checkin);
376 obj.error.sdump('D_CIRC','circ.checkin: No external .on_checkin()\n');
382 obj.error.standard_unexpected_error_alert('Something went wrong in circ.util.checkin2: ',E);
383 if (typeof obj.on_failure == 'function') {
386 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
387 obj.error.sdump('D_CIRC','circ.util.checkin2: Calling external .on_failure()\n');
388 window.xulG.on_failure(E);
390 obj.error.sdump('D_CIRC','circ.util.checkin2: No external .on_failure()\n');
396 'on_checkin' : function() {
397 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
398 this.controller.view.checkin_barcode_entry_textbox.select();
399 this.controller.view.checkin_barcode_entry_textbox.value = '';
400 this.controller.view.checkin_barcode_entry_textbox.focus();
403 'on_failure' : function() {
404 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
405 this.controller.view.checkin_barcode_entry_textbox.select();
406 this.controller.view.checkin_barcode_entry_textbox.focus();
409 'spawn_copy_editor' : function() {
411 /* FIXME - a lot of redundant calls here */
415 JSAN.use('util.widgets'); JSAN.use('util.functional');
417 var list = obj.selection_list;
419 list = util.functional.map_list(
426 var copies = util.functional.map_list(
429 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
435 edit = obj.network.request(
436 api.PERM_MULTI_ORG_CHECK.app,
437 api.PERM_MULTI_ORG_CHECK.method,
440 obj.data.list.au[0].id(),
441 util.functional.map_list(
444 return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
447 copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
449 ).length == 0 ? 1 : 0;
451 obj.error.sdump('D_ERROR','batch permission check: ' + E);
454 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
460 dump('exiting circ.checkin.js\n');