1 dump('entering circ.renew.js\n');
3 if (typeof circ == 'undefined') circ = {};
4 circ.renew = function (params) {
6 JSAN.use('util.error'); this.error = new util.error();
7 JSAN.use('util.network'); this.network = new util.network();
8 JSAN.use('util.barcode');
10 this.OpenILS = {}; JSAN.use('OpenILS.data'); this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
11 this.data = this.OpenILS.data;
14 circ.renew.prototype = {
16 'selection_list' : [],
18 'init' : function( params ) {
22 JSAN.use('circ.util'); JSAN.use('patron.util');
23 var columns = circ.util.columns(
25 'barcode' : { 'hidden' : false },
26 'title' : { 'hidden' : false },
27 'location' : { 'hidden' : false },
28 'call_number' : { 'hidden' : false },
29 'status' : { 'hidden' : false },
30 'alert_message' : { 'hidden' : false },
31 'due_date' : { 'hidden' : false },
32 'due_time' : { 'hidden' : false },
33 'renewal_remaining' : { 'hidden' : false }
36 'except_these' : [ 'uses', 'checkin_time_full' ]
39 patron.util.columns( { 'family_name' : { 'hidden' : 'false' } } )
42 patron.util.mbts_columns( {}, { 'except_these' : [ 'total_paid', 'total_owed', 'xact_start', 'xact_finish', 'xact_type' ] } )
44 ).sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
46 JSAN.use('util.list'); obj.list = new util.list('renew_list');
50 'on_select' : function(ev) {
52 JSAN.use('util.functional');
53 var sel = obj.list.retrieve_selection();
54 obj.selection_list = util.functional.map_list(
56 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
58 obj.error.sdump('D_TRACE', 'circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
59 if (obj.selection_list.length == 0) {
60 obj.controller.view.sel_edit.setAttribute('disabled','true');
61 obj.controller.view.sel_opac.setAttribute('disabled','true');
62 obj.controller.view.sel_patron.setAttribute('disabled','true');
63 obj.controller.view.sel_last_patron.setAttribute('disabled','true');
64 obj.controller.view.sel_copy_details.setAttribute('disabled','true');
65 obj.controller.view.sel_bucket.setAttribute('disabled','true');
66 obj.controller.view.sel_spine.setAttribute('disabled','true');
67 obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
68 obj.controller.view.sel_clip.setAttribute('disabled','true');
69 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
71 obj.controller.view.sel_edit.setAttribute('disabled','false');
72 obj.controller.view.sel_opac.setAttribute('disabled','false');
73 obj.controller.view.sel_patron.setAttribute('disabled','false');
74 obj.controller.view.sel_last_patron.setAttribute('disabled','false');
75 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
76 obj.controller.view.sel_bucket.setAttribute('disabled','false');
77 obj.controller.view.sel_spine.setAttribute('disabled','false');
78 obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
79 obj.controller.view.sel_clip.setAttribute('disabled','false');
80 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
89 JSAN.use('util.controller'); obj.controller = new util.controller();
93 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
98 obj.controller.view.renew_barcode_entry_textbox.focus();
105 obj.spawn_copy_editor();
114 JSAN.use('cat.util');
115 cat.util.spawn_spine_editor(obj.selection_list);
121 JSAN.use('cat.util');
122 cat.util.show_in_opac(obj.selection_list);
125 'sel_transit_abort' : [
128 JSAN.use('circ.util');
129 circ.util.abort_transits(obj.selection_list);
135 JSAN.use('circ.util');
136 circ.util.show_last_few_circs(obj.selection_list);
139 'sel_last_patron' : [
143 for (var i = 0; i < obj.selection_list.length; i++) {
144 var circs = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),obj.selection_list[i].copy_id,1]);
145 if (circs.length > 0) {
146 patrons[circs[0].usr()] = 1;
148 alert(document.getElementById('circStrings').getFormattedString('staff.circ.item_no_circs', [obj.selection_list[i].barcode]));
151 for (var i in patrons) {
152 xulG.new_patron_tab({},{'id' : i});
156 'sel_copy_details' : [
159 JSAN.use('circ.util');
160 circ.util.item_details_new(
161 util.functional.map_list(
163 function(o) { return o.barcode; }
168 'sel_mark_items_damaged' : [
172 JSAN.use('cat.util'); JSAN.use('util.functional');
173 cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
179 JSAN.use('cat.util');
180 cat.util.add_copies_to_bucket(obj.selection_list);
183 'renew_barcode_entry_textbox' : [
186 if (ev.keyCode && ev.keyCode == 13) {
193 function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
195 'cmd_renew_submit_barcode' : [
201 'cmd_renew_print' : [
205 'printer_context' : 'receipt',
211 'cmd_csv_to_clipboard' : [ ['command'], function() {
212 obj.list.dump_csv_to_clipboard();
213 obj.controller.view.renew_barcode_entry_textbox.focus();
215 'cmd_csv_to_printer' : [ ['command'], function() {
216 obj.list.dump_csv_to_printer();
217 obj.controller.view.renew_barcode_entry_textbox.focus();
219 'cmd_csv_to_file' : [ ['command'], function() {
220 obj.list.dump_csv_to_file( { 'defaultFileName' : 'checked_in.txt' } );
221 obj.controller.view.renew_barcode_entry_textbox.focus();
223 'renew_duedate_datepicker' : [
227 if (obj.check_date(ev.target)) {
228 ev.target.parentNode.setAttribute('style','');
230 ev.target.parentNode.setAttribute('style','background-color: red');
233 alert('Error in renew.js, renew_duedate_datepicker @change: ' + E);
241 this.controller.render();
242 this.controller.view.renew_barcode_entry_textbox.focus();
246 'test_barcode' : function(bc) {
248 var x = document.getElementById('strict_barcode');
249 if (x && x.checked != true) return true;
250 var good = util.barcode.check(bc);
254 if ( 1 == obj.error.yns_alert(
255 document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
256 document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
257 document.getElementById('circStrings').getString('staff.circ.cancel'),
258 document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
260 document.getElementById('circStrings').getString('staff.circ.confirm'),
261 '/xul/server/skin/media/images/bad_barcode.png'
270 'renew' : function(params) {
273 if (!params) params = {};
275 var barcode = obj.controller.view.renew_barcode_entry_textbox.value;
276 if (!barcode) return;
278 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
280 params.barcode = barcode;
281 params.return_patron = true;
283 var auto_print = document.getElementById('renew_auto');
284 if (auto_print) auto_print = auto_print.checked;
286 if (document.getElementById('renew_duedate_checkbox').checked) {
287 if (! obj.check_date(obj.controller.view.renew_duedate_datepicker)) return;
288 var tp = document.getElementById('renew_duedate_timepicker');
289 var dp = obj.controller.view.renew_duedate_datepicker;
290 var tp_date = tp.dateValue;
291 var dp_date = dp.dateValue;
292 dp_date.setHours( tp_date.getHours() );
293 dp_date.setMinutes( tp_date.getMinutes() );
295 JSAN.use('util.date');
296 params.due_date = util.date.formatted_date(dp_date,'%{iso8601}');
300 JSAN.use('circ.util');
301 var renew = circ.util.renew_via_barcode(
304 obj.renew_followup( r, barcode );
308 obj.error.standard_unexpected_error_alert('Error in circ/renew.js, renew():', E);
309 if (typeof obj.on_failure == 'function') {
312 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
313 window.xulG.on_failure(E);
318 'renew_followup' : function(r,bc) {
321 if (!r) return obj.on_failure(); /* circ.util.renew handles errors and returns null currently */
322 if ( (typeof r[0].ilsevent != 'undefined' && r[0].ilsevent == 0) ) {
324 var x = document.getElementById('no_change_label');
327 x.setAttribute('value','');
331 var msg = document.getElementById("patronStrings").getFormattedString('staff.patron.items.items_renew.not_renewed',[bc, r[0].textcode + r[0].desc]);
332 var x = document.getElementById('no_change_label');
335 x.setAttribute('value',msg);
337 obj.controller.view.renew_barcode_entry_textbox.focus();
338 obj.controller.view.renew_barcode_entry_textbox.select();
341 var renew = r[0].payload;
342 var retrieve_id = js2JSON( { 'copy_id' : renew.copy.id(), 'barcode' : renew.copy.barcode(), 'doc_id' : (renew.record == null ? null : renew.record.doc_id() ) } );
343 if (document.getElementById('trim_list')) {
344 var x = document.getElementById('trim_list');
345 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
349 'retrieve_id' : retrieve_id,
353 'mbts' : renew.parent_circ ? renew.parent_circ.billable_transaction().summary() : null,
354 'mvr' : renew.record,
356 'acn' : renew.volume,
358 'status' : renew.status,
359 'route_to' : renew.route_to,
360 'message' : renew.message
365 obj.list.append( params );
367 if (params.row.my.mbts && ( document.getElementById('no_change_label') || document.getElementById('fine_tally') ) ) {
368 JSAN.use('util.money');
369 var bill = params.row.my.mbts;
370 if (Number(bill.balance_owed()) != 0) {
371 if (document.getElementById('no_change_label')) {
372 var m = document.getElementById('no_change_label').getAttribute('value');
373 document.getElementById('no_change_label').setAttribute(
375 m + document.getElementById('circStrings').getFormattedString('staff.circ.utils.billable.amount', [params.row.my.acp.barcode(), util.money.sanitize(bill.balance_owed())]) + ' '
377 document.getElementById('no_change_label').setAttribute('hidden','false');
379 if (document.getElementById('fine_tally')) {
380 var amount = Number( document.getElementById('fine_tally').getAttribute('amount') ) + Number( bill.balance_owed() );
381 document.getElementById('fine_tally').setAttribute('amount',amount);
382 document.getElementById('fine_tally').setAttribute(
384 document.getElementById('circStrings').getFormattedString('staff.circ.utils.fine_tally_text', [ util.money.sanitize( amount ) ])
386 document.getElementById('fine_tally').setAttribute('hidden','false');
391 obj.list.node.view.selection.select(0);
393 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
395 if (typeof obj.on_renew == 'function') {
398 if (typeof window.xulG == 'object' && typeof window.xulG.on_renew == 'function') {
399 window.xulG.on_renew(renew);
405 obj.error.standard_unexpected_error_alert('Error in circ/renew.js, renew_followup():', E);
406 if (typeof obj.on_failure == 'function') {
409 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
410 window.xulG.on_failure(E);
416 'on_renew' : function() {
418 this.controller.view.renew_barcode_entry_textbox.disabled = false;
419 this.controller.view.renew_barcode_entry_textbox.select();
420 this.controller.view.renew_barcode_entry_textbox.value = '';
421 this.controller.view.renew_barcode_entry_textbox.focus();
423 alert('Error in renew.js, on_renew(): ' + E);
427 'on_failure' : function() {
429 this.controller.view.renew_barcode_entry_textbox.disabled = false;
430 this.controller.view.renew_barcode_entry_textbox.select();
431 this.controller.view.renew_barcode_entry_textbox.focus();
433 alert('Error in renew.js, on_failure(): ' + E);
437 'spawn_copy_editor' : function() {
441 JSAN.use('util.functional');
443 var list = obj.selection_list;
445 list = util.functional.map_list(
452 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
456 'check_date' : function(node) {
458 JSAN.use('util.date');
460 obj.controller.view.renew_barcode_entry_textbox.setAttribute('disabled','false');
461 obj.controller.view.renew_barcode_entry_textbox.disabled = false;
462 obj.controller.view.cmd_renew_submit_barcode.setAttribute('disabled','false');
463 obj.controller.view.cmd_renew_submit_barcode.disabled = false;
464 if (util.date.check_past('YYYY-MM-DD',node.value) ) {
465 obj.controller.view.renew_barcode_entry_textbox.setAttribute('disabled','true');
466 obj.controller.view.cmd_renew_submit_barcode.setAttribute('disabled','true');
477 dump('exiting circ.renew.js\n');