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_checkout.xul');
10 JSAN.use('util.widgets'); JSAN.use('util.file');
12 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
13 try { window.xulG.set_tab_name('Standalone'); } catch(E) { alert(E); }
16 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
18 JSAN.use('util.list'); g.list = new util.list('checkout_list');
19 JSAN.use('circ.util');
21 'columns' : circ.util.offline_checkout_columns(),
22 'map_row_to_column' : circ.util.std_map_row_to_column(),
25 JSAN.use('util.date');
26 var today = new Date();
27 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
28 todayPlus = util.date.formatted_date(todayPlus,"%F");
30 $('duedate').setAttribute('value',todayPlus);
31 $('duedate').addEventListener('change',check_date,false);
33 $('p_barcode').addEventListener('change',test_patron,false);
35 $('p_barcode').addEventListener('keypress',handle_keypress,false);
36 $('p_barcode').focus();
38 $('i_barcode').addEventListener('keypress',handle_keypress,false);
39 $('enter').addEventListener('command',handle_enter,false);
41 $('duedate_menu').addEventListener('command',handle_duedate_menu,false);
43 $('submit').addEventListener('command',function(ev){
44 save_xacts(); next_patron();
46 $('cancel').addEventListener('command',function(ev){
47 next_patron('cancel');
50 var file; var list_data; var ml;
52 file = new util.file('offline_cnct_list');
53 if (file._file.exists()) {
54 list_data = file.get_object(); file.close();
55 ml = util.widgets.make_menulist(
56 [ ['or choose a non-barcoded option...', ''] ].concat(list_data[0]),
59 ml.setAttribute('id','noncat_type_menu'); $('x_noncat_type').appendChild(ml);
63 var count = window.prompt('Enter the number of items:',1,ml.getAttribute('label'));
64 append_to_list('noncat',count);
70 alert('WARNING: The non-barcode types have not been downloaded from the server. You should log in to retrieve these.');
73 var file = new util.file('offline_delta');
74 if (file._file.exists()) { g.delta = file.get_object()[0]; file.close(); } else { g.delta = 0; }
77 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
78 "system administrator or software developer the following:\ncirc/offline_checkout.xul\n" + E + '\n';
79 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
84 function $(id) { return document.getElementById(id); }
86 function test_patron(ev) {
88 var barcode = ev.target.value;
89 JSAN.use('util.barcode');
90 if ( ($('strict_p_barcode').checked) && (! util.barcode.check(barcode)) ) {
91 var r = g.error.yns_alert('This barcode has a bad checkdigit.','Barcode Warning','Ok','Clear',null,'Check here to confirm this message');
102 if (g.data.bad_patrons[barcode]) {
103 var msg = 'Warning: As of ' + g.data.bad_patrons_date.substr(0,15) + ', this barcode (' + barcode + ') was flagged ';
104 switch(g.data.bad_patrons[barcode]) {
105 case 'L' : msg += 'Lost'; break;
106 case 'E' : msg += 'Expired'; break;
107 case 'B' : msg += 'Barred'; break;
108 case 'D' : msg += 'Blocked'; break;
109 default : msg += ' with an unknown code: ' + g.data.bad_patrons[barcode]; break;
111 var r = g.error.yns_alert(msg,'Barcode Warning','Ok','Clear',null,'Check here to confirm this message');
115 ev.target.value = '';
126 function check_date(ev) {
127 JSAN.use('util.date');
129 if (! util.date.check('YYYY-MM-DD',ev.target.value) ) { throw('Invalid Date'); }
130 if (util.date.check_past('YYYY-MM-DD',ev.target.value) ) { throw('Due date needs to be after today.'); }
131 if ( util.date.formatted_date(new Date(),'%F') == ev.target.value) { throw('Due date needs to be after today.'); }
134 var today = new Date();
135 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
136 todayPlus = util.date.formatted_date(todayPlus,"%F");
137 ev.target.value = todayPlus;
141 function handle_keypress(ev) {
142 if ( (! ev.keyCode) || (ev.keyCode != 13) ) return;
144 case $('p_barcode') : /*$('p_barcode').disabled = true;*/ setTimeout( function() { $('i_barcode').focus(); },0 ); break;
145 case $('i_barcode') : handle_enter(); break;
150 function handle_enter(ev) {
151 JSAN.use('util.barcode');
152 if ( ($('strict_i_barcode').checked) && (! util.barcode.check($('i_barcode').value)) ) {
153 var r = g.error.yns_alert('This barcode has a bad checkdigit.','Barcode Warning','Ok','Clear',null,'Check here to confirm this message');
157 $('i_barcode').value = '';
158 $('i_barcode').focus();
162 append_to_list('barcode');
165 append_to_list('barcode');
169 function handle_duedate_menu(ev) {
170 if (ev.target.value=='0') return;
171 JSAN.use('util.date');
172 var today = new Date();
173 var todayPlus = new Date();
174 todayPlus.setTime( today.getTime() + 24*60*60*1000*ev.target.value );
175 todayPlus = util.date.formatted_date(todayPlus,'%F');
176 $('duedate').setAttribute('value',todayPlus);
177 $('duedate').value = todayPlus;
180 function append_to_list(checkout_type,count) {
186 my.type = 'checkout';
187 my.timestamp = parseInt( new Date().getTime() / 1000) + g.delta;
188 my.checkout_time = util.date.formatted_date(new Date(),"%F %H:%M:%s");
190 var p_barcode = $('p_barcode').value;
192 g.error.yns_alert('Please enter a patron barcode first.','Required Field','Ok',null,null,'Check here to confirm this message');
196 // Need to validate patron barcode against bad patron list
197 my.patron_barcode = p_barcode;
200 var due_date = $('duedate').value; // Need to validate this
201 my.due_date = due_date;
203 var i_barcode = $('i_barcode').value;
204 switch(checkout_type) {
206 if (! i_barcode) return;
208 var rows = g.list.dump_with_keys();
209 for (var i = 0; i < rows.length; i++) {
210 if (rows[i].barcode == i_barcode) {
211 g.error.yns_alert('This barcode has already been scanned.','Duplicate Scan','Ok',null,null,'Check here to confirm this message');
216 my.barcode = i_barcode;
219 count = parseInt(count); if (! (count>0) ) {
220 g.error.yns_alert("Please try again and enter a valid count.",'Required Value','Ok',null,null,'Check here to confirm this message');
223 my.barcode = $('noncat_type_menu').getAttribute('label');
225 my.noncat_type = JSON2js($('noncat_type_menu').value)[0];
226 my.noncat_count = count;
228 default: alert("Please report that this happened."); break;
231 g.list.append( { 'row' : { 'my' : my } } );
233 var x = $('i_barcode'); x.value = ''; x.focus();
237 dump(E+'\n'); alert(E);
243 function save_xacts() {
244 JSAN.use('util.file'); var file = new util.file('pending_xacts');
245 var rows = g.list.dump_with_keys();
246 for (var i = 0; i < rows.length; i++) {
247 var row = rows[i]; row.delta = g.delta;
248 if (row.noncat == 1) {
252 delete(row.noncat_type);
253 delete(row.noncat_count);
255 file.append_object(row);
260 function next_patron(cancel) {
263 if ($('print_receipt').checked && (cancel!='cancel')) {
266 'patron_barcode' : $('p_barcode').value,
267 'header' : g.data.print_list_templates.offline_checkout.header,
268 'line_item' : g.data.print_list_templates.offline_checkout.line_item,
269 'footer' : g.data.print_list_templates.offline_checkout.footer,
270 'type' : g.data.print_list_templates.offline_checkout.type,
271 'list' : g.list.dump(),
273 JSAN.use('util.print'); var print = new util.print();
274 print.tree_list( params );
276 g.error.sdump('D_ERROR','print: ' + E);
277 alert('print: ' + E);
284 x = $('i_barcode'); x.value = '';
285 x = $('p_barcode'); x.value = '';
286 x.setAttribute('disabled','false'); x.disabled = false;
290 dump(E+'\n'); alert(E);