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();
8 var js = JSAN._loadJSFromUrl( urls.isodate_lib );
9 try { eval( js ); } catch(E) { this.error.standard_unexpected_error_alert('Problem loading ISO8601 date extension',E); }
11 JSAN.use('util.network'); this.network = new util.network();
12 JSAN.use('util.barcode');
13 JSAN.use('util.date');
14 this.OpenILS = {}; JSAN.use('OpenILS.data'); this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
15 this.data = this.OpenILS.data;
18 circ.checkin.prototype = {
20 'selection_list' : [],
22 'init' : function( params ) {
26 JSAN.use('circ.util');
27 var columns = circ.util.columns(
29 'barcode' : { 'hidden' : false },
30 'title' : { 'hidden' : false },
31 'location' : { 'hidden' : false },
32 'call_number' : { 'hidden' : false },
33 'status' : { 'hidden' : false },
34 'route_to' : { 'hidden' : false },
35 'alert_message' : { 'hidden' : false },
36 'checkin_time' : { 'hidden' : false },
39 'except_these' : [ 'uses', 'checkin_time_full' ],
43 JSAN.use('util.list'); obj.list = new util.list('checkin_list');
47 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
48 'on_select' : function(ev) {
50 JSAN.use('util.functional');
51 var sel = obj.list.retrieve_selection();
52 obj.selection_list = util.functional.map_list(
54 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
56 obj.error.sdump('D_TRACE', 'circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
57 if (obj.selection_list.length == 0) {
58 obj.controller.view.sel_edit.setAttribute('disabled','true');
59 obj.controller.view.sel_opac.setAttribute('disabled','true');
60 obj.controller.view.sel_patron.setAttribute('disabled','true');
61 obj.controller.view.sel_last_patron.setAttribute('disabled','true');
62 obj.controller.view.sel_copy_details.setAttribute('disabled','true');
63 obj.controller.view.sel_bucket.setAttribute('disabled','true');
64 obj.controller.view.sel_spine.setAttribute('disabled','true');
65 obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
66 obj.controller.view.sel_clip.setAttribute('disabled','true');
67 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
69 obj.controller.view.sel_edit.setAttribute('disabled','false');
70 obj.controller.view.sel_opac.setAttribute('disabled','false');
71 obj.controller.view.sel_patron.setAttribute('disabled','false');
72 obj.controller.view.sel_last_patron.setAttribute('disabled','false');
73 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
74 obj.controller.view.sel_bucket.setAttribute('disabled','false');
75 obj.controller.view.sel_spine.setAttribute('disabled','false');
76 obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
77 obj.controller.view.sel_clip.setAttribute('disabled','false');
78 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
88 JSAN.use('util.controller'); obj.controller = new util.controller();
92 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
95 function() { obj.list.clipboard(); }
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('Item ' + obj.selection_list[i].barcode + ' has never circulated');
147 for (var i in patrons) {
148 xulG.new_tab(urls.XUL_PATRON_DISPLAY,{},{'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 );
161 'sel_mark_items_damaged' : [
165 JSAN.use('cat.util'); JSAN.use('util.functional');
166 cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
172 JSAN.use('cat.util');
173 cat.util.add_copies_to_bucket(obj.selection_list);
176 'checkin_barcode_entry_textbox' : [
179 if (ev.keyCode && ev.keyCode == 13) {
184 'checkin_effective_date_label' : [
188 obj.controller.view.checkin_effective_date_textbox.value =
189 util.date.formatted_date(new Date(),'%F');
193 'checkin_effective_date_textbox' : [
196 if (ev.target.nodeName == 'textbox') {
199 var darray = ev.target.value.split('-');
200 var year = darray[0]; var month = darray[1]; var day = darray[2];
201 if ( (!year) || (year.length != 4) || (!Number(year)) ) flag = true;
202 if ( (!month) || (month.length !=2) || (!Number(month)) ) flag = true;
203 if ( (!day) || (day.length !=2) || (!Number(day)) ) flag = true;
205 throw('invalid date format');
207 var d = new Date( year, month - 1, day );
208 if (d.toString() == 'Invalid Date') throw('Invalid Date');
209 if ( d > new Date() ) throw('Future Date');
210 ev.target.value = util.date.formatted_date(d,'%F');
211 var x = document.getElementById('background');
213 if ( ev.target.value == util.date.formatted_date(new Date(),'%F') ) {
214 x.setAttribute('style','background-color: green');
215 document.getElementById('background-text').setAttribute('value','Check In / Process Item');
217 x.setAttribute('style','background-color: red');
218 document.getElementById('background-text').setAttribute('value','Backdated ' + ev.target.value + ' Check In');
223 dump('checkin:effective_date: ' + E + '\n');
224 alert('Problem setting backdate: ' + E);
225 ev.target.value = util.date.formatted_date(new Date(),'%F');
232 function() { alert('Not Yet Implemented'); }
234 'cmd_checkin_submit_barcode' : [
240 'cmd_checkin_print' : [
243 obj.list.on_all_fleshed = function() {
245 dump( js2JSON( obj.list.dump_with_keys() ) + '\n' );
246 obj.OpenILS.data.stash_retrieve();
247 var lib = obj.OpenILS.data.hash.aou[ obj.OpenILS.data.list.au[0].ws_ou() ];
251 'staff' : obj.OpenILS.data.list.au[0],
252 'header' : obj.OpenILS.data.print_list_templates.checkin.header,
253 'line_item' : obj.OpenILS.data.print_list_templates.checkin.line_item,
254 'footer' : obj.OpenILS.data.print_list_templates.checkin.footer,
255 'type' : obj.OpenILS.data.print_list_templates.checkin.type,
256 'list' : obj.list.dump_with_keys(),
258 JSAN.use('util.print'); var print = new util.print();
259 print.tree_list( p );
260 setTimeout(function(){obj.list.on_all_fleshed = null;},0);
265 obj.list.full_retrieve();
268 'cmd_checkin_export' : [
271 obj.list.on_all_fleshed = function() {
273 dump(obj.list.dump_csv() + '\n');
274 copy_to_clipboard(obj.list.dump_csv());
275 setTimeout(function(){obj.list.on_all_fleshed = null;},0);
280 obj.list.full_retrieve();
284 'cmd_checkin_reprint' : [
287 JSAN.use('util.print'); var print = new util.print();
288 print.reprint_last();
291 'cmd_checkin_done' : [
299 this.controller.render();
300 this.controller.view.checkin_barcode_entry_textbox.focus();
304 'test_barcode' : function(bc) {
306 var x = document.getElementById('strict_barcode');
307 if (x && x.checked != true) return true;
308 var good = util.barcode.check(bc);
312 if ( 1 == obj.error.yns_alert(
313 'Bad checkdigit; possible mis-scan. Use this barcode ("' + bc + '") anyway?',
318 'Check here to confirm this action',
319 '/xul/server/skin/media/images/bad_barcode.png'
328 'checkin' : function() {
331 var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
332 if (!barcode) return;
334 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
336 var backdate = obj.controller.view.checkin_effective_date_textbox.value;
337 var auto_print = document.getElementById('checkin_auto');
338 if (auto_print) auto_print = auto_print.checked;
339 JSAN.use('circ.util');
340 circ.util.checkin_via_barcode(
341 ses(), { 'barcode' : barcode }, backdate, auto_print, {
342 'disable_textbox' : function() {
343 obj.controller.view.checkin_barcode_entry_textbox.disabled = true;
344 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'true');
346 'enable_textbox' : function() {
347 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
348 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
350 'checkin_result' : function(checkin) {
351 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
352 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
353 obj.checkin2(checkin,backdate);
358 obj.error.standard_unexpected_error_alert('Something went wrong in circ.util.checkin: ',E);
359 if (typeof obj.on_failure == 'function') {
362 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
363 obj.error.sdump('D_CIRC','circ.util.checkin: Calling external .on_failure()\n');
364 window.xulG.on_failure(E);
366 obj.error.sdump('D_CIRC','circ.util.checkin: No external .on_failure()\n');
372 'checkin2' : function(checkin,backdate) {
375 if (!checkin) return obj.on_failure(); /* circ.util.checkin handles errors and returns null currently */
376 if (checkin.ilsevent == 7010 /* COPY_ALERT_MESSAGE */
377 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
378 || checkin.ilsevent == -1 /* offline */
379 || checkin.ilsevent == 1502 /* ASSET_COPY_NOT_FOUND */
380 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
381 || checkin.ilsevent == 7009 /* CIRC_CLAIMS_RETURNED */
382 || checkin.ilsevent == 7011 /* COPY_STATUS_LOST */
383 || checkin.ilsevent == 7012 /* COPY_STATUS_MISSING */) return obj.on_failure();
384 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 ) } );
385 if (checkin.circ && checkin.circ.checkin_time() == 'now') checkin.circ.checkin_time(backdate);
386 if (document.getElementById('trim_list')) {
387 var x = document.getElementById('trim_list');
388 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
392 'retrieve_id' : retrieve_id,
395 'circ' : checkin.circ,
396 'mvr' : checkin.record,
397 'acp' : checkin.copy,
398 'status' : checkin.status,
399 'route_to' : checkin.route_to,
400 'message' : checkin.message,
404 //I could override map_row_to_column here
407 obj.list.node.view.selection.select(0);
409 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
411 if (typeof obj.on_checkin == 'function') {
412 obj.on_checkin(checkin);
414 if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
415 obj.error.sdump('D_CIRC','circ.checkin: Calling external .on_checkin()\n');
416 window.xulG.on_checkin(checkin);
418 obj.error.sdump('D_CIRC','circ.checkin: No external .on_checkin()\n');
424 obj.error.standard_unexpected_error_alert('Something went wrong in circ.util.checkin2: ',E);
425 if (typeof obj.on_failure == 'function') {
428 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
429 obj.error.sdump('D_CIRC','circ.util.checkin2: Calling external .on_failure()\n');
430 window.xulG.on_failure(E);
432 obj.error.sdump('D_CIRC','circ.util.checkin2: No external .on_failure()\n');
438 'on_checkin' : function() {
439 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
440 this.controller.view.checkin_barcode_entry_textbox.select();
441 this.controller.view.checkin_barcode_entry_textbox.value = '';
442 this.controller.view.checkin_barcode_entry_textbox.focus();
445 'on_failure' : function() {
446 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
447 this.controller.view.checkin_barcode_entry_textbox.select();
448 this.controller.view.checkin_barcode_entry_textbox.focus();
451 'spawn_copy_editor' : function() {
453 /* FIXME - a lot of redundant calls here */
457 JSAN.use('util.widgets'); JSAN.use('util.functional');
459 var list = obj.selection_list;
461 list = util.functional.map_list(
468 var copies = util.functional.map_list(
471 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
477 edit = obj.network.request(
478 api.PERM_MULTI_ORG_CHECK.app,
479 api.PERM_MULTI_ORG_CHECK.method,
482 obj.data.list.au[0].id(),
483 util.functional.map_list(
486 return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
489 copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
491 ).length == 0 ? 1 : 0;
493 obj.error.sdump('D_ERROR','batch permission check: ' + E);
496 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
502 dump('exiting circ.checkin.js\n');