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