]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/circ/offline_in_house_use.js
seconds instead of milliseconds
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / circ / offline_in_house_use.js
1 function my_init() {
2         try {
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');
9
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); }
12                 }
13
14                 JSAN.use('util.list'); g.list = new util.list('checkout_list');
15                 g.list.init( {
16                         'columns' : [
17                                 { 
18                                         'id' : 'timestamp', 
19                                         'label' : 'Timestamp', 
20                                         'flex' : 1, 'primary' : false, 'hidden' : true, 
21                                         'render' : 'my.timestamp' 
22                                 },
23                                 { 
24                                         'id' : 'use_time', 
25                                         'label' : 'Use Time', 
26                                         'flex' : 1, 'primary' : false, 'hidden' : true, 
27                                         'render' : 'my.use_time' 
28                                 },
29                                 { 
30                                         'id' : 'type', 
31                                         'label' : 'Transaction Type', 
32                                         'flex' : 1, 'primary' : false, 'hidden' : true, 
33                                         'render' : 'my.type' 
34                                 },
35                                 {
36                                         'id' : 'count',
37                                         'label' : 'Count',
38                                         'flex' : 1, 'primary' : false, 'hidden' : false,
39                                         'render' : 'my.count'
40                                 },
41                                 { 
42                                         'id' : 'barcode', 
43                                         'label' : 'Item Barcode', 
44                                         'flex' : 2, 'primary' : true, 'hidden' : false, 
45                                         'render' : 'my.barcode' 
46                                 },
47                         ],
48                         'map_row_to_column' : function(row,col) {
49                                 // row contains { 'my' : { 'barcode' : xxx, 'duedate' : xxx } }
50                                 // col contains one of the objects listed above in columns
51
52                                 var my = row.my;
53                                 var value;
54                                 try {
55                                         value = eval( col.render );
56                                         if (typeof value == 'undefined') value = '';
57
58                                 } catch(E) {
59                                         JSAN.use('util.error'); var error = new util.error();
60                                         error.sdump('D_WARN','map_row_to_column: ' + E);
61                                         value = '???';
62                                 }
63                                 return value;
64                         }
65                 } );
66
67                 $('i_barcode').addEventListener('keypress',handle_keypress,false);
68                 $('enter').addEventListener('command',handle_enter,false);
69                 $('submit').addEventListener('command',next_patron,false);
70
71                 $('i_barcode').focus();
72
73                 var file = new util.file('offline_delta'); 
74                 if (file._file.exists()) { g.delta = file.get_object(); file.close(); } else { g.delta = 0; }
75
76         } catch(E) {
77                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
78                         "system administrator or software developer the following:\ncirc/offline_in_house_use.xul\n" + E + '\n';
79                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
80                 alert(err_msg);
81         }
82 }
83
84 function $(id) { return document.getElementById(id); }
85
86 function handle_keypress(ev) {
87         if ( (! ev.keyCode) || (ev.keyCode != 13) ) return;
88         switch(ev.target) {
89                 case $('i_barcode') : append_to_list(); break;
90                 default: break;
91         }
92 }
93
94 function handle_enter(ev) {
95         append_to_list();
96 }
97
98 function append_to_list() {
99
100         try {
101
102                 JSAN.use('util.date');
103
104                 var my = {};
105
106                 my.type = 'in_house_use';
107                 my.timestamp = parseInt( new Date().getTime() / 1000);
108                 my.use_time = util.date.formatted_date(new Date(),"%F %H:%M:%s");
109
110                 var i_barcode = $('i_barcode').value;
111                 if (! i_barcode) return; 
112                 my.barcode = i_barcode; 
113
114                 var count = $('count').value;
115                 if (!Number(count) || count < 1) count = 1;
116                 my.count = count;
117
118                 g.list.append( { 'row' : { 'my' : my } } );
119
120                 var x = $('i_barcode'); x.value = ''; x.focus();
121
122         } catch(E) {
123
124                 dump(E+'\n'); alert(E);
125
126         }
127 }
128
129 function next_patron() {
130         try {
131                 JSAN.use('util.file'); var file = new util.file('pending_xacts');
132                 var rows = g.list.dump_with_keys();
133                 for (var i = 0; i < rows.length; i++) {
134                         var row = rows[i]; row.delta = g.delta;
135                         file.append_object(row);
136                 }
137                 file.close();
138                 g.list.clear();
139                 
140                 var x;
141                 x = $('i_barcode'); x.value = ''; x.focus();
142
143         } catch(E) {
144                 dump(E+'\n'); alert(E);
145         }
146 }