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