]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkin.js
visual distinction between checkin/backdated checkin/in-house use/copy status
[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         this.data = this.OpenILS.data;
11 }
12
13 circ.checkin.prototype = {
14
15         'selection_list' : [],
16
17         'init' : function( params ) {
18
19                 var obj = this;
20
21                 JSAN.use('circ.util');
22                 var columns = circ.util.columns( 
23                         { 
24                                 'barcode' : { 'hidden' : false },
25                                 'title' : { 'hidden' : false },
26                                 'location' : { 'hidden' : false },
27                                 'call_number' : { 'hidden' : false },
28                                 'status' : { 'hidden' : false },
29                                 'route_to' : { 'hidden' : false },
30                                 'alert_message' : { 'hidden' : false },
31                         } 
32                 );
33
34                 JSAN.use('util.list'); obj.list = new util.list('checkin_list');
35                 obj.list.init(
36                         {
37                                 'columns' : columns,
38                                 'map_row_to_column' : circ.util.std_map_row_to_column(),
39                                 'on_select' : function(ev) {
40                                         try {
41                                                 JSAN.use('util.functional');
42                                                 var sel = obj.list.retrieve_selection();
43                                                 obj.selection_list = util.functional.map_list(
44                                                         sel,
45                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
46                                                 );
47                                                 obj.error.sdump('D_TRACE', 'circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
48                                                 if (obj.selection_list.length == 0) {
49                                                         obj.controller.view.sel_edit.setAttribute('disabled','true');
50                                                         obj.controller.view.sel_opac.setAttribute('disabled','true');
51                                                         obj.controller.view.sel_patron.setAttribute('disabled','true');
52                                                         obj.controller.view.sel_bucket.setAttribute('disabled','true');
53                                                         obj.controller.view.sel_spine.setAttribute('disabled','true');
54                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
55                                                 } else {
56                                                         obj.controller.view.sel_edit.setAttribute('disabled','false');
57                                                         obj.controller.view.sel_opac.setAttribute('disabled','false');
58                                                         obj.controller.view.sel_patron.setAttribute('disabled','false');
59                                                         obj.controller.view.sel_bucket.setAttribute('disabled','false');
60                                                         obj.controller.view.sel_spine.setAttribute('disabled','false');
61                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
62                                                 }
63                                         } catch(E) {
64                                                 alert('FIXME: ' + E);
65                                         }
66                                 },
67
68                         }
69                 );
70                 
71                 JSAN.use('util.controller'); obj.controller = new util.controller();
72                 obj.controller.init(
73                         {
74                                 'control_map' : {
75                                         'sel_edit' : [
76                                                 ['command'],
77                                                 function() {
78                                                         try {
79                                                                 obj.spawn_copy_editor();
80                                                         } catch(E) {
81                                                                 alert(E);
82                                                         }
83                                                 }
84                                         ],
85                                         'sel_spine' : [
86                                                 ['command'],
87                                                 function() {
88                                                         JSAN.use('cat.util');
89                                                         cat.util.spawn_spine_editor(obj.selection_list);
90                                                 }
91                                         ],
92                                         'sel_opac' : [
93                                                 ['command'],
94                                                 function() {
95                                                         JSAN.use('cat.util');
96                                                         cat.util.show_in_opac(obj.selection_list);
97                                                 }
98                                         ],
99                                         'sel_transit_abort' : [
100                                                 ['command'],
101                                                 function() {
102                                                         JSAN.use('circ.util');
103                                                         circ.util.abort_transits(obj.selection_list);
104                                                 }
105                                         ],
106                                         'sel_patron' : [
107                                                 ['command'],
108                                                 function() {
109                                                         var count = 5;
110                                                         JSAN.use('circ.util');
111                                                         circ.util.show_last_few_circs(obj.selection_list,count);
112                                                 }
113                                         ],
114                                         'sel_bucket' : [
115                                                 ['command'],
116                                                 function() {
117                                                         JSAN.use('cat.util');
118                                                         cat.util.add_copies_to_bucket(obj.selection_list);
119                                                 }
120                                         ],
121                                         'checkin_barcode_entry_textbox' : [
122                                                 ['keypress'],
123                                                 function(ev) {
124                                                         if (ev.keyCode && ev.keyCode == 13) {
125                                                                 obj.checkin();
126                                                         }
127                                                 }
128                                         ],
129                                         'checkin_effective_date_label' : [
130                                                 ['render'],
131                                                 function(e) {
132                                                         return function() {
133                                                                 obj.controller.view.checkin_effective_date_textbox.value =
134                                                                         util.date.formatted_date(new Date(),'%F');
135                                                         };
136                                                 }
137                                         ],
138                                         'checkin_effective_date_textbox' : [
139                                                 ['change'],
140                                                 function(ev) {
141                                                         if (ev.target.nodeName == 'textbox') {
142                                                                 try {
143                                                                         var flag = false;
144                                                                         var darray = ev.target.value.split('-');
145                                                                         var year = darray[0]; var month = darray[1]; var day = darray[2]; 
146                                                                         if ( (!year) || (year.length != 4) || (!parseInt(year)) ) flag = true;
147                                                                         if ( (!month) || (month.length !=2) || (!parseInt(month)) ) flag = true;
148                                                                         if ( (!day) || (day.length !=2) || (!parseInt(day)) ) flag = true;
149                                                                         if (flag) {
150                                                                                 throw('invalid date format');
151                                                                         }
152                                                                         var d = new Date( year, month - 1, day );
153                                                                         if (d.toString() == 'Invalid Date') throw('Invalid Date');
154                                                                         if ( d > new Date() ) throw('Future Date');
155                                                                         ev.target.value = util.date.formatted_date(d,'%F');
156                                                                         var x = document.getElementById('background');
157                                                                         if (x) {
158                                                                                 if ( ev.target.value == util.date.formatted_date(new Date(),'%F') ) {
159                                                                                         x.setAttribute('style','background-color: green');
160                                                                                 } else {
161                                                                                         x.setAttribute('style','background-color: red');
162                                                                                 }
163                                                                         }
164
165                                                                 } catch(E) {
166                                                                         dump('checkin:effective_date: ' + E + '\n');
167                                                                         ev.target.value = util.date.formatted_date(new Date(),'%F');
168                                                                 }
169                                                         }
170                                                 }
171                                         ],
172                                         'cmd_broken' : [
173                                                 ['command'],
174                                                 function() { alert('Not Yet Implemented'); }
175                                         ],
176                                         'cmd_checkin_submit_barcode' : [
177                                                 ['command'],
178                                                 function() {
179                                                         obj.checkin();
180                                                 }
181                                         ],
182                                         'cmd_checkin_print' : [
183                                                 ['command'],
184                                                 function() {
185                                                         try {
186                                                         dump( js2JSON( obj.list.dump() ) + '\n' );
187                                                         obj.OpenILS.data.stash_retrieve();
188                                                         var lib = obj.OpenILS.data.hash.aou[ obj.OpenILS.data.list.au[0].ws_ou() ];
189                                                         lib.children(null);
190                                                         var p = { 
191                                                                 'lib' : lib,
192                                                                 'staff' : obj.OpenILS.data.list.au[0],
193                                                                 'header' : obj.OpenILS.data.print_list_templates.checkin.header,
194                                                                 'line_item' : obj.OpenILS.data.print_list_templates.checkin.line_item,
195                                                                 'footer' : obj.OpenILS.data.print_list_templates.checkin.footer,
196                                                                 'type' : obj.OpenILS.data.print_list_templates.checkin.type,
197                                                                 'list' : obj.list.dump(),
198                                                         };
199                                                         JSAN.use('util.print'); var print = new util.print();
200                                                         print.tree_list( p );
201                                                         } catch(E) {
202                                                                 alert(E); 
203                                                         }
204                                                 }
205                                         ],
206                                         'cmd_checkin_reprint' : [
207                                                 ['command'],
208                                                 function() {
209                                                         JSAN.use('util.print'); var print = new util.print();
210                                                         print.reprint_last();
211                                                 }
212                                         ],
213                                         'cmd_checkin_done' : [
214                                                 ['command'],
215                                                 function() {
216                                                 }
217                                         ],
218                                 }
219                         }
220                 );
221                 this.controller.render();
222                 this.controller.view.checkin_barcode_entry_textbox.focus();
223
224         },
225
226         'checkin' : function() {
227                 var obj = this;
228                 try {
229                         var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
230                         if (!barcode) return;
231                         var backdate = obj.controller.view.checkin_effective_date_textbox.value;
232                         var auto_print = document.getElementById('checkin_auto');
233                         if (auto_print) auto_print = auto_print.checked;
234                         JSAN.use('circ.util');
235                         var checkin = circ.util.checkin_via_barcode(
236                                 ses(), barcode, backdate, auto_print
237                         );
238                         if (!checkin) return; /* circ.util.checkin handles errors and returns null currently */
239                         if (checkin.ilsevent == 7010 /* COPY_ALERT_MESSAGE */
240                                 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
241                                 || checkin.ilsevent == -1 /* offline */
242                                 || checkin.ilsevent == 1502 /* ASSET_COPY_NOT_FOUND */
243                                 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
244                                 || checkin.ilsevent == 7011 /* COPY_STATUS_LOST */ 
245                                 || checkin.ilsevent == 7012 /* COPY_STATUS_MISSING */) return;
246                         var retrieve_id = js2JSON( { 'copy_id' : checkin.copy.id(), 'barcode' : checkin.copy.barcode(), 'doc_id' : (typeof checkin.record.ilsevent == 'undefined' ? checkin.record.doc_id() : null ) } );
247                         obj.list.append(
248                                 {
249                                         'retrieve_id' : retrieve_id,
250                                         'row' : {
251                                                 'my' : {
252                                                         'circ' : checkin.circ,
253                                                         'mvr' : checkin.record,
254                                                         'acp' : checkin.copy,
255                                                         'status' : checkin.status,
256                                                         'route_to' : checkin.route_to,
257                                                         'message' : checkin.message,
258                                                 }
259                                         }
260                                 //I could override map_row_to_column here
261                                 }
262                         );
263
264                         JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
265
266                         if (typeof obj.on_checkin == 'function') {
267                                 obj.on_checkin(checkin);
268                         }
269                         if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
270                                 obj.error.sdump('D_CIRC','circ.checkin: Calling external .on_checkin()\n');
271                                 window.xulG.on_checkin(checkin);
272                         } else {
273                                 obj.error.sdump('D_CIRC','circ.checkin: No external .on_checkin()\n');
274                         }
275
276                 } catch(E) {
277                         obj.error.standard_unexpected_error_alert('Something went wrong in circ.checkin.checkin: ',E);
278                         if (typeof obj.on_failure == 'function') {
279                                 obj.on_failure(E);
280                         }
281                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
282                                 obj.error.sdump('D_CIRC','circ.checkin: Calling external .on_failure()\n');
283                                 window.xulG.on_failure(E);
284                         } else {
285                                 obj.error.sdump('D_CIRC','circ.checkin: No external .on_failure()\n');
286                         }
287                 }
288
289         },
290
291         'on_checkin' : function() {
292                 this.controller.view.checkin_barcode_entry_textbox.value = '';
293                 this.controller.view.checkin_barcode_entry_textbox.focus();
294         },
295
296         'on_failure' : function() {
297                 this.controller.view.checkin_barcode_entry_textbox.select();
298                 this.controller.view.checkin_barcode_entry_textbox.focus();
299         },
300         
301         'spawn_copy_editor' : function() {
302
303                 /* FIXME -  a lot of redundant calls here */
304
305                 var obj = this;
306
307                 JSAN.use('util.widgets'); JSAN.use('util.functional');
308
309                 var list = obj.selection_list;
310
311                 list = util.functional.map_list(
312                         list,
313                         function (o) {
314                                 return o.copy_id;
315                         }
316                 );
317
318                 var copies = util.functional.map_list(
319                         list,
320                         function (acp_id) {
321                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
322                         }
323                 );
324
325                 var edit = 0;
326                 try {
327                         edit = obj.network.request(
328                                 api.PERM_MULTI_ORG_CHECK.app,
329                                 api.PERM_MULTI_ORG_CHECK.method,
330                                 [ 
331                                         ses(), 
332                                         obj.data.list.au[0].id(), 
333                                         util.functional.map_list(
334                                                 copies,
335                                                 function (o) {
336                                                         return obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
337                                                 }
338                                         ),
339                                         [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
340                                 ]
341                         ).length == 0 ? 1 : 0;
342                 } catch(E) {
343                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
344                 }
345
346                 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
347
348         },
349
350 }
351
352 dump('exiting circ.checkin.js\n');