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_columns' : circ.util.std_map_row_to_columns(),
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');
61 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
63 obj.controller.view.sel_edit.setAttribute('disabled','false');
64 obj.controller.view.sel_opac.setAttribute('disabled','false');
65 obj.controller.view.sel_patron.setAttribute('disabled','false');
66 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
67 obj.controller.view.sel_bucket.setAttribute('disabled','false');
68 obj.controller.view.sel_spine.setAttribute('disabled','false');
69 obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
70 obj.controller.view.sel_clip.setAttribute('disabled','false');
71 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
81 JSAN.use('util.controller'); obj.controller = new util.controller();
85 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
88 function() { obj.list.clipboard(); }
94 obj.spawn_copy_editor();
103 JSAN.use('cat.util');
104 cat.util.spawn_spine_editor(obj.selection_list);
110 JSAN.use('cat.util');
111 cat.util.show_in_opac(obj.selection_list);
114 'sel_transit_abort' : [
117 JSAN.use('circ.util');
118 circ.util.abort_transits(obj.selection_list);
124 JSAN.use('circ.util');
125 circ.util.show_last_few_circs(obj.selection_list);
128 'sel_copy_details' : [
131 JSAN.use('circ.util');
132 for (var i = 0; i < obj.selection_list.length; i++) {
133 circ.util.show_copy_details( obj.selection_list[i].copy_id );
137 'sel_mark_items_damaged' : [
141 JSAN.use('cat.util'); JSAN.use('util.functional');
142 cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
148 JSAN.use('cat.util');
149 cat.util.add_copies_to_bucket(obj.selection_list);
152 'checkin_barcode_entry_textbox' : [
155 if (ev.keyCode && ev.keyCode == 13) {
160 'checkin_effective_date_label' : [
164 obj.controller.view.checkin_effective_date_textbox.value =
165 util.date.formatted_date(new Date(),'%F');
169 'checkin_effective_date_textbox' : [
172 if (ev.target.nodeName == 'textbox') {
175 var darray = ev.target.value.split('-');
176 var year = darray[0]; var month = darray[1]; var day = darray[2];
177 if ( (!year) || (year.length != 4) || (!Number(year)) ) flag = true;
178 if ( (!month) || (month.length !=2) || (!Number(month)) ) flag = true;
179 if ( (!day) || (day.length !=2) || (!Number(day)) ) flag = true;
181 throw('invalid date format');
183 var d = new Date( year, month - 1, day );
184 if (d.toString() == 'Invalid Date') throw('Invalid Date');
185 if ( d > new Date() ) throw('Future Date');
186 ev.target.value = util.date.formatted_date(d,'%F');
187 var x = document.getElementById('background');
189 if ( ev.target.value == util.date.formatted_date(new Date(),'%F') ) {
190 x.setAttribute('style','background-color: green');
191 document.getElementById('background-text').setAttribute('value','Check In / Process Item');
193 x.setAttribute('style','background-color: red');
194 document.getElementById('background-text').setAttribute('value','Backdated ' + ev.target.value + ' Check In');
199 dump('checkin:effective_date: ' + E + '\n');
200 alert('Problem setting backdate: ' + E);
201 ev.target.value = util.date.formatted_date(new Date(),'%F');
208 function() { alert('Not Yet Implemented'); }
210 'cmd_checkin_submit_barcode' : [
216 'cmd_checkin_print' : [
219 obj.list.on_all_fleshed = function() {
221 dump( js2JSON( obj.list.dump_with_keys() ) + '\n' );
222 obj.OpenILS.data.stash_retrieve();
223 var lib = obj.OpenILS.data.hash.aou[ obj.OpenILS.data.list.au[0].ws_ou() ];
227 'staff' : obj.OpenILS.data.list.au[0],
228 'header' : obj.OpenILS.data.print_list_templates.checkin.header,
229 'line_item' : obj.OpenILS.data.print_list_templates.checkin.line_item,
230 'footer' : obj.OpenILS.data.print_list_templates.checkin.footer,
231 'type' : obj.OpenILS.data.print_list_templates.checkin.type,
232 'list' : obj.list.dump_with_keys(),
234 JSAN.use('util.print'); var print = new util.print();
235 print.tree_list( p );
236 setTimeout(function(){obj.list.on_all_fleshed = null;},0);
241 obj.list.full_retrieve();
244 'cmd_checkin_reprint' : [
247 JSAN.use('util.print'); var print = new util.print();
248 print.reprint_last();
251 'cmd_checkin_done' : [
259 this.controller.render();
260 this.controller.view.checkin_barcode_entry_textbox.focus();
264 'checkin' : function() {
267 var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
268 if (!barcode) return;
269 var backdate = obj.controller.view.checkin_effective_date_textbox.value;
270 var auto_print = document.getElementById('checkin_auto');
271 if (auto_print) auto_print = auto_print.checked;
272 JSAN.use('circ.util');
273 circ.util.checkin_via_barcode(
274 ses(), barcode, backdate, auto_print, {
275 'disable_textbox' : function() {
276 obj.controller.view.checkin_barcode_entry_textbox.disabled = true;
277 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'true');
279 'enable_textbox' : function() {
280 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
281 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
283 'checkin_result' : function(checkin) {
284 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
285 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false');
286 obj.checkin2(checkin,backdate);
291 obj.error.standard_unexpected_error_alert('Something went wrong in circ.util.checkin: ',E);
292 if (typeof obj.on_failure == 'function') {
295 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
296 obj.error.sdump('D_CIRC','circ.util.checkin: Calling external .on_failure()\n');
297 window.xulG.on_failure(E);
299 obj.error.sdump('D_CIRC','circ.util.checkin: No external .on_failure()\n');
305 'checkin2' : function(checkin,backdate) {
308 if (!checkin) return obj.on_failure(); /* circ.util.checkin handles errors and returns null currently */
309 if (checkin.ilsevent == 7010 /* COPY_ALERT_MESSAGE */
310 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
311 || checkin.ilsevent == -1 /* offline */
312 || checkin.ilsevent == 1502 /* ASSET_COPY_NOT_FOUND */
313 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
314 || checkin.ilsevent == 7009 /* CIRC_CLAIMS_RETURNED */
315 || checkin.ilsevent == 7011 /* COPY_STATUS_LOST */
316 || checkin.ilsevent == 7012 /* COPY_STATUS_MISSING */) return obj.on_failure();
317 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 ) } );
318 if (checkin.circ && checkin.circ.checkin_time() == 'now') checkin.circ.checkin_time(backdate);
319 if (document.getElementById('trim_list')) {
320 var x = document.getElementById('trim_list');
321 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
325 'retrieve_id' : retrieve_id,
328 'circ' : checkin.circ,
329 'mvr' : checkin.record,
330 'acp' : checkin.copy,
331 'status' : checkin.status,
332 'route_to' : checkin.route_to,
333 'message' : checkin.message,
337 //I could override map_row_to_column here
341 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
343 if (typeof obj.on_checkin == 'function') {
344 obj.on_checkin(checkin);
346 if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
347 obj.error.sdump('D_CIRC','circ.checkin: Calling external .on_checkin()\n');
348 window.xulG.on_checkin(checkin);
350 obj.error.sdump('D_CIRC','circ.checkin: No external .on_checkin()\n');
356 obj.error.standard_unexpected_error_alert('Something went wrong in circ.util.checkin2: ',E);
357 if (typeof obj.on_failure == 'function') {
360 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
361 obj.error.sdump('D_CIRC','circ.util.checkin2: Calling external .on_failure()\n');
362 window.xulG.on_failure(E);
364 obj.error.sdump('D_CIRC','circ.util.checkin2: No external .on_failure()\n');
370 'on_checkin' : function() {
371 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
372 this.controller.view.checkin_barcode_entry_textbox.select();
373 this.controller.view.checkin_barcode_entry_textbox.value = '';
374 this.controller.view.checkin_barcode_entry_textbox.focus();
377 'on_failure' : function() {
378 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
379 this.controller.view.checkin_barcode_entry_textbox.select();
380 this.controller.view.checkin_barcode_entry_textbox.focus();
383 'spawn_copy_editor' : function() {
385 /* FIXME - a lot of redundant calls here */
389 JSAN.use('util.widgets'); JSAN.use('util.functional');
391 var list = obj.selection_list;
393 list = util.functional.map_list(
400 var copies = util.functional.map_list(
403 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
409 edit = obj.network.request(
410 api.PERM_MULTI_ORG_CHECK.app,
411 api.PERM_MULTI_ORG_CHECK.method,
414 obj.data.list.au[0].id(),
415 util.functional.map_list(
418 return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
421 copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
423 ).length == 0 ? 1 : 0;
425 obj.error.sdump('D_ERROR','batch permission check: ' + E);
428 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
434 dump('exiting circ.checkin.js\n');