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_opac_holds.setAttribute('disabled','true');
63 obj.controller.view.sel_patron.setAttribute('disabled','true');
64 obj.controller.view.sel_last_patron.setAttribute('disabled','true');
65 obj.controller.view.sel_copy_details.setAttribute('disabled','true');
66 obj.controller.view.sel_bucket.setAttribute('disabled','true');
67 obj.controller.view.sel_spine.setAttribute('disabled','true');
68 obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
69 obj.controller.view.sel_clip.setAttribute('disabled','true');
70 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
72 obj.controller.view.sel_edit.setAttribute('disabled','false');
73 obj.controller.view.sel_opac.setAttribute('disabled','false');
74 obj.controller.view.sel_opac_holds.setAttribute('disabled','false');
75 obj.controller.view.sel_patron.setAttribute('disabled','false');
76 obj.controller.view.sel_last_patron.setAttribute('disabled','false');
77 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
78 obj.controller.view.sel_bucket.setAttribute('disabled','false');
79 obj.controller.view.sel_spine.setAttribute('disabled','false');
80 obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
81 obj.controller.view.sel_clip.setAttribute('disabled','false');
82 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
91 JSAN.use('util.controller'); obj.controller = new util.controller();
95 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
100 obj.controller.view.renew_barcode_entry_textbox.focus();
107 obj.spawn_copy_editor();
116 JSAN.use('cat.util');
117 cat.util.spawn_spine_editor(obj.selection_list);
123 JSAN.use('cat.util');
124 cat.util.show_in_opac(obj.selection_list);
130 JSAN.use('cat.util');
131 cat.util.show_in_opac(obj.selection_list,{default_view:'hold_browser'});
134 'sel_transit_abort' : [
137 JSAN.use('circ.util');
138 circ.util.abort_transits(obj.selection_list);
144 JSAN.use('circ.util');
145 circ.util.show_last_few_circs(obj.selection_list);
148 'sel_last_patron' : [
152 for (var i = 0; i < obj.selection_list.length; i++) {
153 var circs = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),obj.selection_list[i].copy_id,1]);
154 if (circs.length > 0) {
155 patrons[circs[0].usr()] = 1;
157 alert(document.getElementById('circStrings').getFormattedString('staff.circ.item_no_circs', [obj.selection_list[i].barcode]));
160 for (var i in patrons) {
161 xulG.new_patron_tab({},{'id' : i});
165 'sel_copy_details' : [
168 JSAN.use('circ.util');
169 circ.util.item_details_new(
170 util.functional.map_list(
172 function(o) { return o.barcode; }
177 'sel_mark_items_damaged' : [
181 JSAN.use('cat.util'); JSAN.use('util.functional');
182 cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
188 JSAN.use('cat.util');
189 cat.util.add_copies_to_bucket(obj.selection_list);
192 'renew_barcode_entry_textbox' : [
195 if (ev.keyCode && ev.keyCode == 13) {
202 function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
204 'cmd_renew_submit_barcode' : [
210 'cmd_renew_print' : [
214 'printer_context' : 'receipt',
220 'cmd_csv_to_clipboard' : [ ['command'], function() {
221 obj.list.dump_csv_to_clipboard();
222 obj.controller.view.renew_barcode_entry_textbox.focus();
224 'cmd_csv_to_printer' : [ ['command'], function() {
225 obj.list.dump_csv_to_printer();
226 obj.controller.view.renew_barcode_entry_textbox.focus();
228 'cmd_csv_to_file' : [ ['command'], function() {
229 obj.list.dump_csv_to_file( { 'defaultFileName' : 'checked_in.txt' } );
230 obj.controller.view.renew_barcode_entry_textbox.focus();
232 'renew_duedate_datepicker' : [
236 if (obj.check_date(ev.target)) {
237 ev.target.parentNode.setAttribute('style','');
239 ev.target.parentNode.setAttribute('style','background-color: red');
242 alert('Error in renew.js, renew_duedate_datepicker @change: ' + E);
250 this.controller.render();
251 this.controller.view.renew_barcode_entry_textbox.focus();
255 'test_barcode' : function(bc) {
257 var x = document.getElementById('strict_barcode');
258 if (x && x.checked != true) return true;
259 var good = util.barcode.check(bc);
263 if ( 1 == obj.error.yns_alert(
264 document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
265 document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
266 document.getElementById('circStrings').getString('staff.circ.cancel'),
267 document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
269 document.getElementById('circStrings').getString('staff.circ.confirm'),
270 '/xul/server/skin/media/images/bad_barcode.png'
279 'renew' : function(params) {
282 if (!params) params = {};
284 var barcode = obj.controller.view.renew_barcode_entry_textbox.value;
285 if (!barcode) return;
287 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
289 params.barcode = barcode;
290 params.return_patron = true;
292 var auto_print = document.getElementById('renew_auto');
293 if (auto_print) auto_print = auto_print.checked;
295 if (document.getElementById('renew_duedate_checkbox').checked) {
296 if (! obj.check_date(obj.controller.view.renew_duedate_datepicker)) return;
297 var tp = document.getElementById('renew_duedate_timepicker');
298 var dp = obj.controller.view.renew_duedate_datepicker;
299 var tp_date = tp.dateValue;
300 var dp_date = dp.dateValue;
301 dp_date.setHours( tp_date.getHours() );
302 dp_date.setMinutes( tp_date.getMinutes() );
304 JSAN.use('util.date');
305 params.due_date = util.date.formatted_date(dp_date,'%{iso8601}');
309 JSAN.use('circ.util');
310 var renew = circ.util.renew_via_barcode(
313 obj.renew_followup( r, barcode );
317 obj.error.standard_unexpected_error_alert('Error in circ/renew.js, renew():', E);
318 if (typeof obj.on_failure == 'function') {
321 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
322 window.xulG.on_failure(E);
327 'renew_followup' : function(r,bc) {
330 if (!r) return obj.on_failure(); /* circ.util.renew handles errors and returns null currently */
331 if ( (typeof r[0].ilsevent != 'undefined' && r[0].ilsevent == 0) ) {
333 var x = document.getElementById('no_change_label');
336 x.setAttribute('value','');
340 var msg = document.getElementById("patronStrings").getFormattedString('staff.patron.items.items_renew.not_renewed',[bc, r[0].textcode + r[0].desc]);
341 var x = document.getElementById('no_change_label');
344 x.setAttribute('value',msg);
346 obj.controller.view.renew_barcode_entry_textbox.focus();
347 obj.controller.view.renew_barcode_entry_textbox.select();
350 var renew = r[0].payload;
351 var retrieve_id = js2JSON( { 'copy_id' : renew.copy.id(), 'barcode' : renew.copy.barcode(), 'doc_id' : (renew.record == null ? null : renew.record.doc_id() ) } );
352 if (document.getElementById('trim_list')) {
353 var x = document.getElementById('trim_list');
354 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
358 'retrieve_id' : retrieve_id,
362 'mbts' : renew.parent_circ ? renew.parent_circ.billable_transaction().summary() : null,
363 'mvr' : renew.record,
365 'acn' : renew.volume,
367 'status' : renew.status,
368 'route_to' : renew.route_to,
369 'message' : renew.message
374 obj.list.append( params );
376 if (params.row.my.mbts && ( document.getElementById('no_change_label') || document.getElementById('fine_tally') ) ) {
377 JSAN.use('util.money');
378 var bill = params.row.my.mbts;
379 if (Number(bill.balance_owed()) != 0) {
380 if (document.getElementById('no_change_label')) {
381 var m = document.getElementById('no_change_label').getAttribute('value');
382 document.getElementById('no_change_label').setAttribute(
384 m + document.getElementById('circStrings').getFormattedString('staff.circ.utils.billable.amount', [params.row.my.acp.barcode(), util.money.sanitize(bill.balance_owed())]) + ' '
386 document.getElementById('no_change_label').setAttribute('hidden','false');
388 if (document.getElementById('fine_tally')) {
389 var amount = Number( document.getElementById('fine_tally').getAttribute('amount') ) + Number( bill.balance_owed() );
390 document.getElementById('fine_tally').setAttribute('amount',amount);
391 document.getElementById('fine_tally').setAttribute(
393 document.getElementById('circStrings').getFormattedString('staff.circ.utils.fine_tally_text', [ util.money.sanitize( amount ) ])
395 document.getElementById('fine_tally').setAttribute('hidden','false');
400 obj.list.node.view.selection.select(0);
402 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
404 if (typeof obj.on_renew == 'function') {
407 if (typeof window.xulG == 'object' && typeof window.xulG.on_renew == 'function') {
408 window.xulG.on_renew(renew);
414 obj.error.standard_unexpected_error_alert('Error in circ/renew.js, renew_followup():', E);
415 if (typeof obj.on_failure == 'function') {
418 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
419 window.xulG.on_failure(E);
425 'on_renew' : function() {
427 this.controller.view.renew_barcode_entry_textbox.disabled = false;
428 this.controller.view.renew_barcode_entry_textbox.select();
429 this.controller.view.renew_barcode_entry_textbox.value = '';
430 this.controller.view.renew_barcode_entry_textbox.focus();
432 alert('Error in renew.js, on_renew(): ' + E);
436 'on_failure' : function() {
438 this.controller.view.renew_barcode_entry_textbox.disabled = false;
439 this.controller.view.renew_barcode_entry_textbox.select();
440 this.controller.view.renew_barcode_entry_textbox.focus();
442 alert('Error in renew.js, on_failure(): ' + E);
446 'spawn_copy_editor' : function() {
450 JSAN.use('util.functional');
452 var list = obj.selection_list;
454 list = util.functional.map_list(
461 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
465 'check_date' : function(node) {
467 JSAN.use('util.date');
469 obj.controller.view.renew_barcode_entry_textbox.setAttribute('disabled','false');
470 obj.controller.view.renew_barcode_entry_textbox.disabled = false;
471 obj.controller.view.cmd_renew_submit_barcode.setAttribute('disabled','false');
472 obj.controller.view.cmd_renew_submit_barcode.disabled = false;
473 if (util.date.check_past('YYYY-MM-DD',node.value) ) {
474 obj.controller.view.renew_barcode_entry_textbox.setAttribute('disabled','true');
475 obj.controller.view.cmd_renew_submit_barcode.setAttribute('disabled','true');
486 dump('exiting circ.renew.js\n');