]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/circ/offline_in_house_use.js
Improve Firefox/XULRunner Support
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / circ / offline_in_house_use.js
1 var offlineStrings;
2 var local_lock = false;
3
4 function my_init() {
5     try {
6         offlineStrings = document.getElementById('offlineStrings');
7
8         if (typeof JSAN == 'undefined') { throw(offlineStrings.getString('common.jsan.missing')); }
9         JSAN.errorLevel = "die"; // none, warn, or die
10         JSAN.addRepository('..');
11         JSAN.use('util.error'); g.error = new util.error();
12         g.error.sdump('D_TRACE','my_init() for offline_checkout.xul');
13
14         if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
15             try { window.xulG.set_tab_name(offlineStrings.getString('circ.standalone')); } catch(E) { alert(E); }
16         }
17
18         JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
19
20         JSAN.use('util.list'); g.list = new util.list('checkout_list');
21         JSAN.use('circ.util');
22         g.list.init( {
23             'columns' : circ.util.offline_inhouse_use_columns(),
24             'map_row_to_column' : circ.util.std_map_row_to_column(),
25         } );
26
27         function handle_lock(ev) {
28             if (!(ev.altKey || ev.ctrlKey || ev.metakey)) {
29                 if (!local_lock) {
30                     local_lock = true;
31                     xulG.lock();
32                 }
33             }
34         }
35         $('i_barcode').addEventListener('keypress',handle_lock,false);
36         $('i_barcode').addEventListener('keypress',handle_keypress,false);
37         $('enter').addEventListener('command',handle_enter,false);
38         $('submit').addEventListener('command',next_patron,false);
39
40         $('i_barcode').focus();
41
42         JSAN.use('util.file');
43         var file = new util.file('offline_delta'); 
44         if (file._file.exists()) { g.delta = file.get_object()[0]; file.close(); } else { g.delta = 0; }
45
46     } catch(E) {
47         var err_msg = offlineStrings.getFormattedString('common.exception', ["circ/offline_in_house_use.xul", E]);
48         try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
49         alert(err_msg);
50     }
51 }
52
53 function $(id) { return document.getElementById(id); }
54
55 function handle_keypress(ev) {
56     if ( (! ev.keyCode) || (ev.keyCode != 13) ) return;
57     switch(ev.target) {
58         case $('i_barcode') : handle_enter(); break;
59         default: break;
60     }
61 }
62
63 function handle_enter(ev) {
64     JSAN.use('util.barcode');
65     if ( ($('strict_i_barcode').checked) && (! util.barcode.check($('i_barcode').value)) ) {
66         var r = g.error.yns_alert(offlineStrings.getString('circ.bad_checkdigit'),offlineStrings.getString('circ.barcode.warning'),offlineStrings.getString('common.ok'),offlineStrings.getString('common.clear'),null,offlineStrings.getString('common.confirm'));
67         if (r == 1) {
68             setTimeout(
69                 function() {
70                     $('i_barcode').value = '';
71                     $('i_barcode').focus();
72                 },0
73             );
74         } else {
75             append_to_list();
76         }
77     } else {
78         append_to_list();
79     }
80 }
81
82 function append_to_list() {
83
84     try {
85
86         JSAN.use('util.date');
87
88         var my = {};
89
90         my.type = 'in_house_use';
91         my.timestamp = parseInt( new Date().getTime() / 1000) + g.delta;
92         /* I18N to-do: enable localized date formats */
93         my.use_time = util.date.formatted_date(new Date(),"%F %H:%M:%s");
94
95         var i_barcode = $('i_barcode').value;
96         if (! i_barcode) return; 
97         my.barcode = i_barcode; 
98
99         var count = $('count').value;
100         if (!Number(count) || count < 1) count = 1;
101         my.count = count;
102
103         g.list.append( { 'row' : { 'my' : my }, 'to_top' : true } );
104
105         var x = $('i_barcode'); x.value = ''; x.focus();
106
107         if (!local_lock) {
108             local_lock = true;
109             xulG.lock();
110         }
111
112     } catch(E) {
113
114         dump(E+'\n'); alert(E);
115
116     }
117 }
118
119 function next_patron() {
120     try {
121         JSAN.use('util.file'); var file = new util.file('pending_xacts');
122         var rows = g.list.dump_with_keys();
123         for (var i = 0; i < rows.length; i++) {
124             var row = rows[i]; row.delta = g.delta;
125             file.append_object(row);
126         }
127         file.close();
128         
129         if (local_lock) {
130             local_lock = false;
131             xulG.unlock();
132         }
133
134         if ($('print_receipt').checked) {
135             try {
136                 var params = {
137                     'template' : 'offline_inhouse_use',
138                     'printer_context' : 'offline',
139                     'callback' : function() {
140                         g.list.clear();
141                         var x = $('i_barcode'); x.value = ''; x.focus();
142                     }
143                 };
144                 g.list.print( params );
145             } catch(E) {
146                 g.error.sdump('D_ERROR','print: ' + E);
147                 alert('print: ' + E);
148             }
149         } else {
150             g.list.clear();
151             var x = $('i_barcode'); x.value = ''; x.focus();
152         }
153     } catch(E) {
154         dump(E+'\n'); alert(E);
155     }
156 }