]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/copy_status.js
export csv from list to clipboard
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / circ / copy_status.js
1 dump('entering circ.copy_status.js\n');
2
3 if (typeof circ == 'undefined') circ = {};
4 circ.copy_status = 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         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
11 }
12
13 circ.copy_status.prototype = {
14         'selection_list' : [],
15
16         'init' : function( params ) {
17
18                 var obj = this;
19
20                 JSAN.use('circ.util');
21                 var columns = circ.util.columns( 
22                         { 
23                                 'barcode' : { 'hidden' : false },
24                                 'title' : { 'hidden' : false },
25                                 'location' : { 'hidden' : false },
26                                 'call_number' : { 'hidden' : false },
27                                 'status' : { 'hidden' : false },
28                                 'alert_message' : { 'hidden' : false },
29                                 'due_date' : { 'hidden' : false },
30                         },
31                         {
32                                 'except_these' : [
33                                         'checkin_time', 'checkin_time_full', 'route_to', 'message', 'uses', 'xact_finish',
34                                 ],
35                         }
36                 );
37
38                 JSAN.use('util.list'); obj.list = new util.list('copy_status_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_checkin.setAttribute('disabled','true');
54                                                         obj.controller.view.cmd_replace_barcode.setAttribute('disabled','true');
55                                                         obj.controller.view.sel_edit.setAttribute('disabled','true');
56                                                         obj.controller.view.sel_opac.setAttribute('disabled','true');
57                                                         obj.controller.view.sel_bucket.setAttribute('disabled','true');
58                                                         obj.controller.view.sel_copy_details.setAttribute('disabled','true');
59                                                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
60                                                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
61                                                         obj.controller.view.sel_patron.setAttribute('disabled','true');
62                                                         obj.controller.view.sel_spine.setAttribute('disabled','true');
63                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
64                                                         obj.controller.view.sel_clip.setAttribute('disabled','true');
65                                                         obj.controller.view.sel_renew.setAttribute('disabled','true');
66                                                 } else {
67                                                         obj.controller.view.sel_checkin.setAttribute('disabled','false');
68                                                         obj.controller.view.cmd_replace_barcode.setAttribute('disabled','false');
69                                                         obj.controller.view.sel_edit.setAttribute('disabled','false');
70                                                         obj.controller.view.sel_opac.setAttribute('disabled','false');
71                                                         obj.controller.view.sel_patron.setAttribute('disabled','false');
72                                                         obj.controller.view.sel_bucket.setAttribute('disabled','false');
73                                                         obj.controller.view.sel_copy_details.setAttribute('disabled','false');
74                                                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
75                                                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
76                                                         obj.controller.view.sel_spine.setAttribute('disabled','false');
77                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
78                                                         obj.controller.view.sel_clip.setAttribute('disabled','false');
79                                                         obj.controller.view.sel_renew.setAttribute('disabled','false');
80                                                 }
81                                         } catch(E) {
82                                                 alert('FIXME: ' + E);
83                                         }
84                                 },
85                         }
86                 );
87                 
88                 JSAN.use('util.controller'); obj.controller = new util.controller();
89                 obj.controller.init(
90                         {
91                                 'control_map' : {
92                                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
93                                         'sel_clip' : [
94                                                 ['command'],
95                                                 function() { obj.list.clipboard(); }
96                                         ],
97                                         'sel_checkin' : [
98                                                 ['command'],
99                                                 function() {
100                                                         try {
101                                                                 var funcs = [];
102                                                                 JSAN.use('circ.util');
103                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
104                                                                         var barcode = obj.selection_list[i].barcode;
105                                                                         var checkin = circ.util.checkin_via_barcode( ses(), { 'barcode' : barcode } );
106                                                                         funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
107                                                                 }
108                                                                 alert('Action complete.');
109                                                                 for (var i = 0; i < funcs.length; i++) { funcs[i](); }
110                                                         } catch(E) {
111                                                                 obj.error.standard_unexpected_error_alert('Checkin did not likely happen.',E);
112                                                         }
113                                                 }
114                                         ],
115                                         'cmd_replace_barcode' : [
116                                                 ['command'],
117                                                 function() {
118                                                         try {
119                                                                 var funcs = [];
120                                                                 JSAN.use('cat.util');
121                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
122                                                                         try { 
123                                                                                 var barcode = obj.selection_list[i].barcode;
124                                                                                 var new_bc = cat.util.replace_barcode( barcode );
125                                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(new_bc) );
126                                                                         } catch(E) {
127                                                                                 obj.error.standard_unexpected_error_alert('Barcode ' + barcode + ' was not likely replaced.',E);
128                                                                         }
129                                                                 }
130                                                                 alert('Action complete.');
131                                                                 for (var i = 0; i < funcs.length; i++) { funcs[i](); }
132                                                         } catch(E) {
133                                                                 obj.error.standard_unexpected_error_alert('Barcode replacements did not likely happen.',E);
134                                                         }
135                                                 }
136                                         ],
137                                         'sel_edit' : [
138                                                 ['command'],
139                                                 function() {
140                                                         try {
141                                                                 var funcs = [];
142                                                                 obj.spawn_copy_editor();
143                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
144                                                                                 var barcode = obj.selection_list[i].barcode;
145                                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
146                                                                 }
147                                                                 for (var i = 0; i < funcs.length; i++) { funcs[i](); }
148                                                         } catch(E) {
149                                                                 obj.error.standard_unexpected_error_alert('with copy editor',E);
150                                                         }
151                                                 }
152                                         ],
153                                         'sel_spine' : [
154                                                 ['command'],
155                                                 function() {
156                                                         JSAN.use('cat.util');
157                                                         cat.util.spawn_spine_editor(obj.selection_list);
158                                                 }
159                                         ],
160                                         'sel_opac' : [
161                                                 ['command'],
162                                                 function() {
163                                                         JSAN.use('cat.util');
164                                                         cat.util.show_in_opac(obj.selection_list);
165                                                 }
166                                         ],
167                                         'sel_transit_abort' : [
168                                                 ['command'],
169                                                 function() {
170                                                         var funcs = [];
171                                                         JSAN.use('circ.util');
172                                                         circ.util.abort_transits(obj.selection_list);
173                                                         for (var i = 0; i < obj.selection_list.length; i++) {
174                                                                 var barcode = obj.selection_list[i].barcode;
175                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
176                                                         }
177                                                         alert('Action complete.');
178                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
179                                                 }
180                                         ],
181                                         'sel_patron' : [
182                                                 ['command'],
183                                                 function() {
184                                                         JSAN.use('circ.util');
185                                                         circ.util.show_last_few_circs(obj.selection_list);
186                                                 }
187                                         ],
188                                         'sel_copy_details' : [
189                                                 ['command'],
190                                                 function() {
191                                                         JSAN.use('circ.util');
192                                                         for (var i = 0; i < obj.selection_list.length; i++) {
193                                                                 circ.util.show_copy_details( obj.selection_list[i].copy_id );
194                                                         }
195                                                 }
196                                         ],
197                                         'sel_renew' : [
198                                                 ['command'],
199                                                 function() {
200                                                         var funcs = [];
201                                                         JSAN.use('circ.util');
202                                                         for (var i = 0; i < obj.selection_list.length; i++) {
203                                                                 var test = obj.selection_list[i].renewable;
204                                                                 var barcode = obj.selection_list[i].barcode;
205                                                                 if (test == 't') {
206                                                                         circ.util.renew_via_barcode( barcode );
207                                                                         funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
208                                                                 } else {
209                                                                         alert('Item with barcode ' + barcode + ' is not circulating.');
210                                                                 }
211                                                         }
212                                                         alert('Action complete.');
213                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
214                                                 }
215                                         ],
216
217                                         'sel_mark_items_damaged' : [
218                                                 ['command'],
219                                                 function() {
220                                                         var funcs = [];
221                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
222                                                         cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
223                                                         for (var i = 0; i < obj.selection_list.length; i++) {
224                                                                 var barcode = obj.selection_list[i].barcode;
225                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
226                                                         }
227                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
228                                                 }
229                                         ],
230                                         'sel_mark_items_missing' : [
231                                                 ['command'],
232                                                 function() {
233                                                         var funcs = [];
234                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
235                                                         cat.util.mark_item_missing( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
236                                                         for (var i = 0; i < obj.selection_list.length; i++) {
237                                                                 var barcode = obj.selection_list[i].barcode;
238                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
239                                                         }
240                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
241                                                 }
242                                         ],
243                                         'sel_bucket' : [
244                                                 ['command'],
245                                                 function() {
246                                                         JSAN.use('cat.util');
247                                                         cat.util.add_copies_to_bucket(obj.selection_list);
248                                                 }
249                                         ],
250                                         'copy_status_barcode_entry_textbox' : [
251                                                 ['keypress'],
252                                                 function(ev) {
253                                                         if (ev.keyCode && ev.keyCode == 13) {
254                                                                 obj.copy_status();
255                                                         }
256                                                 }
257                                         ],
258                                         'cmd_broken' : [
259                                                 ['command'],
260                                                 function() { alert('Not Yet Implemented'); }
261                                         ],
262                                         'cmd_copy_status_submit_barcode' : [
263                                                 ['command'],
264                                                 function() {
265                                                         obj.copy_status();
266                                                 }
267                                         ],
268                                         'cmd_copy_status_print' : [
269                                                 ['command'],
270                                                 function() {
271                                                         try {
272                                                                 obj.list.on_all_fleshed =
273                                                                         function() {
274                                                                                 try {
275                                                                                         dump( js2JSON( obj.list.dump_with_keys() ) + '\n' );
276                                                                                         obj.data.stash_retrieve();
277                                                                                         var lib = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
278                                                                                         lib.children(null);
279                                                                                         var p = { 
280                                                                                                 'lib' : lib,
281                                                                                                 'staff' : obj.data.list.au[0],
282                                                                                                 'header' : obj.data.print_list_templates.item_status.header,
283                                                                                                 'line_item' : obj.data.print_list_templates.item_status.line_item,
284                                                                                                 'footer' : obj.data.print_list_templates.item_status.footer,
285                                                                                                 'type' : obj.data.print_list_templates.item_status.type,
286                                                                                                 'list' : obj.list.dump_with_keys(),
287                                                                                         };
288                                                                                         JSAN.use('util.print'); var print = new util.print();
289                                                                                         print.tree_list( p );
290                                                                                         setTimeout(function(){ obj.list.on_all_fleshed = null; },0);
291                                                                                 } catch(E) {
292                                                                                         obj.error.standard_unexpected_error_alert('print',E); 
293                                                                                 }
294                                                                         }
295                                                                 obj.list.full_retrieve();
296                                                         } catch(E) {
297                                                                 obj.error.standard_unexpected_error_alert('print',E); 
298                                                         }
299                                                 }
300                                         ],
301                                         'cmd_copy_status_export' : [
302                                                 ['command'],
303                                                 function() {
304                                                         try {
305                                                                 obj.list.on_all_fleshed =
306                                                                         function() {
307                                                                                 try {
308                                                                                         dump( obj.list.dump_csv() + '\n' );
309                                                                                         copy_to_clipboard(obj.list.dump_csv());
310                                                                                         setTimeout(function(){ obj.list.on_all_fleshed = null; },0);
311                                                                                 } catch(E) {
312                                                                                         obj.error.standard_unexpected_error_alert('export',E); 
313                                                                                 }
314                                                                         }
315                                                                 obj.list.full_retrieve();
316                                                         } catch(E) {
317                                                                 obj.error.standard_unexpected_error_alert('export',E); 
318                                                         }
319                                                 }
320                                         ],
321
322                                         'cmd_copy_status_reprint' : [
323                                                 ['command'],
324                                                 function() {
325                                                 }
326                                         ],
327                                         'cmd_copy_status_done' : [
328                                                 ['command'],
329                                                 function() {
330                                                 }
331                                         ],
332                                 }
333                         }
334                 );
335                 this.controller.render();
336                 this.controller.view.copy_status_barcode_entry_textbox.focus();
337
338         },
339
340         'test_barcode' : function(bc) {
341                 var obj = this;
342                 var good = util.barcode.check(bc);
343                 if (good) {
344                         return true;
345                 } else {
346                         if ( 1 == obj.error.yns_alert(
347                                                 'Bad checkdigit; possible mis-scan.  Use this barcode ("' + bc + '") anyway?',
348                                                 'Bad Barcode',
349                                                 'Cancel',
350                                                 'Accept Barcode',
351                                                 null,
352                                                 'Check here to confirm this action',
353                                                 '/xul/server/skin/media/images/bad_barcode.png'
354                         ) ) {
355                                 return true;
356                         } else {
357                                 return false;
358                         }
359                 }
360         },
361
362         'copy_status' : function(barcode) {
363                 var obj = this;
364                 try {
365                         try { document.getElementById('last_scanned').setAttribute('value',''); } catch(E) {}
366                         if (!barcode) barcode = obj.controller.view.copy_status_barcode_entry_textbox.value;
367                         if (!barcode) return;
368                         if (barcode) {
369                                 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
370                         }
371                         JSAN.use('circ.util');
372                         var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE_VIA_BARCODE', [ barcode ]);
373                         if (copy == null) {
374                                 throw('Something weird happened.  null result');
375                         } else if (copy.ilsevent) {
376                                 switch(copy.ilsevent) {
377                                         case -1: 
378                                                 obj.error.standard_network_error_alert(); 
379                                                 obj.controller.view.copy_status_barcode_entry_textbox.select();
380                                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
381                                         break;
382                                         case 1502 /* ASSET_COPY_NOT_FOUND */ :
383                                                 try { document.getElementById('last_scanned').setAttribute('value',barcode + ' was either mis-scanned or is not cataloged.'); } catch(E) {}
384                                                 obj.error.yns_alert(barcode + ' was either mis-scanned or is not cataloged.','Not Cataloged','OK',null,null,'Check here to confirm this message');
385                                                 obj.controller.view.copy_status_barcode_entry_textbox.select();
386                                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
387                                         break;
388                                         default: 
389                                                 throw(copy); 
390                                         break;
391                                 }
392                         } else {
393                                 obj.network.simple_request('FM_ACP_DETAILS', [ ses(), copy.id() ], function(req) {
394                                         try {
395                                                 var details = req.getResultObject();
396                                                 var msg = copy.barcode() + ' -- ';
397                                                 if (copy.call_number() == -1) msg += 'Item is a Pre-Cat.  ';
398                                                 if (details.hold) msg += 'Item is captured for a Hold.  ';
399                                                 if (details.transit) msg += 'Item is in Transit.  ';
400                                                 if (details.circ && ! details.circ.checkin_time()) msg += 'Item is circulating.  ';
401                                                 try { document.getElementById('last_scanned').setAttribute('value',msg); } catch(E) {}
402                                         } catch(E) {
403                                                 alert(E);
404                                         }
405                                 } );
406                                 var my_mvr = obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]);
407                                 if (document.getElementById('trim_list')) {
408                                         var x = document.getElementById('trim_list');
409                                         if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
410                                 }
411                                 obj.list.append(
412                                         {
413                                                 'retrieve_id' : js2JSON( { 'renewable' : copy.circulations() ? 't' : 'f', 'copy_id' : copy.id(), 'barcode' : barcode, 'doc_id' : (typeof my_mvr.ilsevent == 'undefined' ? my_mvr.doc_id() : null ) } ),
414                                                 'row' : {
415                                                         'my' : {
416                                                                 'mvr' : my_mvr,
417                                                                 'acp' : copy,
418                                                         }
419                                                 },
420                                                 'to_top' : true,
421                                         }
422                                 );
423                                 obj.controller.view.copy_status_barcode_entry_textbox.value = '';
424                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
425                         }
426                 } catch(E) {
427                         obj.error.standard_unexpected_error_alert('',E);
428                         obj.controller.view.copy_status_barcode_entry_textbox.select();
429                         obj.controller.view.copy_status_barcode_entry_textbox.focus();
430                 }
431
432         },
433         
434         'spawn_copy_editor' : function() {
435
436                 /* FIXME -  a lot of redundant calls here */
437
438                 var obj = this;
439
440                 JSAN.use('util.widgets'); JSAN.use('util.functional');
441
442                 var list = obj.selection_list;
443
444                 list = util.functional.map_list(
445                         list,
446                         function (o) {
447                                 return o.copy_id;
448                         }
449                 );
450
451                 var copies = util.functional.map_list(
452                         list,
453                         function (acp_id) {
454                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
455                         }
456                 );
457
458                 var edit = 0;
459                 try {
460                         edit = obj.network.request(
461                                 api.PERM_MULTI_ORG_CHECK.app,
462                                 api.PERM_MULTI_ORG_CHECK.method,
463                                 [ 
464                                         ses(), 
465                                         obj.data.list.au[0].id(), 
466                                         util.functional.map_list(
467                                                 copies,
468                                                 function (o) {
469                                                         return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
470                                                 }
471                                         ),
472                                         copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
473                                 ]
474                         ).length == 0 ? 1 : 0;
475                 } catch(E) {
476                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
477                 }
478
479                 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
480
481         },
482
483 }
484
485 dump('exiting circ.copy_status.js\n');