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