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