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 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('util.list'); g.list = new util.list('checkout_list');
19 'label' : 'Timestamp',
20 'flex' : 1, 'primary' : false, 'hidden' : true,
21 'render' : 'my.timestamp'
24 'id' : 'checkout_time',
25 'label' : 'Check Out Time',
26 'flex' : 1, 'primary' : false, 'hidden' : true,
27 'render' : 'my.checkout_time'
31 'label' : 'Transaction Type',
32 'flex' : 1, 'primary' : false, 'hidden' : true,
37 'label' : 'Non-Cataloged?',
38 'flex' : 1, 'primary' : false, 'hidden' : true,
39 'render' : 'my.noncat'
43 'label' : 'Non-Cat Type ID',
44 'flex' : 1, 'primary' : false, 'hidden' : true,
45 'render' : 'my.noncat_type'
48 'id' : 'noncat_count',
50 'flex' : 1, 'primary' : false, 'hidden' : false,
51 'render' : 'my.noncat_count'
54 'id' : 'patron_barcode',
55 'label' : 'Patron Barcode',
56 'flex' : 1, 'primary' : false, 'hidden' : true,
57 'render' : 'my.patron_barcode'
61 'label' : 'Item Barcode',
62 'flex' : 2, 'primary' : true, 'hidden' : false,
63 'render' : 'my.barcode'
68 'flex' : 1, 'primary' : false, 'hidden' : false,
69 'render' : 'my.due_date'
72 'map_row_to_column' : function(row,col) {
73 // row contains { 'my' : { 'barcode' : xxx, 'duedate' : xxx } }
74 // col contains one of the objects listed above in columns
79 value = eval( col.render );
80 if (typeof value == 'undefined') value = '';
83 JSAN.use('util.error'); var error = new util.error();
84 error.sdump('D_WARN','map_row_to_column: ' + E);
91 JSAN.use('util.date');
92 var today = new Date();
93 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
94 todayPlus = util.date.formatted_date(todayPlus,"%F");
96 $('duedate').setAttribute('value',todayPlus);
98 $('p_barcode').addEventListener('keypress',handle_keypress,false);
99 $('p_barcode').focus();
101 $('i_barcode').addEventListener('keypress',handle_keypress,false);
103 $('duedate_menu').addEventListener('command',handle_duedate_menu,false);
105 $('submit').addEventListener('command',next_patron,false);
107 JSAN.use('util.widgets'); JSAN.use('util.file');
109 var file; var list_data; var ml;
111 file = new util.file('offline_cnct_list'); list_data = file.get_object(); file.close();
112 ml = util.widgets.make_menulist(
113 [ ['or choose a non-barcoded option...', ''] ].concat(list_data[0]),
116 ml.setAttribute('id','noncat_type_menu'); $('x_noncat_type').appendChild(ml);
120 var count = window.prompt('Enter the number of items:',1,ml.getAttribute('label'));
121 append_to_list('noncat',count);
128 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
129 "system administrator or software developer the following:\ncirc/offline_checkout.xul\n" + E + '\n';
130 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
135 function $(id) { return document.getElementById(id); }
137 function handle_keypress(ev) {
138 if ( (! ev.keyCode) || (ev.keyCode != 13) ) return;
140 case $('p_barcode') : $('i_barcode').focus(); break;
141 case $('i_barcode') : append_to_list('barcode'); break;
146 function handle_duedate_menu(ev) {
147 if (ev.target.value=='0') return;
148 JSAN.use('util.date');
149 var today = new Date();
150 var todayPlus = new Date();
151 todayPlus.setTime( today.getTime() + 24*60*60*1000*ev.target.value );
152 todayPlus = util.date.formatted_date(todayPlus,'%F');
153 $('duedate').setAttribute('value',todayPlus);
154 $('duedate').value = todayPlus;
157 function handle_barcode_menu(ev) {
160 function append_to_list(checkout_type,count) {
166 my.type = 'checkout';
167 my.timestamp = new Date().getTime();
168 my.checkout_time = util.date.formatted_date(new Date(),"%F %H:%M:%s");
170 var p_barcode = $('p_barcode').value;
172 alert('Please enter a patron barcode first.');
176 // Need to validate patron barcode against bad patron list
177 my.patron_barcode = p_barcode;
180 var due_date = $('duedate').value; // Need to validate this
181 my.due_date = due_date;
183 var i_barcode = $('i_barcode').value;
184 switch(checkout_type) {
186 if (! i_barcode) return;
188 var rows = g.list.dump_with_keys();
189 for (var i = 0; i < rows.length; i++) {
190 if (rows[i].barcode == i_barcode) {
191 alert('This barcode has already been scanned.');
196 my.barcode = i_barcode;
199 count = parseInt(count); if (! (count>0) ) {
200 alert("Please try again and enter a valid count.");
203 my.barcode = $('noncat_type_menu').getAttribute('label');
205 my.noncat_type = JSON2js($('noncat_type_menu').value)[0];
206 my.noncat_count = count;
208 default: alert("Please report that this happened."); break;
211 g.list.append( { 'row' : { 'my' : my } } );
213 var x = $('i_barcode'); x.value = ''; x.focus();
217 dump(E+'\n'); alert(E);
222 function next_patron() {
224 JSAN.use('util.file'); var file = new util.file('pending_xacts');
225 var rows = g.list.dump_with_keys();
226 for (var i = 0; i < rows.length; i++) {
228 if (row.noncat == 1) {
232 delete(row.noncat_type);
233 delete(row.noncat_count);
235 file.append_object(row);
241 x = $('i_barcode'); x.value = '';
242 x = $('p_barcode'); x.value = ''; x.focus();
245 dump(E+'\n'); alert(E);