1 dump('entering circ/util.js\n');
3 if (typeof circ == 'undefined') var circ = {};
6 circ.util.EXPORT_OK = [
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' : 'my.acp.call_number()'
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' : 'my.acp.location()'
47 'id' : 'loan_duration', 'label' : getString('staff.acp_label_loan_duration'), 'flex' : 1,
48 'primary' : false, 'hidden' : true, 'render' : 'my.acp.loan_duration()'
51 'id' : 'circ_lib', 'label' : getString('staff.acp_label_circ_lib'), 'flex' : 1,
52 'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_lib()'
55 'id' : 'fine_level', 'label' : getString('staff.acp_label_fine_level'), 'flex' : 1,
56 'primary' : false, 'hidden' : true, 'render' : 'my.acp.fine_level()'
59 'id' : 'deposit', 'label' : getString('staff.acp_label_deposit'), 'flex' : 1,
60 'primary' : false, 'hidden' : true, 'render' : 'my.acp.deposit()'
63 'id' : 'deposit_amount', 'label' : getString('staff.acp_label_deposit_amount'), 'flex' : 1,
64 'primary' : false, 'hidden' : true, 'render' : 'my.acp.deposit_amount()'
67 'id' : 'price', 'label' : getString('staff.acp_label_price'), 'flex' : 1,
68 'primary' : false, 'hidden' : true, 'render' : 'my.acp.price()'
71 'id' : 'circ_as_type', 'label' : getString('staff.acp_label_circ_as_type'), 'flex' : 1,
72 'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_as_type()'
75 'id' : 'circ_modifier', 'label' : getString('staff.acp_label_circ_modifier'), 'flex' : 1,
76 'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_modifier()'
79 'id' : 'xact_start', 'label' : getString('staff.circ_label_xact_start'), 'flex' : 1,
80 'primary' : false, 'hidden' : true, 'render' : 'my.circ.xact_start()'
83 'id' : 'xact_finish', 'label' : getString('staff.circ_label_xact_finish'), 'flex' : 1,
84 'primary' : false, 'hidden' : true, 'render' : 'my.circ.xact_finish()'
87 'id' : 'due_date', 'label' : getString('staff.circ_label_due_date'), 'flex' : 1,
88 'primary' : false, 'hidden' : true, 'render' : 'my.circ.due_date().substr(0,10)'
91 'id' : 'title', 'label' : getString('staff.mvr_label_title'), 'flex' : 2,
92 'primary' : false, 'hidden' : true, 'render' : 'my.mvr.title()'
95 'id' : 'author', 'label' : getString('staff.mvr_label_author'), 'flex' : 1,
96 'primary' : false, 'hidden' : true, 'render' : 'my.mvr.author()'
99 'id' : 'renewal_remaining', 'label' : getString('staff.circ_label_renewal_remaining'), 'flex' : 0,
100 'primary' : false, 'hidden' : true, 'render' : 'my.circ.renewal_remaining()'
103 'id' : 'status', 'label' : getString('staff.acp_label_status'), 'flex' : 1,
104 'primary' : false, 'hidden' : true, 'render' : 'obj.OpenILS.data.hash.ccs[ my.acp.status() ].name()'
107 for (var i = 0; i < c.length; i++) {
108 if (modify[ c[i].id ]) {
109 for (var j in modify[ c[i].id ]) {
110 c[i][j] = modify[ c[i].id ][j];
117 circ.util.std_map_row_to_column = function() {
118 return function(row,col) {
119 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
120 // col contains one of the objects listed above in columns
122 // mimicking some of the obj in circ.checkin and circ.checkout where map_row_to_column is usually defined
123 var obj = {}; obj.OpenILS = {}; // One of our circ columns uses OpenILS.data
124 JSAN.use('OpenILS.data'); obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
129 value = eval( col.render );
131 obj.error.sdump('D_ERROR','map_row_to_column: ' + E);
138 circ.util.checkin_via_barcode = function(session,barcode,backdate) {
140 JSAN.use('util.error'); var error = new util.error();
141 JSAN.use('util.network'); var network = new util.network();
142 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
143 JSAN.use('util.date');
144 if (backdate && (backdate == util.date.formatted_date(new Date(),'%Y-%m-%d')) ) backdate = null;
146 var check = network.request(
147 api.checkin_via_barcode.app,
148 api.checkin_via_barcode.method,
149 [ session, barcode, null, backdate ]
153 { // REMOVE_ME, forcing a condition for testing
155 check.text = 'This copy is the first that could fulfill a hold. Do it?';
159 if (check.status != 0) {
160 switch(check.status) {
161 case '1': case 1: /* possible hold capture */
162 var rv = error.yns_alert(
168 "Check here to confirm this message"
171 case 0: /* capture */
173 var check2 = this.hold_capture_by_copy_barcode( session, barcode );
175 check.copy = check2.copy;
176 check.text = check2.text;
177 check.route_to = check2.route_to;
178 JSAN.use('patron.util');
179 var patron = patron.util.retrieve_au_by_id( check.hold.usr() );
180 alert('To Printer\n' + check.text + '\r\n' + 'Barcode: ' + barcode + ' Title: ' +
181 check.record.title() + ' Author: ' + check.record.author() +
182 '\r\n' + 'Route To: ' + check.route_to + ' Patron: ' +
183 patron.card().barcode() + ' ' + patron.family_name() + ', ' +
184 patron.first_given_name() + '\r\n'); //FIXME
187 sPrint(check.text + '<br />\r\n' + 'Barcode: ' + barcode + ' Title: ' +
188 check.record.title() + ' Author: ' + check.record.author() +
189 '<br />\r\n' + 'Route To: ' + check.route_to + ' Patron: ' +
190 patron.card().barcode() + ' ' + patron.family_name() + ', ' +
191 patron.first_given_name() + '<br />\r\n'
198 error.sdump('D_ERROR',E + '\n');
201 check.text = 'Captured for Hold';
202 check.route_to = 'ARL-ATH';
206 case 1: /* don't capture */
208 check.text = 'Not Captured for Hold';
212 case '2': case 2: /* LOST??? */
213 JSAN.use('patron.util');
214 var patron = patron.util.retrieve_au_by_id( check.circ.usr() );
215 var msg = check.text + '\r\n' + 'Barcode: ' + barcode + ' Title: ' +
216 check.record.title() + ' Author: ' + check.record.author() + '\r\n' +
217 'Patron: ' + patron.card().barcode() + ' ' + patron.family_name() + ', ' +
218 patron.first_given_name();
219 var pcheck = error.yns_alert(
222 'Edit Copy & Patron',
225 "Check here to confirm this message"
228 //FIXME//Re-implement
230 var w = mw.spawn_main();
233 mw.spawn_patron_display(w.document,'new_tab','main_tabbox',{'patron':patron});
234 mw.spawn_batch_copy_editor(w.document,'new_tab','main_tabbox',
235 {'copy_ids':[ check.copy.id() ]});
241 case '3': case 3: /* TRANSIT ELSEWHERE */
242 if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
243 var msg = check.text + '\r\n' + 'Barcode: ' + barcode + ' Title: ' +
244 check.record.title() + ' Author: ' + check.record.author() +
245 '\r\n' + 'Route To: ' + check.route_to + '\r\n';
246 var pcheck = error.yns_alert(
252 "Check here to confirm this message"
255 alert('To Printer\n' + msg); //FIXME//
256 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
260 case '4': case 4: /* transit for hold is complete */
261 if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
262 var msg = check.text + '\r\n' + 'Barcode: ' + barcode + ' Title: ' +
263 check.record.title() + ' Author: ' + check.record.author() +
264 '\r\n' + 'Route To: ' + check.route_to +
266 var pcheck = error.yns_alert(
272 "Check here to confirm this message"
275 alert('To Printer\n' + msg); //FIXME//
276 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
282 if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
283 var msg = check.text + '\r\nBarcode: ' + barcode + ' Route To: ' + check.route_to;
284 var pcheck = error.yns_alert(
290 "Check here to confirm this message"
293 alert('To Printer\n' + msg); //FIXME//
294 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
298 } else { // status == 0
300 if (parseInt(check.route_to)) {
301 if (check.route_to != data.list.au[0].home_ou()) {
302 check.route_to = data.hash.aou[ check.route_to ].shortname();
304 check.route_to = data.hash.acpl[ check.copy.location() ].name();
309 JSAN.use('util.error'); var error = new util.error();
310 var msg = E + '\n---\n' + js2JSON(E);
311 error.sdump('D_ERROR',msg);
317 circ.util.hold_capture_by_copy_barcode = function ( session, barcode, retrieve_flag ) {
319 JSAN.use('util.network'); var network = new util.network();
320 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
321 var check = network.request(
322 api.capture_copy_for_hold_via_barcode.app,
323 api.capture_copy_for_hold_via_barcode.method,
324 [ session, barcode, retrieve_flag ]
326 check.text = 'Captured for Hold';
327 if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
330 JSAN.use('util.error'); var error = new util.error();
331 var msg = E + '\n---\n' + js2JSON(E);
332 error.sdump('D_ERROR',msg);
339 dump('exiting circ/util.js\n');