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();
9 this.OpenILS = {}; JSAN.use('OpenILS.data'); this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
10 this.data = this.OpenILS.data;
13 circ.checkin.prototype = {
15 'selection_list' : [],
17 'init' : function( params ) {
21 JSAN.use('circ.util');
22 var columns = circ.util.columns(
24 'barcode' : { 'hidden' : false },
25 'title' : { 'hidden' : false },
26 'location' : { 'hidden' : false },
27 'call_number' : { 'hidden' : false },
28 'status' : { 'hidden' : false },
29 'route_to' : { 'hidden' : false },
30 'alert_message' : { 'hidden' : false },
31 'checkin_time' : { 'hidden' : false },
34 'except_these' : [ 'uses', 'checkin_time_full' ],
38 JSAN.use('util.list'); obj.list = new util.list('checkin_list');
42 'map_row_to_column' : circ.util.std_map_row_to_column(),
43 'on_select' : function(ev) {
45 JSAN.use('util.functional');
46 var sel = obj.list.retrieve_selection();
47 obj.selection_list = util.functional.map_list(
49 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
51 obj.error.sdump('D_TRACE', 'circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
52 if (obj.selection_list.length == 0) {
53 obj.controller.view.sel_edit.setAttribute('disabled','true');
54 obj.controller.view.sel_opac.setAttribute('disabled','true');
55 obj.controller.view.sel_patron.setAttribute('disabled','true');
56 obj.controller.view.sel_copy_details.setAttribute('disabled','true');
57 obj.controller.view.sel_bucket.setAttribute('disabled','true');
58 obj.controller.view.sel_spine.setAttribute('disabled','true');
59 obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
60 obj.controller.view.sel_clip.setAttribute('disabled','true');
62 obj.controller.view.sel_edit.setAttribute('disabled','false');
63 obj.controller.view.sel_opac.setAttribute('disabled','false');
64 obj.controller.view.sel_patron.setAttribute('disabled','false');
65 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
66 obj.controller.view.sel_bucket.setAttribute('disabled','false');
67 obj.controller.view.sel_spine.setAttribute('disabled','false');
68 obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
69 obj.controller.view.sel_clip.setAttribute('disabled','false');
79 JSAN.use('util.controller'); obj.controller = new util.controller();
83 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
86 function() { obj.list.clipboard(); }
92 obj.spawn_copy_editor();
101 JSAN.use('cat.util');
102 cat.util.spawn_spine_editor(obj.selection_list);
108 JSAN.use('cat.util');
109 cat.util.show_in_opac(obj.selection_list);
112 'sel_transit_abort' : [
115 JSAN.use('circ.util');
116 circ.util.abort_transits(obj.selection_list);
122 JSAN.use('circ.util');
123 circ.util.show_last_few_circs(obj.selection_list);
126 'sel_copy_details' : [
129 JSAN.use('circ.util');
130 for (var i = 0; i < obj.selection_list.length; i++) {
131 circ.util.show_copy_details( obj.selection_list[i].copy_id );
139 JSAN.use('cat.util');
140 cat.util.add_copies_to_bucket(obj.selection_list);
143 'checkin_barcode_entry_textbox' : [
146 if (ev.keyCode && ev.keyCode == 13) {
151 'checkin_effective_date_label' : [
155 obj.controller.view.checkin_effective_date_textbox.value =
156 util.date.formatted_date(new Date(),'%F');
160 'checkin_effective_date_textbox' : [
163 if (ev.target.nodeName == 'textbox') {
166 var darray = ev.target.value.split('-');
167 var year = darray[0]; var month = darray[1]; var day = darray[2];
168 if ( (!year) || (year.length != 4) || (!Number(year)) ) flag = true;
169 if ( (!month) || (month.length !=2) || (!Number(month)) ) flag = true;
170 if ( (!day) || (day.length !=2) || (!Number(day)) ) flag = true;
172 throw('invalid date format');
174 var d = new Date( year, month - 1, day );
175 if (d.toString() == 'Invalid Date') throw('Invalid Date');
176 if ( d > new Date() ) throw('Future Date');
177 ev.target.value = util.date.formatted_date(d,'%F');
178 var x = document.getElementById('background');
180 if ( ev.target.value == util.date.formatted_date(new Date(),'%F') ) {
181 x.setAttribute('style','background-color: green');
182 document.getElementById('background-text').setAttribute('value','Check In / Process Item');
184 x.setAttribute('style','background-color: red');
185 document.getElementById('background-text').setAttribute('value','Backdated ' + ev.target.value + ' Check In');
190 dump('checkin:effective_date: ' + E + '\n');
191 alert('Problem setting backdate: ' + E);
192 ev.target.value = util.date.formatted_date(new Date(),'%F');
199 function() { alert('Not Yet Implemented'); }
201 'cmd_checkin_submit_barcode' : [
207 'cmd_checkin_print' : [
210 obj.list.on_all_fleshed = function() {
212 dump( js2JSON( obj.list.dump_with_keys() ) + '\n' );
213 obj.OpenILS.data.stash_retrieve();
214 var lib = obj.OpenILS.data.hash.aou[ obj.OpenILS.data.list.au[0].ws_ou() ];
218 'staff' : obj.OpenILS.data.list.au[0],
219 'header' : obj.OpenILS.data.print_list_templates.checkin.header,
220 'line_item' : obj.OpenILS.data.print_list_templates.checkin.line_item,
221 'footer' : obj.OpenILS.data.print_list_templates.checkin.footer,
222 'type' : obj.OpenILS.data.print_list_templates.checkin.type,
223 'list' : obj.list.dump_with_keys(),
225 JSAN.use('util.print'); var print = new util.print();
226 print.tree_list( p );
227 setTimeout(function(){obj.list.on_all_fleshed = null;},0);
232 obj.list.full_retrieve();
235 'cmd_checkin_reprint' : [
238 JSAN.use('util.print'); var print = new util.print();
239 print.reprint_last();
242 'cmd_checkin_done' : [
250 this.controller.render();
251 this.controller.view.checkin_barcode_entry_textbox.focus();
255 'checkin' : function() {
258 var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
259 if (!barcode) return;
260 var backdate = obj.controller.view.checkin_effective_date_textbox.value;
261 var auto_print = document.getElementById('checkin_auto');
262 if (auto_print) auto_print = auto_print.checked;
263 JSAN.use('circ.util');
264 circ.util.checkin_via_barcode(
265 ses(), barcode, backdate, auto_print, {
266 'disable_textbox' : function() {
267 obj.controller.view.checkin_barcode_entry_textbox.disabled = true;
268 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'true');
270 'enable_textbox' : function() {
271 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
272 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
274 'checkin_result' : function(checkin) {
275 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
276 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
277 obj.checkin2(checkin,backdate);
282 obj.error.standard_unexpected_error_alert('Something went wrong in circ.util.checkin: ',E);
283 if (typeof obj.on_failure == 'function') {
286 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
287 obj.error.sdump('D_CIRC','circ.util.checkin: Calling external .on_failure()\n');
288 window.xulG.on_failure(E);
290 obj.error.sdump('D_CIRC','circ.util.checkin: No external .on_failure()\n');
296 'checkin2' : function(checkin,backdate) {
299 if (!checkin) return obj.on_failure(); /* circ.util.checkin handles errors and returns null currently */
300 if (checkin.ilsevent == 7010 /* COPY_ALERT_MESSAGE */
301 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
302 || checkin.ilsevent == -1 /* offline */
303 || checkin.ilsevent == 1502 /* ASSET_COPY_NOT_FOUND */
304 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
305 || checkin.ilsevent == 7009 /* CIRC_CLAIMS_RETURNED */
306 || checkin.ilsevent == 7011 /* COPY_STATUS_LOST */
307 || checkin.ilsevent == 7012 /* COPY_STATUS_MISSING */) return obj.on_failure();
308 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 ) } );
309 if (checkin.circ && checkin.circ.checkin_time() == 'now') checkin.circ.checkin_time(backdate);
312 'retrieve_id' : retrieve_id,
315 'circ' : checkin.circ,
316 'mvr' : checkin.record,
317 'acp' : checkin.copy,
318 'status' : checkin.status,
319 'route_to' : checkin.route_to,
320 'message' : checkin.message,
324 //I could override map_row_to_column here
328 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
330 if (typeof obj.on_checkin == 'function') {
331 obj.on_checkin(checkin);
333 if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
334 obj.error.sdump('D_CIRC','circ.checkin: Calling external .on_checkin()\n');
335 window.xulG.on_checkin(checkin);
337 obj.error.sdump('D_CIRC','circ.checkin: No external .on_checkin()\n');
343 obj.error.standard_unexpected_error_alert('Something went wrong in circ.util.checkin2: ',E);
344 if (typeof obj.on_failure == 'function') {
347 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
348 obj.error.sdump('D_CIRC','circ.util.checkin2: Calling external .on_failure()\n');
349 window.xulG.on_failure(E);
351 obj.error.sdump('D_CIRC','circ.util.checkin2: No external .on_failure()\n');
357 'on_checkin' : function() {
358 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
359 this.controller.view.checkin_barcode_entry_textbox.select();
360 this.controller.view.checkin_barcode_entry_textbox.value = '';
361 this.controller.view.checkin_barcode_entry_textbox.focus();
364 'on_failure' : function() {
365 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
366 this.controller.view.checkin_barcode_entry_textbox.select();
367 this.controller.view.checkin_barcode_entry_textbox.focus();
370 'spawn_copy_editor' : function() {
372 /* FIXME - a lot of redundant calls here */
376 JSAN.use('util.widgets'); JSAN.use('util.functional');
378 var list = obj.selection_list;
380 list = util.functional.map_list(
387 var copies = util.functional.map_list(
390 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
396 edit = obj.network.request(
397 api.PERM_MULTI_ORG_CHECK.app,
398 api.PERM_MULTI_ORG_CHECK.method,
401 obj.data.list.au[0].id(),
402 util.functional.map_list(
405 return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
408 copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
410 ).length == 0 ? 1 : 0;
412 obj.error.sdump('D_ERROR','batch permission check: ' + E);
415 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
421 dump('exiting circ.checkin.js\n');