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