]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkin.js
Consolidate some checkboxes into a Checkin Modifiers menu button, since we'll be...
[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.barcode');
9         JSAN.use('util.date');
10         this.OpenILS = {}; JSAN.use('OpenILS.data'); this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
11         this.data = this.OpenILS.data;
12 }
13
14 circ.checkin.prototype = {
15
16         'selection_list' : [],
17
18         'init' : function( params ) {
19
20                 var obj = this;
21
22                 JSAN.use('circ.util');
23                 var columns = circ.util.columns( 
24                         { 
25                                 'barcode' : { 'hidden' : false },
26                                 'title' : { 'hidden' : false },
27                                 'location' : { 'hidden' : false },
28                                 'call_number' : { 'hidden' : false },
29                                 'status' : { 'hidden' : false },
30                                 'route_to' : { 'hidden' : false },
31                                 'alert_message' : { 'hidden' : false },
32                                 'checkin_time' : { 'hidden' : false }
33                         },
34                         {
35                                 'except_these' : [ 'uses', 'checkin_time_full' ]
36                         }
37                 );
38
39                 JSAN.use('util.list'); obj.list = new util.list('checkin_list');
40                 obj.list.init(
41                         {
42                                 'columns' : columns,
43                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
44                                 'on_select' : function(ev) {
45                                         try {
46                                                 JSAN.use('util.functional');
47                                                 var sel = obj.list.retrieve_selection();
48                                                 obj.selection_list = util.functional.map_list(
49                                                         sel,
50                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
51                                                 );
52                                                 obj.error.sdump('D_TRACE', 'circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
53                                                 if (obj.selection_list.length == 0) {
54                                                         obj.controller.view.sel_edit.setAttribute('disabled','true');
55                                                         obj.controller.view.sel_backdate.setAttribute('disabled','true');
56                                                         obj.controller.view.sel_opac.setAttribute('disabled','true');
57                                                         obj.controller.view.sel_patron.setAttribute('disabled','true');
58                                                         obj.controller.view.sel_last_patron.setAttribute('disabled','true');
59                                                         obj.controller.view.sel_copy_details.setAttribute('disabled','true');
60                                                         obj.controller.view.sel_bucket.setAttribute('disabled','true');
61                                                         obj.controller.view.sel_spine.setAttribute('disabled','true');
62                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
63                                                         obj.controller.view.sel_clip.setAttribute('disabled','true');
64                                                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
65                                                 } else {
66                                                         obj.controller.view.sel_edit.setAttribute('disabled','false');
67                                                         obj.controller.view.sel_backdate.setAttribute('disabled','false');
68                                                         obj.controller.view.sel_opac.setAttribute('disabled','false');
69                                                         obj.controller.view.sel_patron.setAttribute('disabled','false');
70                                                         obj.controller.view.sel_last_patron.setAttribute('disabled','false');
71                                                         obj.controller.view.sel_copy_details.setAttribute('disabled','false');
72                                                         obj.controller.view.sel_bucket.setAttribute('disabled','false');
73                                                         obj.controller.view.sel_spine.setAttribute('disabled','false');
74                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
75                                                         obj.controller.view.sel_clip.setAttribute('disabled','false');
76                                                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
77                                                 }
78                                         } catch(E) {
79                                                 alert('FIXME: ' + E);
80                                         }
81                                 }
82                         }
83                 );
84                 
85                 JSAN.use('util.controller'); obj.controller = new util.controller();
86                 obj.controller.init(
87                         {
88                                 'control_map' : {
89                                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
90                                         'sel_clip' : [
91                                                 ['command'],
92                                                 function() { 
93                             obj.list.clipboard(); 
94                             obj.controller.view.checkin_barcode_entry_textbox.focus();
95                         }
96                                         ],
97                                         'sel_edit' : [
98                                                 ['command'],
99                                                 function() {
100                                                         try {
101                                                                 obj.spawn_copy_editor();
102                                                         } catch(E) {
103                                                                 alert(E);
104                                                         }
105                                                 }
106                                         ],
107                                         'sel_spine' : [
108                                                 ['command'],
109                                                 function() {
110                                                         JSAN.use('cat.util');
111                                                         cat.util.spawn_spine_editor(obj.selection_list);
112                                                 }
113                                         ],
114                                         'sel_opac' : [
115                                                 ['command'],
116                                                 function() {
117                                                         JSAN.use('cat.util');
118                                                         cat.util.show_in_opac(obj.selection_list);
119                                                 }
120                                         ],
121                                         'sel_transit_abort' : [
122                                                 ['command'],
123                                                 function() {
124                                                         JSAN.use('circ.util');
125                                                         circ.util.abort_transits(obj.selection_list);
126                                                 }
127                                         ],
128                                         'sel_patron' : [
129                                                 ['command'],
130                                                 function() {
131                                                         JSAN.use('circ.util');
132                                                         circ.util.show_last_few_circs(obj.selection_list);
133                                                 }
134                                         ],
135                                         'sel_last_patron' : [
136                                                 ['command'],
137                                                 function() {
138                                                         var patrons = {};
139                                                         for (var i = 0; i < obj.selection_list.length; i++) {
140                                                                 var circs = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),obj.selection_list[i].copy_id,1]);
141                                                                 if (circs.length > 0) {
142                                                                         patrons[circs[0].usr()] = 1;
143                                                                 } else {
144                                                                         alert(document.getElementById('circStrings').getFormattedString('staff.circ.item_no_circs', [obj.selection_list[i].barcode]));
145                                                                 }
146                                                         }
147                                                         for (var i in patrons) {
148                                                                 xulG.new_patron_tab({},{'id' : i});
149                                                         }
150                                                 }
151                                         ],
152                                         'sel_copy_details' : [
153                                                 ['command'],
154                                                 function() {
155                                                         JSAN.use('circ.util');
156                                                         for (var i = 0; i < obj.selection_list.length; i++) {
157                                                                 circ.util.show_copy_details( obj.selection_list[i].copy_id );
158                                                         }
159                                                 }
160                                         ],
161                                         'sel_backdate' : [
162                                                 ['command'],
163                                                 function() {
164                                                         JSAN.use('circ.util');
165                                                         for (var i = 0; i < obj.selection_list.length; i++) {
166                                 var circ_id = obj.selection_list[i].circ_id; 
167                                 var copy_id = obj.selection_list[i].copy_id; 
168                                 if (!circ_id) {
169                                     var blob = obj.network.simple_request('FM_ACP_DETAILS',[ses(),copy_id]);
170                                     if (blob.circ) circ_id = blob.circ.id();
171                                 }
172                                 if (!circ_id) continue;
173                                                                 circ.util.backdate_post_checkin( circ_id );
174                                                         }
175                                                 }
176                                         ],
177                                         'sel_mark_items_damaged' : [
178                                                 ['command'],
179                                                 function() {
180                                                         var funcs = [];
181                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
182                                                         cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
183                                                 }
184                                         ],
185                                         'sel_bucket' : [
186                                                 ['command'],
187                                                 function() {
188                                                         JSAN.use('cat.util');
189                                                         cat.util.add_copies_to_bucket(obj.selection_list);
190                                                 }
191                                         ],
192                                         'checkin_barcode_entry_textbox' : [
193                                                 ['keypress'],
194                                                 function(ev) {
195                                                         if (ev.keyCode && ev.keyCode == 13) {
196                                                                 obj.checkin();
197                                                         }
198                                                 }
199                                         ],
200                                         'checkin_effective_date_label' : [
201                                                 ['render'],
202                                                 function(e) {
203                                                         return function() {
204                                                                 obj.controller.view.checkin_effective_datepicker.value =
205                                                                         util.date.formatted_date(new Date(),'%F');
206                                                         };
207                                                 }
208                                         ],
209                                         'checkin_effective_datepicker' : [
210                                                 ['change'],
211                                                 function(ev) {
212                                                         if (ev.target.nodeName == 'datepicker') {
213                                                                 try {
214                                                                         if ( ev.target.dateValue > new Date() ) throw(document.getElementById('circStrings').getString('staff.circ.future_date'));
215                                                                         var x = document.getElementById('background');
216                                                                         if (x) {
217                                                                                 if ( ev.target.value == util.date.formatted_date(new Date(),'%F') ) {
218                                                                                         x.setAttribute('style','background-color: green');
219                                                                                         document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
220                                                                                 } else {
221                                                                                         x.setAttribute('style','background-color: red');
222                                                                                         document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getFormattedString('staff.circ.backdated_checkin', [ev.target.value]));
223                                                                                 }
224                                                                         }
225
226                                                                 } catch(E) {
227                                                                         var x = document.getElementById('background');
228                                                                         if (x) {
229                                         x.setAttribute('style','background-color: green');
230                                         document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
231                                     }
232                                                                         dump('checkin:effective_date: ' + E + '\n');
233                                     ev.target.disabled = true;
234                                                                         //alert(document.getElementById('circStrings').getFormattedString('staff.circ.backdate.exception', [E]));
235                                     ev.target.value = util.date.formatted_date(new Date(),'%F');
236                                     ev.target.disabled = false;
237                                                 JSAN.use('util.sound'); var sound = new util.sound(); sound.bad();
238                                     
239                                                                 }
240                                                         }
241                                                 }
242                                         ],
243                                         'cmd_broken' : [
244                                                 ['command'],
245                                                 function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
246                                         ],
247                                         'cmd_checkin_submit_barcode' : [
248                                                 ['command'],
249                                                 function() {
250                                                         obj.checkin();
251                                                 }
252                                         ],
253                                         'cmd_checkin_print' : [
254                                                 ['command'],
255                                                 function() {
256                                                         var p = { 
257                                                                 'template' : 'checkin'
258                                                         };
259                                                         obj.list.print(p);
260                                                 }
261                                         ],
262                                         'cmd_csv_to_clipboard' : [ ['command'], function() { 
263                         obj.list.dump_csv_to_clipboard(); 
264                         obj.controller.view.checkin_barcode_entry_textbox.focus();
265                     } ],
266                                         'cmd_csv_to_printer' : [ ['command'], function() { 
267                         obj.list.dump_csv_to_printer(); 
268                         obj.controller.view.checkin_barcode_entry_textbox.focus();
269                     } ],
270                                         'cmd_csv_to_file' : [ ['command'], function() { 
271                         obj.list.dump_csv_to_file( { 'defaultFileName' : 'checked_in.txt' } ); 
272                         obj.controller.view.checkin_barcode_entry_textbox.focus();
273                     } ]
274                                 }
275                         }
276                 );
277                 this.controller.render();
278                 this.controller.view.checkin_barcode_entry_textbox.focus();
279
280         },
281
282         'test_barcode' : function(bc) {
283                 var obj = this;
284                 var x = document.getElementById('strict_barcode');
285                 if (x && x.checked != true) return true;
286                 var good = util.barcode.check(bc);
287                 if (good) {
288                         return true;
289                 } else {
290                         if ( 1 == obj.error.yns_alert(
291                                                 document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
292                                                 document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
293                                                 document.getElementById('circStrings').getString('staff.circ.cancel'),
294                                                 document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
295                                                 null,
296                                                 document.getElementById('circStrings').getString('staff.circ.confirm'),
297                                                 '/xul/server/skin/media/images/bad_barcode.png'
298                         ) ) {
299                                 return true;
300                         } else {
301                                 return false;
302                         }
303                 }
304         },
305
306         'checkin' : function() {
307                 var obj = this;
308                 try {
309                         var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
310                         if (!barcode) return;
311                         if (barcode) {
312                                 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
313                         }
314                         var backdate = obj.controller.view.checkin_effective_datepicker.value;
315                         var auto_print = document.getElementById('checkin_auto');
316                         if (auto_print) auto_print = auto_print.getAttribute('checked') == 'true';
317                         JSAN.use('circ.util');
318                         circ.util.checkin_via_barcode(
319                                 ses(), 
320                 { 
321                     'barcode' : barcode,
322                                         'disable_textbox' : function() { 
323                                                 obj.controller.view.checkin_barcode_entry_textbox.disabled = true; 
324                                                 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'true'); 
325                                         },
326                                         'enable_textbox' : function() { 
327                                                 obj.controller.view.checkin_barcode_entry_textbox.disabled = false; 
328                                                 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false'); 
329                                         },
330                                         'checkin_result' : function(checkin) {
331                                                 obj.controller.view.checkin_barcode_entry_textbox.disabled = false;
332                                                 obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false'); 
333                                                 obj.checkin2(checkin,backdate);
334                                         }
335                 }, 
336                 backdate, 
337                 auto_print
338                         );
339                 } catch(E) {
340                         obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.exception', [E]));
341                         if (typeof obj.on_failure == 'function') {
342                                 obj.on_failure(E);
343                         }
344                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
345                                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.external') + '\n');
346                                 window.xulG.on_failure(E);
347                         } else {
348                                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.no_external') + '\n');
349                         }
350                 }
351
352         },
353
354         'checkin2' : function(checkin,backdate) {
355                 var obj = this;
356                 try {
357                         if (!checkin) return obj.on_failure(); /* circ.util.checkin handles errors and returns null currently */
358                         if (checkin.ilsevent == 7010 /* COPY_ALERT_MESSAGE */
359                                 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
360                                 || checkin.ilsevent == -1 /* offline */
361                                 || checkin.ilsevent == 1502 /* ASSET_COPY_NOT_FOUND */
362                                 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
363                                 || checkin.ilsevent == 7009 /* CIRC_CLAIMS_RETURNED */ 
364                                 || checkin.ilsevent == 7011 /* COPY_STATUS_LOST */ 
365                                 || checkin.ilsevent == 7012 /* COPY_STATUS_MISSING */) return obj.on_failure();
366                         var retrieve_id = js2JSON( { 'circ_id' : checkin.circ ? checkin.circ.id() : null , '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 ) } );
367                         if (checkin.circ && checkin.circ.checkin_time() == 'now') checkin.circ.checkin_time(backdate);
368                         if (document.getElementById('trim_list')) {
369                                 var x = document.getElementById('trim_list');
370                                 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
371                         }
372                         obj.list.append(
373                                 {
374                                         'retrieve_id' : retrieve_id,
375                                         'row' : {
376                                                 'my' : {
377                                                         'circ' : checkin.circ,
378                                                         'mvr' : checkin.record,
379                                                         'acp' : checkin.copy,
380                                                         'status' : checkin.status,
381                                                         'route_to' : checkin.route_to,
382                                                         'message' : checkin.message
383                                                 }
384                                         },
385                                         'to_top' : true
386                                 //I could override map_row_to_column here
387                                 }
388                         );
389                         obj.list.node.view.selection.select(0);
390
391                         JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
392
393                         if (typeof obj.on_checkin == 'function') {
394                                 obj.on_checkin(checkin);
395                         }
396                         if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
397                                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.external') + '\n');
398                                 window.xulG.on_checkin(checkin);
399                         } else {
400                                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.no_external') + '\n');
401                         }
402
403                         return true;
404
405                 } catch(E) {
406                         obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin2.exception', [E]));
407                         if (typeof obj.on_failure == 'function') {
408                                 obj.on_failure(E);
409                         }
410                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
411                                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.external') + '\n');
412                                 window.xulG.on_failure(E);
413                         } else {
414                                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.no_external') + '\n');
415                         }
416                 }
417
418         },
419
420         'on_checkin' : function() {
421                 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
422                 this.controller.view.checkin_barcode_entry_textbox.select();
423                 this.controller.view.checkin_barcode_entry_textbox.value = '';
424                 this.controller.view.checkin_barcode_entry_textbox.focus();
425         },
426
427         'on_failure' : function() {
428                 this.controller.view.checkin_barcode_entry_textbox.disabled = false;
429                 this.controller.view.checkin_barcode_entry_textbox.select();
430                 this.controller.view.checkin_barcode_entry_textbox.focus();
431         },
432         
433         'spawn_copy_editor' : function() {
434
435                 var obj = this;
436
437                 JSAN.use('util.functional');
438
439                 var list = obj.selection_list;
440
441                 list = util.functional.map_list(
442                         list,
443                         function (o) {
444                                 return o.copy_id;
445                         }
446                 );
447
448                 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
449
450         }
451
452 }
453
454 dump('exiting circ.checkin.js\n');