]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkin.js
receipt printing
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / circ / checkin.js
1 dump('entering circ.checkin.js\n');
2
3 if (typeof circ == 'undefined') circ = {};
4 circ.checkin = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8         JSAN.use('util.date');
9         this.OpenILS = {}; JSAN.use('OpenILS.data'); this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
10 }
11
12 circ.checkin.prototype = {
13
14         'init' : function( params ) {
15
16                 var obj = this;
17
18                 obj.session = params['session'];
19
20                 JSAN.use('circ.util');
21                 var columns = circ.util.columns( 
22                         { 
23                                 'barcode' : { 'hidden' : false },
24                                 'title' : { 'hidden' : false },
25                                 'location' : { 'hidden' : false },
26                                 'call_number' : { 'hidden' : false },
27                                 'status' : { 'hidden' : false },
28                                 'route_to' : { 'hidden' : false },
29                         } 
30                 );
31
32                 JSAN.use('util.list'); obj.list = new util.list('checkin_list');
33                 obj.list.init(
34                         {
35                                 'columns' : columns,
36                                 'map_row_to_column' : circ.util.std_map_row_to_column(),
37                         }
38                 );
39                 
40                 JSAN.use('util.controller'); obj.controller = new util.controller();
41                 obj.controller.init(
42                         {
43                                 'control_map' : {
44                                         'checkin_barcode_entry_textbox' : [
45                                                 ['keypress'],
46                                                 function(ev) {
47                                                         if (ev.keyCode && ev.keyCode == 13) {
48                                                                 obj.checkin();
49                                                         }
50                                                 }
51                                         ],
52                                         'checkin_effective_date_label' : [
53                                                 ['render'],
54                                                 function(e) {
55                                                         return function() {
56                                                                 obj.controller.view.checkin_effective_date_textbox.value =
57                                                                         util.date.formatted_date(new Date(),'%F');
58                                                         };
59                                                 }
60                                         ],
61                                         'checkin_effective_date_textbox' : [
62                                                 ['change'],
63                                                 function(ev) {
64                                                         if (ev.target.nodeName == 'textbox') {
65                                                                 try {
66                                                                         var flag = false;
67                                                                         var darray = ev.target.value.split('-');
68                                                                         var year = darray[0]; var month = darray[1]; var day = darray[2]; 
69                                                                         if ( (!year) || (year.length != 4) || (!parseInt(year)) ) flag = true;
70                                                                         if ( (!month) || (month.length !=2) || (!parseInt(month)) ) flag = true;
71                                                                         if ( (!day) || (day.length !=2) || (!parseInt(day)) ) flag = true;
72                                                                         if (flag) {
73                                                                                 throw('invalid date format');
74                                                                         }
75                                                                         var d = new Date( year, month - 1, day );
76                                                                         if (d.toString() == 'Invalid Date') throw('Invalid Date');
77                                                                         if ( d > new Date() ) throw('Future Date');
78                                                                         ev.target.value = util.date.formatted_date(d,'%F');
79
80                                                                 } catch(E) {
81                                                                         dump('checkin:effective_date: ' + E + '\n');
82                                                                         ev.target.value = util.date.formatted_date(new Date(),'%F');
83                                                                 }
84                                                         }
85                                                 }
86                                         ],
87                                         'cmd_broken' : [
88                                                 ['command'],
89                                                 function() { alert('Not Yet Implemented'); }
90                                         ],
91                                         'cmd_checkin_submit_barcode' : [
92                                                 ['command'],
93                                                 function() {
94                                                         obj.checkin();
95                                                 }
96                                         ],
97                                         'cmd_checkin_print' : [
98                                                 ['command'],
99                                                 function() {
100                                                         try {
101                                                         dump( js2JSON( obj.list.dump() ) + '\n' );
102                                                         obj.OpenILS.data.stash_retrieve();
103                                                         var lib = obj.OpenILS.data.hash.aou[ obj.OpenILS.data.list.au[0].ws_ou() ];
104                                                         lib.children(null);
105                                                         var p = { 
106                                                                 'lib' : lib,
107                                                                 'staff' : obj.OpenILS.data.list.au[0],
108                                                                 'header' : obj.OpenILS.data.print_list_templates.checkin.header,
109                                                                 'line_item' : obj.OpenILS.data.print_list_templates.checkin.line_item,
110                                                                 'footer' : obj.OpenILS.data.print_list_templates.checkin.footer,
111                                                                 'type' : obj.OpenILS.data.print_list_templates.checkin.type,
112                                                                 'list' : obj.list.dump(),
113                                                         };
114                                                         JSAN.use('util.print'); var print = new util.print();
115                                                         print.tree_list( p );
116                                                         } catch(E) {
117                                                                 alert(E); 
118                                                         }
119                                                 }
120                                         ],
121                                         'cmd_checkin_reprint' : [
122                                                 ['command'],
123                                                 function() {
124                                                 }
125                                         ],
126                                         'cmd_checkin_done' : [
127                                                 ['command'],
128                                                 function() {
129                                                 }
130                                         ],
131                                 }
132                         }
133                 );
134                 this.controller.render();
135                 this.controller.view.checkin_barcode_entry_textbox.focus();
136
137         },
138
139         'checkin' : function() {
140                 var obj = this;
141                 try {
142                         var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
143                         var backdate = obj.controller.view.checkin_effective_date_textbox.value;
144                         JSAN.use('circ.util');
145                         var checkin = circ.util.checkin_via_barcode(
146                                 obj.session, barcode, backdate
147                         );
148                         obj.list.append(
149                                 {
150                                         'row' : {
151                                                 'my' : {
152                                                         'circ' : checkin.circ,
153                                                         'mvr' : checkin.record,
154                                                         'acp' : checkin.copy,
155                                                         'status' : checkin.status,
156                                                         'route_to' : checkin.route_to,
157                                                         'message' : checkin.message,
158                                                 }
159                                         }
160                                 //I could override map_row_to_column here
161                                 }
162                         );
163
164                         JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
165
166                         if (typeof obj.on_checkin == 'function') {
167                                 obj.on_checkin(checkin);
168                         }
169                         if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
170                                 obj.error.sdump('D_CIRC','circ.checkin: Calling external .on_checkin()\n');
171                                 window.xulG.on_checkin(checkin);
172                         } else {
173                                 obj.error.sdump('D_CIRC','circ.checkin: No external .on_checkin()\n');
174                         }
175
176                 } catch(E) {
177                         alert('FIXME: need special alert and error handling\n'
178                                 + js2JSON(E));
179                         if (typeof obj.on_failure == 'function') {
180                                 obj.on_failure(E);
181                         }
182                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
183                                 obj.error.sdump('D_CIRC','circ.checkin: Calling external .on_failure()\n');
184                                 window.xulG.on_failure(E);
185                         } else {
186                                 obj.error.sdump('D_CIRC','circ.checkin: No external .on_failure()\n');
187                         }
188                 }
189
190         },
191
192         'on_checkin' : function() {
193                 this.controller.view.checkin_barcode_entry_textbox.value = '';
194                 this.controller.view.checkin_barcode_entry_textbox.focus();
195         },
196
197         'on_failure' : function() {
198                 this.controller.view.checkin_barcode_entry_textbox.select();
199                 this.controller.view.checkin_barcode_entry_textbox.focus();
200         }
201 }
202
203 dump('exiting circ.checkin.js\n');