3 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
4 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
5 JSAN.errorLevel = "die"; // none, warn, or die
6 JSAN.addRepository('..');
7 JSAN.use('util.error'); g.error = new util.error();
8 g.error.sdump('D_TRACE','my_init() for offline_renew.xul');
10 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
11 try { window.xulG.set_tab_name('Standalone'); } catch(E) { alert(E); }
14 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
16 JSAN.use('util.list'); g.list = new util.list('checkout_list');
17 JSAN.use('circ.util');
19 'columns' : circ.util.offline_renew_columns(),
20 'map_row_to_column' : circ.util.std_map_row_to_column(),
23 JSAN.use('util.date');
24 var today = new Date();
25 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
26 todayPlus = util.date.formatted_date(todayPlus,"%F");
28 $('duedate').setAttribute('value',todayPlus);
29 $('duedate').addEventListener('change',check_date,false);
31 $('p_barcode').addEventListener('change',test_patron,false);
33 $('p_barcode').addEventListener('keypress',handle_keypress,false);
34 $('p_barcode').focus();
36 $('i_barcode').addEventListener('keypress',handle_keypress,false);
37 $('enter').addEventListener('command',handle_enter,false);
39 $('duedate_menu').addEventListener('command',handle_duedate_menu,false);
41 $('submit').addEventListener('command',next_patron,false);
42 $('cancel').addEventListener('command',function(){next_patron('cancel');},false);
44 JSAN.use('util.file');
45 var file = new util.file('offline_delta');
46 if (file._file.exists()) { g.delta = file.get_object()[0]; file.close(); } else { g.delta = 0; }
49 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
50 "system administrator or software developer the following:\ncirc/offline_renew.xul\n" + E + '\n';
51 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
56 function $(id) { return document.getElementById(id); }
58 function test_patron(ev) {
60 var barcode = ev.target.value;
61 JSAN.use('util.barcode');
62 if ( ($('strict_p_barcode').checked) && (! util.barcode.check(barcode)) ) {
63 var r = g.error.yns_alert('This barcode has a bad checkdigit.','Barcode Warning','Ok','Clear',null,'Check here to confirm this message');
75 if (g.data.bad_patrons[barcode]) {
76 var msg = 'Warning: As of ' + g.data.bad_patrons_date.substr(0,15) + ', this barcode (' + barcode + ') was flagged ';
77 switch(g.data.bad_patrons[barcode]) {
78 case 'L' : msg += 'Lost'; break;
79 case 'E' : msg += 'Expired'; break;
80 case 'B' : msg += 'Barred'; break;
81 case 'D' : msg += 'Blocked'; break;
82 default : msg += ' with an unknown code: ' + g.data.bad_patrons[barcode]; break;
84 var r = g.error.yns_alert(msg,'Barcode Warning','Ok','Clear',null,'Check here to confirm this message');
99 function handle_keypress(ev) {
100 if ( (! ev.keyCode) || (ev.keyCode != 13) ) return;
102 case $('p_barcode') : setTimeout( function() { $('i_barcode').focus(); },0 ); break;
103 case $('i_barcode') : handle_enter(); break;
108 function handle_enter(ev) {
109 JSAN.use('util.barcode');
110 if ( ($('strict_i_barcode').checked) && (! util.barcode.check($('i_barcode').value)) ) {
111 var r = g.error.yns_alert('This barcode has a bad checkdigit.','Barcode Warning','Ok','Clear',null,'Check here to confirm this message');
115 ev.target.value = '';
120 append_to_list('barcode');
123 append_to_list('barcode');
127 function handle_duedate_menu(ev) {
128 if (ev.target.value=='0') return;
129 JSAN.use('util.date');
130 var today = new Date();
131 var todayPlus = new Date();
132 todayPlus.setTime( today.getTime() + 24*60*60*1000*ev.target.value );
133 todayPlus = util.date.formatted_date(todayPlus,'%F');
134 $('duedate').setAttribute('value',todayPlus);
135 $('duedate').value = todayPlus;
138 function check_date(ev) {
139 JSAN.use('util.date');
141 if (! util.date.check('YYYY-MM-DD',ev.target.value) ) { throw('Invalid Date'); }
142 if (util.date.check_past('YYYY-MM-DD',ev.target.value) ) { throw('Due date needs to be after today.'); }
143 if ( util.date.formatted_date(new Date(),'%F') == ev.target.value) { throw('Due date needs to be after today.'); }
146 var today = new Date();
147 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
148 todayPlus = util.date.formatted_date(todayPlus,"%F");
149 ev.target.value = todayPlus;
153 function append_to_list(checkout_type,count) {
160 my.timestamp = parseInt( new Date().getTime() / 1000) + g.delta;
161 my.checkout_time = util.date.formatted_date(new Date(),"%F %H:%M:%s");
163 var p_barcode = $('p_barcode').value;
165 /* Not strictly necessary for a renewal
166 alert('Please enter a patron barcode first.');
171 // Need to validate patron barcode against bad patron list
172 my.patron_barcode = p_barcode;
175 var due_date = $('duedate').value; // Need to validate this
176 my.due_date = due_date;
178 var i_barcode = $('i_barcode').value;
179 switch(checkout_type) {
181 if (! i_barcode) return;
183 var rows = g.list.dump_with_keys();
184 for (var i = 0; i < rows.length; i++) {
185 if (rows[i].barcode == i_barcode) {
186 g.error.yns_alert('This barcode has already been scanned.','Duplicate Scan','Ok',null,null,'Check here to confirm this message');
191 my.barcode = i_barcode;
193 default: alert("Please report that this happened."); break;
196 g.list.append( { 'row' : { 'my' : my }, 'to_top' : true } );
198 var x = $('i_barcode'); x.value = ''; x.focus();
202 dump(E+'\n'); alert(E);
207 function next_patron(cancel) {
210 if (cancel!='cancel') {
211 JSAN.use('util.file'); var file = new util.file('pending_xacts');
212 var rows = g.list.dump_with_keys();
213 for (var i = 0; i < rows.length; i++) {
214 var row = rows[i]; row.delta = g.delta;
215 if (row.patron_barcode == '') {
216 delete(row.patron_barcode);
218 file.append_object(row);
222 if ($('print_receipt').checked) {
225 'patron_barcode' : $('p_barcode').value,
226 'header' : g.data.print_list_templates.offline_renew.header,
227 'line_item' : g.data.print_list_templates.offline_renew.line_item,
228 'footer' : g.data.print_list_templates.offline_renew.footer,
229 'type' : g.data.print_list_templates.offline_renew.type,
230 'list' : g.list.dump(),
232 JSAN.use('util.print'); var print = new util.print();
233 print.tree_list( params );
235 g.error.sdump('D_ERROR','print: ' + E);
236 alert('print: ' + E);
244 x = $('i_barcode'); x.value = '';
245 x = $('p_barcode'); x.value = ''; x.focus();
248 dump(E+'\n'); alert(E);