1 dump('entering circ/util.js\n');
3 if (typeof circ == 'undefined') var circ = {};
6 circ.util.EXPORT_OK = [
7 'columns', 'hold_columns', 'CHECKIN_VIA_BARCODE', 'std_map_row_to_column', 'hold_capture_via_copy_barcode'
9 circ.util.EXPORT_TAGS = { ':all' : circ.util.EXPORT_OK };
11 circ.util.columns = function(modify) {
13 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
15 function getString(s) { return data.entities[s]; }
19 'id' : 'acp_id', 'label' : getString('staff.acp_label_id'), 'flex' : 1,
20 'primary' : false, 'hidden' : true, 'render' : 'my.acp.id()'
23 'id' : 'circ_id', 'label' : getString('staff.circ_label_id'), 'flex' : 1,
24 'primary' : false, 'hidden' : true, 'render' : 'my.circ.id()'
27 'id' : 'mvr_doc_id', 'label' : getString('staff.mvr_label_doc_id'), 'flex' : 1,
28 'primary' : false, 'hidden' : true, 'render' : 'my.mvr.doc_id()'
31 'id' : 'barcode', 'label' : getString('staff.acp_label_barcode'), 'flex' : 1,
32 'primary' : false, 'hidden' : true, 'render' : 'my.acp.barcode()'
35 'id' : 'call_number', 'label' : getString('staff.acp_label_call_number'), 'flex' : 1,
36 'primary' : false, 'hidden' : true, 'render' : 'obj.network.simple_request("FM_ACN_RETRIEVE",[ my.acp.call_number() ]).label()'
39 'id' : 'copy_number', 'label' : getString('staff.acp_label_copy_number'), 'flex' : 1,
40 'primary' : false, 'hidden' : true, 'render' : 'my.acp.copy_number()'
43 'id' : 'location', 'label' : getString('staff.acp_label_location'), 'flex' : 1,
44 'primary' : false, 'hidden' : true, 'render' : 'obj.data.hash.acpl[ my.acp.location() ].name()'
47 'id' : 'loan_duration', 'label' : getString('staff.acp_label_loan_duration'), 'flex' : 1,
48 'primary' : false, 'hidden' : true,
49 'render' : 'switch(my.acp.loan_duration()){ case 1: "Short"; break; case 2: "Normal"; break; case 3: "Long"; break; }'
52 'id' : 'circ_lib', 'label' : getString('staff.acp_label_circ_lib'), 'flex' : 1,
53 'primary' : false, 'hidden' : true, 'render' : 'obj.data.hash.aou[ my.acp.circ_lib() ].shortname()'
56 'id' : 'fine_level', 'label' : getString('staff.acp_label_fine_level'), 'flex' : 1,
57 'primary' : false, 'hidden' : true,
58 'render' : 'switch(my.acp.fine_level()){ case 1: "Low"; break; case 2: "Normal"; break; case 3: "High"; break; }'
61 'id' : 'deposit', 'label' : getString('staff.acp_label_deposit'), 'flex' : 1,
62 'primary' : false, 'hidden' : true, 'render' : 'my.acp.deposit()'
65 'id' : 'deposit_amount', 'label' : getString('staff.acp_label_deposit_amount'), 'flex' : 1,
66 'primary' : false, 'hidden' : true, 'render' : 'my.acp.deposit_amount()'
69 'id' : 'price', 'label' : getString('staff.acp_label_price'), 'flex' : 1,
70 'primary' : false, 'hidden' : true, 'render' : 'my.acp.price()'
73 'id' : 'circ_as_type', 'label' : getString('staff.acp_label_circ_as_type'), 'flex' : 1,
74 'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_as_type()'
77 'id' : 'circ_modifier', 'label' : getString('staff.acp_label_circ_modifier'), 'flex' : 1,
78 'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_modifier()'
81 'id' : 'xact_start', 'label' : getString('staff.circ_label_xact_start'), 'flex' : 1,
82 'primary' : false, 'hidden' : true, 'render' : 'my.circ.xact_start()'
85 'id' : 'xact_finish', 'label' : getString('staff.circ_label_xact_finish'), 'flex' : 1,
86 'primary' : false, 'hidden' : true, 'render' : 'my.circ.xact_finish()'
89 'id' : 'due_date', 'label' : getString('staff.circ_label_due_date'), 'flex' : 1,
90 'primary' : false, 'hidden' : true, 'render' : 'my.circ.due_date().substr(0,10)'
93 'id' : 'title', 'label' : getString('staff.mvr_label_title'), 'flex' : 2,
94 'primary' : false, 'hidden' : true, 'render' : 'try { my.mvr.title(); } catch(E) { my.acp.dummy_title(); }'
97 'id' : 'author', 'label' : getString('staff.mvr_label_author'), 'flex' : 1,
98 'primary' : false, 'hidden' : true, 'render' : 'try { my.mvr.author(); } catch(E) { my.acp.dummy_author(); }'
101 'id' : 'renewal_remaining', 'label' : getString('staff.circ_label_renewal_remaining'), 'flex' : 0,
102 'primary' : false, 'hidden' : true, 'render' : 'my.circ.renewal_remaining()'
105 'id' : 'status', 'label' : getString('staff.acp_label_status'), 'flex' : 1,
106 'primary' : false, 'hidden' : true, 'render' : 'obj.data.hash.ccs[ my.acp.status() ].name()'
109 'id' : 'checkin_status', 'label' : getString('staff.checkin_label_status'), 'flex' : 1,
110 'primary' : false, 'hidden' : true, 'render' : 'my.status.toString()'
113 'id' : 'checkin_route_to', 'label' : getString('staff.checkin_label_route_to'), 'flex' : 1,
114 'primary' : false, 'hidden' : true, 'render' : 'my.route_to.toString()'
117 'id' : 'checkin_text', 'label' : getString('staff.checkin_label_text'), 'flex' : 1,
118 'primary' : false, 'hidden' : true, 'render' : 'my.text.toString()'
122 for (var i = 0; i < c.length; i++) {
123 if (modify[ c[i].id ]) {
124 for (var j in modify[ c[i].id ]) {
125 c[i][j] = modify[ c[i].id ][j];
132 circ.util.hold_columns = function(modify) {
134 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
136 function getString(s) { return data.entities[s]; }
140 'id' : 'request_time', 'label' : getString('staff.ahr_request_time_label'), 'flex' : 0,
141 'primary' : false, 'hidden' : true,
142 'render' : 'my.ahr.request_time().toString().substr(0,10)'
145 'id' : 'capture_time', 'label' : getString('staff.ahr_capture_time_label'), 'flex' : 1,
146 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.capture_time()'
149 'id' : 'status', 'label' : getString('staff.ahr_status_label'), 'flex' : 1,
150 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.status()'
153 'id' : 'hold_type', 'label' : getString('staff.ahr_hold_type_label'), 'flex' : 0,
154 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.hold_type()'
157 'id' : 'pickup_lib', 'label' : getString('staff.ahr_pickup_lib_label'), 'flex' : 1,
158 'primary' : false, 'hidden' : true,
159 'render' : 'obj.data.hash.aou[ my.ahr.pickup_lib() ].name()'
162 'id' : 'pickup_lib_shortname', 'label' : getString('staff.ahr_pickup_lib_label'), 'flex' : 0,
163 'primary' : false, 'hidden' : true,
164 'render' : 'obj.data.hash.aou[ my.ahr.pickup_lib() ].shortname()'
167 'id' : 'current_copy', 'label' : getString('staff.ahr_current_copy_label'), 'flex' : 1,
168 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.current_copy()'
171 'id' : 'email_notify', 'label' : getString('staff.ahr_email_notify_label'), 'flex' : 1,
172 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.email_notify()'
175 'id' : 'expire_time', 'label' : getString('staff.ahr_expire_time_label'), 'flex' : 1,
176 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.expire_time()'
179 'id' : 'fulfillment_time', 'label' : getString('staff.ahr_fulfillment_time_label'), 'flex' : 1,
180 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.fulfillment_time()'
183 'id' : 'holdable_formats', 'label' : getString('staff.ahr_holdable_formats_label'), 'flex' : 1,
184 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.holdable_formats()'
187 'id' : 'id', 'label' : getString('staff.ahr_id_label'), 'flex' : 1,
188 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.id()'
191 'id' : 'phone_notify', 'label' : getString('staff.ahr_phone_notify_label'), 'flex' : 1,
192 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.phone_notify()'
195 'id' : 'prev_check_time', 'label' : getString('staff.ahr_prev_check_time_label'), 'flex' : 1,
196 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.prev_check_time()'
199 'id' : 'requestor', 'label' : getString('staff.ahr_requestor_label'), 'flex' : 1,
200 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.requestor()'
203 'id' : 'selection_depth', 'label' : getString('staff.ahr_selection_depth_label'), 'flex' : 1,
204 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.selection_depth()'
207 'id' : 'target', 'label' : getString('staff.ahr_target_label'), 'flex' : 1,
208 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.target()'
211 'id' : 'usr', 'label' : getString('staff.ahr_usr_label'), 'flex' : 1,
212 'primary' : false, 'hidden' : true, 'render' : 'my.ahr.usr()'
215 'id' : 'title', 'label' : getString('staff.mvr_label_title'), 'flex' : 1,
216 'primary' : false, 'hidden' : true, 'render' : 'my.mvr.title()'
219 'id' : 'author', 'label' : getString('staff.mvr_label_author'), 'flex' : 1,
220 'primary' : false, 'hidden' : true, 'render' : 'my.mvr.author()'
224 for (var i = 0; i < c.length; i++) {
225 if (modify[ c[i].id ]) {
226 for (var j in modify[ c[i].id ]) {
227 c[i][j] = modify[ c[i].id ][j];
234 circ.util.std_map_row_to_column = function() {
235 return function(row,col) {
236 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
237 // col contains one of the objects listed above in columns
239 // mimicking some of the obj in circ.checkin and circ.checkout where map_row_to_column is usually defined
241 JSAN.use('util.error'); obj.error = new util.error();
242 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
243 JSAN.use('util.network'); obj.network = new util.network();
248 value = eval( col.render );
250 obj.error.sdump('D_ERROR','map_row_to_column: ' + E);
257 circ.util.checkin_via_barcode = function(session,barcode,backdate) {
259 JSAN.use('util.error'); var error = new util.error();
260 JSAN.use('util.network'); var network = new util.network();
261 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
262 JSAN.use('util.date');
263 if (backdate && (backdate == util.date.formatted_date(new Date(),'%Y-%m-%d')) ) backdate = null;
265 var params = { 'barcode' : barcode };
266 if (backdate) params.backdate = backdate;
268 var check = network.request(
269 api.CHECKIN_VIA_BARCODE.app,
270 api.CHECKIN_VIA_BARCODE.method,
275 check.status = check.textcode;
276 check.text = check.textcode;
278 check.copy = check.payload.copy;
279 check.circ = check.payload.circ;
280 check.record = check.payload.record;
281 check.hold = check.payload.hold;
283 check.copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ barcode ]);
284 if (check.copy.ilsevent) {
285 check.text = check.copy.textcode; /* Probably 1502 - COPY_NOT_FOUND */
286 check.copy = new acp();
288 check.record = network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY',[ check.copy.id() ]);
289 if (check.record.ilsevent) {
290 check.text = check.record.textcode; /* Probably 1202 - ITEM_NOT_CATALOGED */
291 if (check.record.ilsevent == 1202) check.route_to = 'CATALOGING';
294 check.circ = new aoc();
296 if (typeof check.route_to != 'undefined') {
297 if (parseInt(check.route_to)) {
298 if (check.route_to != data.list.au[0].home_ou()) {
299 check.route_to = data.hash.aou[ check.route_to ].shortname();
301 check.route_to = data.hash.acpl[ check.copy.location() ].name();
305 check.route_to = data.hash.acpl[ check.copy.location() ].name();
308 if (check.ilsevent != 0) {
309 switch(check.ilsevent) {
310 case '1': case 1: /* possible hold capture */
311 var rv = error.yns_alert(
317 "Check here to confirm this message"
320 case 0: /* capture */
322 var check2 = this.hold_capture_via_copy_barcode( session, barcode );
324 check.copy = check2.copy;
325 check.text = check2.textcode;
326 check.route_to = check2.route_to;
327 JSAN.use('patron.util');
328 var au_obj = patron.util.retrieve_au_via_id( session, check.payload.hold.usr() );
329 alert('To Printer\n' + check.text + '\r\n' + 'Barcode: ' + barcode + ' Title: ' +
330 check.record.title() + ' Author: ' + check.record.author() +
331 '\r\n' + 'Route To: ' + check.route_to + ' Patron: ' +
332 au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' +
333 au_obj.first_given_name() + '\r\n'); //FIXME
336 sPrint(check.text + '<br />\r\n' + 'Barcode: ' + barcode + ' Title: ' +
337 check.record.title() + ' Author: ' + check.record.author() +
338 '<br />\r\n' + 'Route To: ' + check.route_to + ' Patron: ' +
339 au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' +
340 au_obj.first_given_name() + '<br />\r\n'
347 error.sdump('D_ERROR',E + '\n');
350 check.text = 'Captured for Hold';
351 check.route_to = 'ARL-ATH';
355 case 1: /* don't capture */
357 check.text = 'Not Captured for Hold';
361 case '2': case 2: /* LOST??? */
362 JSAN.use('patron.util');
363 var au_obj = patron.util.retrieve_au_via_id( session, check.circ.usr() );
364 var msg = check.text + '\r\n' + 'Barcode: ' + barcode + ' Title: ' +
365 check.record.title() + ' Author: ' + check.record.author() + '\r\n' +
366 'Patron: ' + au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' +
367 au_obj.first_given_name();
368 var pcheck = error.yns_alert(
371 'Edit Copy & Patron',
374 "Check here to confirm this message"
377 //FIXME//Re-implement
379 var w = mw.spawn_main();
382 mw.spawn_patron_display(w.document,'new_tab','main_tabbox',{'patron':au_obj});
383 mw.spawn_batch_copy_editor(w.document,'new_tab','main_tabbox',
384 {'copy_ids':[ check.copy.id() ]});
390 case '3': case 3: /* TRANSIT ELSEWHERE */
391 if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
392 var msg = check.text + '\r\n' + 'Barcode: ' + barcode + ' Title: ' +
393 check.record.title() + ' Author: ' + check.record.author() +
394 '\r\n' + 'Route To: ' + check.route_to + '\r\n';
395 var pcheck = error.yns_alert(
401 "Check here to confirm this message"
404 alert('To Printer\n' + msg); //FIXME//
405 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
409 case '4': case 4: /* transit for hold is complete */
410 if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
411 var msg = check.text + '\r\n' + 'Barcode: ' + barcode + ' Title: ' +
412 check.record.title() + ' Author: ' + check.record.author() +
413 '\r\n' + 'Route To: ' + check.route_to +
415 var pcheck = error.yns_alert(
421 "Check here to confirm this message"
424 alert('To Printer\n' + msg); //FIXME//
425 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
430 default: /* 1500 - "CIRCULATION_NOT_FOUND" */
431 if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
432 var msg = check.text + '\r\nBarcode: ' + barcode + ' Route To: ' + check.route_to;
433 var pcheck = error.yns_alert(
439 "Check here to confirm this message"
442 alert('To Printer\n' + msg); //FIXME//
443 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
447 } else { // ilsevent == 0
451 JSAN.use('util.error'); var error = new util.error();
452 var msg = E + '\n---\n' + js2JSON(E);
453 error.sdump('D_ERROR',msg);
459 circ.util.hold_capture_via_copy_barcode = function ( session, barcode, retrieve_flag ) {
461 JSAN.use('util.network'); var network = new util.network();
462 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
463 var robj = network.request(
464 api.CAPTURE_COPY_FOR_HOLD_VIA_BARCODE.app,
465 api.CAPTURE_COPY_FOR_HOLD_VIA_BARCODE.method,
466 [ session, barcode, retrieve_flag ]
468 var check = robj.payload;
471 check.status = robj.ilsevent;
472 check.copy = new acp(); check.copy.barcode( barcode );
474 check.text = robj.textcode;
475 check.route_to = robj.route_to;
476 //check.text = 'Captured for Hold';
477 if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
480 JSAN.use('util.error'); var error = new util.error();
481 var msg = E + '\n---\n' + js2JSON(E);
482 error.sdump('D_ERROR',msg);
489 dump('exiting circ/util.js\n');