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 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
51 'on_select' : function(ev) {
53 JSAN.use('util.functional');
54 var sel = obj.list.retrieve_selection();
55 obj.selection_list = util.functional.map_list(
57 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
59 obj.error.sdump('D_TRACE', 'circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
60 if (obj.selection_list.length == 0) {
61 obj.controller.view.sel_edit.setAttribute('disabled','true');
62 obj.controller.view.sel_opac.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_patron.setAttribute('disabled','false');
75 obj.controller.view.sel_last_patron.setAttribute('disabled','false');
76 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
77 obj.controller.view.sel_bucket.setAttribute('disabled','false');
78 obj.controller.view.sel_spine.setAttribute('disabled','false');
79 obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
80 obj.controller.view.sel_clip.setAttribute('disabled','false');
81 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
90 JSAN.use('util.controller'); obj.controller = new util.controller();
94 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
99 obj.controller.view.renew_barcode_entry_textbox.focus();
106 obj.spawn_copy_editor();
115 JSAN.use('cat.util');
116 cat.util.spawn_spine_editor(obj.selection_list);
122 JSAN.use('cat.util');
123 cat.util.show_in_opac(obj.selection_list);
126 'sel_transit_abort' : [
129 JSAN.use('circ.util');
130 circ.util.abort_transits(obj.selection_list);
136 JSAN.use('circ.util');
137 circ.util.show_last_few_circs(obj.selection_list);
140 'sel_last_patron' : [
144 for (var i = 0; i < obj.selection_list.length; i++) {
145 var circs = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),obj.selection_list[i].copy_id,1]);
146 if (circs.length > 0) {
147 patrons[circs[0].usr()] = 1;
149 alert(document.getElementById('circStrings').getFormattedString('staff.circ.item_no_circs', [obj.selection_list[i].barcode]));
152 for (var i in patrons) {
153 xulG.new_patron_tab({},{'id' : i});
157 'sel_copy_details' : [
160 JSAN.use('circ.util');
161 for (var i = 0; i < obj.selection_list.length; i++) {
162 circ.util.show_copy_details( obj.selection_list[i].copy_id );
166 'sel_mark_items_damaged' : [
170 JSAN.use('cat.util'); JSAN.use('util.functional');
171 cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
177 JSAN.use('cat.util');
178 cat.util.add_copies_to_bucket(obj.selection_list);
181 'renew_barcode_entry_textbox' : [
184 if (ev.keyCode && ev.keyCode == 13) {
191 function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
193 'cmd_renew_submit_barcode' : [
199 'cmd_renew_print' : [
208 'cmd_csv_to_clipboard' : [ ['command'], function() {
209 obj.list.dump_csv_to_clipboard();
210 obj.controller.view.renew_barcode_entry_textbox.focus();
212 'cmd_csv_to_printer' : [ ['command'], function() {
213 obj.list.dump_csv_to_printer();
214 obj.controller.view.renew_barcode_entry_textbox.focus();
216 'cmd_csv_to_file' : [ ['command'], function() {
217 obj.list.dump_csv_to_file( { 'defaultFileName' : 'checked_in.txt' } );
218 obj.controller.view.renew_barcode_entry_textbox.focus();
223 this.controller.render();
224 this.controller.view.renew_barcode_entry_textbox.focus();
228 'test_barcode' : function(bc) {
230 var x = document.getElementById('strict_barcode');
231 if (x && x.checked != true) return true;
232 var good = util.barcode.check(bc);
236 if ( 1 == obj.error.yns_alert(
237 document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
238 document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
239 document.getElementById('circStrings').getString('staff.circ.cancel'),
240 document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
242 document.getElementById('circStrings').getString('staff.circ.confirm'),
243 '/xul/server/skin/media/images/bad_barcode.png'
252 'renew' : function() {
255 var barcode = obj.controller.view.renew_barcode_entry_textbox.value;
256 if (!barcode) return;
258 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
260 var auto_print = document.getElementById('renew_auto');
261 if (auto_print) auto_print = auto_print.checked;
262 JSAN.use('circ.util');
263 var renew = circ.util.renew_via_barcode(
267 obj.renew_followup( r, barcode );
271 obj.error.standard_unexpected_error_alert('Error in circ/renew.js, renew():', E);
272 if (typeof obj.on_failure == 'function') {
275 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
276 window.xulG.on_failure(E);
281 'renew_followup' : function(r,bc) {
284 if (!r) return obj.on_failure(); /* circ.util.renew handles errors and returns null currently */
285 if ( (typeof r[0].ilsevent != 'undefined' && r[0].ilsevent == 0) ) {
287 var x = document.getElementById('no_change_label');
290 x.setAttribute('value','');
294 var msg = document.getElementById("patronStrings").getFormattedString('staff.patron.items.items_renew.not_renewed',[bc, r[0].textcode + r[0].desc]);
295 var x = document.getElementById('no_change_label');
298 x.setAttribute('value',msg);
300 obj.controller.view.renew_barcode_entry_textbox.focus();
301 obj.controller.view.renew_barcode_entry_textbox.select();
304 var renew = r[0].payload;
305 var retrieve_id = js2JSON( { 'copy_id' : renew.copy.id(), 'barcode' : renew.copy.barcode(), 'doc_id' : (renew.record == null ? null : renew.record.doc_id() ) } );
306 if (document.getElementById('trim_list')) {
307 var x = document.getElementById('trim_list');
308 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
312 'retrieve_id' : retrieve_id,
316 'mbts' : renew.parent_circ ? renew.parent_circ.billable_transaction().summary() : null,
317 'mvr' : renew.record,
319 'status' : renew.status,
320 'route_to' : renew.route_to,
321 'message' : renew.message
326 obj.list.append( params );
328 if (params.row.my.mbts && ( document.getElementById('no_change_label') || document.getElementById('fine_tally') ) ) {
329 JSAN.use('util.money');
330 var bill = params.row.my.mbts;
331 if (Number(bill.balance_owed()) == 0) { return; }
332 if (document.getElementById('no_change_label')) {
333 var m = document.getElementById('no_change_label').getAttribute('value');
334 document.getElementById('no_change_label').setAttribute(
336 m + document.getElementById('circStrings').getFormattedString('staff.circ.utils.billable.amount', [params.row.my.acp.barcode(), util.money.sanitize(bill.balance_owed())]) + ' '
338 document.getElementById('no_change_label').setAttribute('hidden','false');
340 if (document.getElementById('fine_tally')) {
341 var amount = Number( document.getElementById('fine_tally').getAttribute('amount') ) + Number( bill.balance_owed() );
342 document.getElementById('fine_tally').setAttribute('amount',amount);
343 document.getElementById('fine_tally').setAttribute(
345 document.getElementById('circStrings').getFormattedString('staff.circ.utils.fine_tally_text', [ util.money.sanitize( amount ) ])
347 document.getElementById('fine_tally').setAttribute('hidden','false');
351 obj.list.node.view.selection.select(0);
353 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
355 if (typeof obj.on_renew == 'function') {
358 if (typeof window.xulG == 'object' && typeof window.xulG.on_renew == 'function') {
359 window.xulG.on_renew(renew);
365 obj.error.standard_unexpected_error_alert('Error in circ/renew.js, renew_followup():', E);
366 if (typeof obj.on_failure == 'function') {
369 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
370 window.xulG.on_failure(E);
376 'on_renew' : function() {
377 this.controller.view.renew_barcode_entry_textbox.disabled = false;
378 this.controller.view.renew_barcode_entry_textbox.select();
379 this.controller.view.renew_barcode_entry_textbox.value = '';
380 this.controller.view.renew_barcode_entry_textbox.focus();
383 'on_failure' : function() {
384 this.controller.view.renew_barcode_entry_textbox.disabled = false;
385 this.controller.view.renew_barcode_entry_textbox.select();
386 this.controller.view.renew_barcode_entry_textbox.focus();
389 'spawn_copy_editor' : function() {
393 JSAN.use('util.functional');
395 var list = obj.selection_list;
397 list = util.functional.map_list(
404 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
410 dump('exiting circ.renew.js\n');