2 var local_lock = false;
6 offlineStrings = $('offlineStrings');
7 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
8 JSAN.errorLevel = "die"; // none, warn, or die
9 JSAN.addRepository('..');
10 JSAN.use('util.error'); g.error = new util.error();
11 g.error.sdump('D_TRACE','my_init() for offline_renew.xul');
13 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
14 try { window.xulG.set_tab_name('Standalone'); } catch(E) { alert(E); }
17 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
19 JSAN.use('util.list'); g.list = new util.list('checkout_list');
20 JSAN.use('circ.util');
22 'columns' : circ.util.offline_renew_columns(),
23 'map_row_to_column' : circ.util.std_map_row_to_column(),
26 JSAN.use('util.date');
27 var today = new Date();
28 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
29 todayPlus = util.date.formatted_date(todayPlus,"%F");
31 function handle_lock(ev) {
32 if (!(ev.altKey || ev.ctrlKey || ev.metakey)) {
40 $('duedate').setAttribute('value',todayPlus);
41 $('duedate').addEventListener('change',check_date,false);
43 $('p_barcode').addEventListener('keypress',handle_lock,false);
44 $('p_barcode').addEventListener('change',test_patron,false);
46 $('p_barcode').addEventListener('keypress',handle_keypress,false);
47 $('p_barcode').focus();
49 $('i_barcode').addEventListener('keypress',handle_lock,false);
50 $('i_barcode').addEventListener('keypress',handle_keypress,false);
51 $('enter').addEventListener('command',handle_enter,false);
53 $('duedate_menu').addEventListener('command',handle_duedate_menu,false);
55 $('submit').addEventListener('command',next_patron,false);
56 $('cancel').addEventListener('command',function(){next_patron('cancel');},false);
58 JSAN.use('util.file');
59 var file = new util.file('offline_delta');
60 if (file._file.exists()) { g.delta = file.get_object()[0]; file.close(); } else { g.delta = 0; }
63 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
64 "system administrator or software developer the following:\ncirc/offline_renew.xul\n" + E + '\n';
65 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
70 function $(id) { return document.getElementById(id); }
72 function test_patron(ev) {
74 var barcode = ev.target.value;
75 JSAN.use('util.barcode');
76 if ( ($('strict_p_barcode').checked) && (! util.barcode.check(barcode)) ) {
77 var r = g.error.yns_alert('This barcode has a bad checkdigit.','Barcode Warning','Ok','Clear',null,'Check here to confirm this message');
89 if (g.data.bad_patrons[barcode]) {
90 var msg = 'Warning: As of ' + g.data.bad_patrons_date.substr(0,15) + ', this barcode (' + barcode + ') was flagged ';
91 switch(g.data.bad_patrons[barcode]) {
92 case 'L' : msg += 'Lost'; break;
93 case 'E' : msg += 'Expired'; break;
94 case 'B' : msg += 'Barred'; break;
95 case 'D' : msg += 'Blocked'; break;
96 default : msg += ' with an unknown code: ' + g.data.bad_patrons[barcode]; break;
98 var r = g.error.yns_alert(msg,'Barcode Warning','Ok','Clear',null,'Check here to confirm this message');
102 ev.target.value = '';
113 function handle_keypress(ev) {
114 if ( (! ev.keyCode) || (ev.keyCode != 13) ) return;
116 case $('p_barcode') : setTimeout( function() { $('i_barcode').focus(); },0 ); break;
117 case $('i_barcode') : handle_enter(); break;
122 function handle_enter(ev) {
123 JSAN.use('util.barcode');
124 if ( ($('strict_i_barcode').checked) && (! util.barcode.check($('i_barcode').value)) ) {
125 var r = g.error.yns_alert('This barcode has a bad checkdigit.','Barcode Warning','Ok','Clear',null,'Check here to confirm this message');
129 ev.target.value = '';
134 append_to_list('barcode');
137 append_to_list('barcode');
141 function handle_duedate_menu(ev) {
142 if (ev.target.value=='0') return;
143 JSAN.use('util.date');
144 var today = new Date();
145 var todayPlus = new Date();
146 todayPlus.setTime( today.getTime() + 24*60*60*1000*ev.target.value );
147 todayPlus = util.date.formatted_date(todayPlus,'%F');
148 $('duedate').setAttribute('value',todayPlus);
149 $('duedate').value = todayPlus;
152 function check_date(ev) {
153 JSAN.use('util.date');
155 if (! util.date.check('YYYY-MM-DD',ev.target.value) ) { throw('Invalid Date'); }
156 if (util.date.check_past('YYYY-MM-DD',ev.target.value) ) { throw('Due date needs to be after today.'); }
157 if ( util.date.formatted_date(new Date(),'%F') == ev.target.value) { throw('Due date needs to be after today.'); }
160 var today = new Date();
161 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
162 todayPlus = util.date.formatted_date(todayPlus,"%F");
163 ev.target.value = todayPlus;
167 function append_to_list(checkout_type,count) {
174 my.timestamp = parseInt( new Date().getTime() / 1000) + g.delta;
175 my.checkout_time = util.date.formatted_date(new Date(),"%F %H:%M:%s");
177 var p_barcode = $('p_barcode').value;
179 /* Not strictly necessary for a renewal
180 alert('Please enter a patron barcode first.');
185 // Need to validate patron barcode against bad patron list
186 my.patron_barcode = p_barcode;
189 var due_date = $('duedate').value; // Need to validate this
190 my.due_date = due_date;
192 var i_barcode = $('i_barcode').value;
193 switch(checkout_type) {
195 if (! i_barcode) return;
197 var rows = g.list.dump_with_keys();
198 for (var i = 0; i < rows.length; i++) {
199 if (rows[i].barcode == i_barcode) {
200 g.error.yns_alert('This barcode has already been scanned.','Duplicate Scan','Ok',null,null,'Check here to confirm this message');
205 my.barcode = i_barcode;
207 default: alert("Please report that this happened."); break;
210 g.list.append( { 'row' : { 'my' : my }, 'to_top' : true } );
212 var x = $('i_barcode'); x.value = ''; x.focus();
221 dump(E+'\n'); alert(E);
226 function next_patron(cancel) {
229 if (cancel!='cancel') {
230 JSAN.use('util.file'); var file = new util.file('pending_xacts');
231 var rows = g.list.dump_with_keys();
232 for (var i = 0; i < rows.length; i++) {
233 var row = rows[i]; row.delta = g.delta;
234 if (row.patron_barcode == '') {
235 delete(row.patron_barcode);
237 file.append_object(row);
246 if ($('print_receipt').checked) {
249 'patron_barcode' : $('p_barcode').value,
250 'template' : 'offline_renew',
251 'printer_context' : 'offline',
252 'callback' : function() {
254 var x = $('i_barcode'); x.value = '';
255 x = $('p_barcode'); x.value = ''; x.focus();
258 g.list.print( params );
260 g.error.sdump('D_ERROR','print: ' + E);
261 alert('print: ' + E);
265 var x = $('i_barcode'); x.value = '';
266 x = $('p_barcode'); x.value = ''; x.focus();
270 dump(E+'\n'); alert(E);