]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/transit_list.js
don't test for UPDATE_BATCH_COPY if single copy is being edited
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / admin / transit_list.js
1 dump('entering admin.transit_list.js\n');
2
3 if (typeof admin == 'undefined') admin = {};
4 admin.transit_list = 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         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
10 }
11
12 admin.transit_list.prototype = {
13
14         'init' : function( params ) {
15
16                 var obj = this;
17
18                 obj.list_init();
19                 obj.controller_init();
20                 obj.kick_off();
21
22         },
23
24         'kick_off' : function() {
25                 var obj = this;
26                 try {
27                         obj.network.simple_request('FM_ATC_RETRIEVE_VIA_AOU',[ ses(), obj.data.list.au[ 0 ].ws_ou() ], 
28                                 function(req) {
29                                         try {
30                                                 var robj = req.getResultObject();
31                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
32
33                                                 JSAN.use('util.exec'); 
34                                                 var exec = new util.exec(2);
35                                                 var exec2 = new util.exec(2);
36
37                                                 function gen_list_append(id,which_list) {
38                                                         return function() {
39                                                                 switch(which_list) {
40                                                                         case 0: obj.list.append( { 'row' : { 'my' : { 'transit_id' : id } } } ); break;
41                                                                         case 1: obj.list2.append( { 'row' : { 'my' : { 'transit_id' : id } } } ); break;
42                                                                 }
43                                                         };
44                                                 }
45
46                                                 var rows = []; var rows2 = [];
47
48                                                 for (var i = 0; i < robj.from.length; i++) {
49                                                         //get_transit(robj.from[i], 0);
50                                                         rows.push( gen_list_append(robj.from[i],0) );
51                                                 }
52
53                                                 for (var i = 0; i < robj.to.length; i++) {
54                                                         //get_transit(robj.to[i], 1);
55                                                         rows2.push( gen_list_append(robj.to[i],1) );
56                                                 }
57                                 
58                                                 exec.chain( rows );
59                                                 exec2.chain( rows2 );
60
61                                         } catch(E) {
62                                                 try { obj.error.standard_unexpected_error_alert('retrieving transits',E); } catch(F) { alert(E); }
63                                         }
64                                 }
65                         );
66                 } catch(E) {
67                         try { obj.error.standard_unexpected_error_alert('pre-retrieving transits',E); } catch(F) { alert(E); }
68                 }
69         },
70
71         'list_init' : function() {
72
73                 var obj = this;
74
75                 obj.selection_list = [];
76                 obj.selection_list2 = [];
77
78                 JSAN.use('circ.util'); 
79                 var columns = circ.util.transit_columns(
80                         {
81                                 'transit_source' : { 'hidden' : false },
82                                 'transit_source_send_time' : { 'hidden' : false },
83                                 'transit_dest_lib' : { 'hidden' : false },
84                                 'transit_item_barcode' : { 'hidden' : false },
85                                 'transit_item_title' : { 'hidden' : false },
86                         },
87                         {
88                                 'just_these' : [
89                                         'transit_id',
90                                         'transit_source',
91                                         'transit_source_send_time',
92                                         'transit_dest_lib',
93                                         'transit_item_barcode',
94                                         'transit_item_title',
95                                         'transit_item_author',
96                                         'transit_item_callnumber',
97                                         'transit_target_copy',
98                                 ]
99                         }
100                 ).concat( 
101                         circ.util.hold_columns(
102                                 {
103                                         'request_time' : { 'hidden' : false },
104                                 },
105                                 {
106                                         'just_these' : [
107                                                 'request_timestamp',
108                                                 'request_time',
109                                                 'capture_timestamp',
110                                                 'capture_time',
111                                                 'hold_type',
112                                                 'expire_time',
113                                                 'patron_name',
114                                         ],
115                                 }
116                         ) 
117                 );
118
119                 JSAN.use('util.list'); 
120                 obj.list = new util.list('transit_from');
121                 obj.list.init( 
122                         { 
123                                 'columns' : columns, 
124                                 'map_row_to_column' : circ.util.std_map_row_to_column(), 
125                                 'retrieve_row' : function(params) {
126                                         var row = params.row;
127                                         try {
128                                                 obj.get_transit_and_hold_and_run_func(
129                                                         row.my.transit_id,
130                                                         function(transit,hold) { return obj.get_rest_of_row_given_transit_and_hold(params,transit,hold); }
131                                                 );
132                                         } catch(E) {
133                                                 try { obj.error.standard_unexpected_error_alert('retrieving row',E); } catch(F) { alert(E); }
134                                         }
135                                 },
136                                 'on_select' : function(ev) {
137                                         try {
138                                                 JSAN.use('util.functional');
139                                                 var sel = obj.list.retrieve_selection();
140                                                 obj.selection_list = util.functional.map_list(
141                                                         sel,
142                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
143                                                 );
144                                                 obj.error.sdump('D_TRACE','admin.transit_list: selection list = ' + js2JSON(obj.selection_list) );
145                                                 if (obj.selection_list.length == 0) {
146                                                         obj.controller.view.sel_edit.setAttribute('disabled','true');
147                                                         obj.controller.view.sel_opac.setAttribute('disabled','true');
148                                                         obj.controller.view.sel_bucket.setAttribute('disabled','true');
149                                                         obj.controller.view.sel_copy_details.setAttribute('disabled','true');
150                                                         obj.controller.view.sel_patron.setAttribute('disabled','true');
151                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
152                                                         obj.controller.view.sel_clip.setAttribute('disabled','true');
153                                                 } else {
154                                                         obj.controller.view.sel_edit.setAttribute('disabled','false');
155                                                         obj.controller.view.sel_opac.setAttribute('disabled','false');
156                                                         obj.controller.view.sel_patron.setAttribute('disabled','false');
157                                                         obj.controller.view.sel_bucket.setAttribute('disabled','false');
158                                                         obj.controller.view.sel_copy_details.setAttribute('disabled','false');
159                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
160                                                         obj.controller.view.sel_clip.setAttribute('disabled','false');
161                                                 }
162                                         } catch(E) {
163                                                 alert('FIXME: ' + E);
164                                         }
165                                 },
166                         }
167                 );
168                 obj.list2 = new util.list('transit_to');
169                 obj.list2.init( 
170                         { 
171                                 'columns' : columns, 
172                                 'map_row_to_column' : circ.util.std_map_row_to_column(), 
173                                 'retrieve_row' : function(params) {
174                                         var row = params.row;
175                                         try {
176                                                 obj.get_transit_and_hold_and_run_func(
177                                                         row.my.transit_id,
178                                                         function(transit,hold) { return obj.get_rest_of_row_given_transit_and_hold(params,transit,hold); }
179                                                 );
180                                         } catch(E) {
181                                                 try { obj.error.standard_unexpected_error_alert('retrieving row',E); } catch(F) { alert(E); }
182                                         }
183                                 },
184                                 'on_select' : function(ev) {
185                                         try {
186                                                 JSAN.use('util.functional');
187                                                 var sel = obj.list2.retrieve_selection();
188                                                 obj.selection_list2 = util.functional.map_list(
189                                                         sel,
190                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
191                                                 );
192                                                 obj.error.sdump('D_TRACE','admin.transit_list: selection list2 = ' + js2JSON(obj.selection_list2) );
193                                                 if (obj.selection_list2.length == 0) {
194                                                         obj.controller.view.sel_edit2.setAttribute('disabled','true');
195                                                         obj.controller.view.sel_opac2.setAttribute('disabled','true');
196                                                         obj.controller.view.sel_bucket2.setAttribute('disabled','true');
197                                                         obj.controller.view.sel_copy_details2.setAttribute('disabled','true');
198                                                         obj.controller.view.sel_patron2.setAttribute('disabled','true');
199                                                         obj.controller.view.sel_transit_abort2.setAttribute('disabled','true');
200                                                         obj.controller.view.sel_clip2.setAttribute('disabled','true');
201                                                 } else {
202                                                         obj.controller.view.sel_edit2.setAttribute('disabled','false');
203                                                         obj.controller.view.sel_opac2.setAttribute('disabled','false');
204                                                         obj.controller.view.sel_patron2.setAttribute('disabled','false');
205                                                         obj.controller.view.sel_bucket2.setAttribute('disabled','false');
206                                                         obj.controller.view.sel_copy_details2.setAttribute('disabled','false');
207                                                         obj.controller.view.sel_transit_abort2.setAttribute('disabled','false');
208                                                         obj.controller.view.sel_clip2.setAttribute('disabled','false');
209                                                 }
210                                         } catch(E) {
211                                                 alert('FIXME: ' + E);
212                                         }
213                                 },
214                         }
215                 );
216
217         },
218
219         'get_transit_and_hold_and_run_func' : function (transit_id,do_this) {
220                 var obj = this;
221                 obj.network.simple_request('FM_ATC_RETRIEVE', [ ses(), transit_id ],
222                         function(req2) {
223                                 try {
224                                         var r_atc = req2.getResultObject();
225                                         if (typeof r_atc.ilsevent != 'undefined') throw(r_atc);
226
227                                         if (instanceOf(r_atc,atc)) {
228                                                 do_this(r_atc,null);
229                                         } else if (instanceOf(r_atc,ahtc)) {
230                                                 obj.network.simple_request('FM_AHR_RETRIEVE', [ ses(), r_atc.hold() ],
231                                                         function(req3) {
232                                                                 try {
233                                                                         var r_ahr = req3.getResultObject();
234                                                                         if (typeof r_ahr.ilsevent != 'undefined') throw(r_ahr);
235                                                                         if (instanceOf(r_ahr[0],ahr)) {
236                                                                                 do_this(r_atc,r_ahr[0]);
237                                                                         } else {
238                                                                                 throw(r_ahr);
239                                                                         }
240                                                                 } catch(E) {
241                                                                         try { obj.error.standard_unexpected_error_alert('retrieving hold id = ' + r_atc.hold() + ' for transit id = ' + transit_id,E); } catch(F) { alert(E); }
242                                                                 }
243                                                         }
244                                                 );
245                                         } else {
246                                                 throw(r_atc);
247                                         }
248
249                                 } catch(E) {
250                                         try { obj.error.standard_unexpected_error_alert('retrieving transit id = ' + transit_id,E); } catch(F) { alert(E); }
251                                 }
252                         }
253                 );
254         },
255
256         'get_rest_of_row_given_transit_and_hold' : function(params,transit,hold) {
257                 var obj = this;
258                 var row = params.row;
259
260                 row.my.atc = transit;
261                 if (hold) row.my.ahr = hold;
262
263                 obj.network.simple_request(
264                         'FM_ACP_RETRIEVE',
265                         [ row.my.atc.target_copy() ],
266                         function(req) {
267                                 try { 
268                                         var r_acp = req.getResultObject();
269                                         if (typeof r_acp.ilsevent != 'undefined') throw(r_acp);
270                                         row.my.acp = r_acp;
271
272                                         obj.network.simple_request(
273                                                 'FM_ACN_RETRIEVE',
274                                                 [ r_acp.call_number() ],
275                                                 function(req2) {
276                                                         try {
277                                                                 var r_acn = req2.getResultObject();
278                                                                 if (typeof r_acn.ilsevent != 'undefined') throw(r_acn);
279                                                                 row.my.acn = r_acn;
280
281                                                                 if (row.my.acn.record() > 0) {
282                                                                         obj.network.simple_request(
283                                                                                 'MODS_SLIM_RECORD_RETRIEVE',
284                                                                                 [ r_acn.record() ],
285                                                                                 function(req3) {
286                                                                                         try {
287                                                                                                 var r_mvr = req3.getResultObject();
288                                                                                                 if (typeof r_mvr.ilsevent != 'undefined') throw(r_mvr);
289                                                                                                 row.my.mvr = r_mvr;
290
291                                                                                                 params.row_node.setAttribute(
292                                                                                                         'retrieve_id', js2JSON( { 
293                                                                                                                 'copy_id' : row.my.acp ? row.my.acp.id() : null, 
294                                                                                                                 'doc_id' : row.my.mvr ? row.my.mvr.doc_id() : null,  
295                                                                                                                 'barcode' : row.my.acp ? row.my.acp.barcode() : null, 
296                                                                                                                 'acp_id' : row.my.acp ? row.my.acp.id() : null, 
297                                                                                                                 'acn_id' : row.my.acn ? row.my.acn.id() : null,  
298                                                                                                                 'atc_id' : row.my.atc ? row.my.atc.id() : null,  
299                                                                                                                 'ahr_id' : row.my.ahr ? row.my.ahr.id() : null,  
300                                                                                                         } )
301                                                                                                 );
302                                                                                                 if (typeof params.on_retrieve == 'function') {
303                                                                                                         params.on_retrieve(row);
304                                                                                                 }
305                                                                                         } catch(E) {
306                                                                                                 try { obj.error.standard_unexpected_error_alert('retrieving mvr',E); } catch(F) { alert(E); }
307                                                                                         }
308                                                                                 }
309                                                                         );
310                                                                 } else {
311                                                                         params.row_node.setAttribute(
312                                                                                 'retrieve_id', js2JSON( { 
313                                                                                         'copy_id' : row.my.acp ? row.my.acp.id() : null, 
314                                                                                         'doc_id' : row.my.mvr ? row.my.mvr.doc_id() : null,  
315                                                                                         'barcode' : row.my.acp ? row.my.acp.barcode() : null, 
316                                                                                         'acp_id' : row.my.acp ? row.my.acp.id() : null, 
317                                                                                         'acn_id' : row.my.acn ? row.my.acn.id() : null,  
318                                                                                         'atc_id' : row.my.atc ? row.my.atc.id() : null,  
319                                                                                         'ahr_id' : row.my.ahr ? row.my.ahr.id() : null,  
320                                                                                 } )
321                                                                         );
322                                                                         if (typeof params.on_retrieve == 'function') {
323                                                                                 params.on_retrieve(row);
324                                                                         }
325                                                                 }
326                                         
327                                                         } catch(E) {
328                                                                 try { obj.error.standard_unexpected_error_alert('retrieving acn',E); } catch(F) { alert(E); }
329                                                         }
330                                                 }
331                                         );
332
333
334                                 } catch(E) {
335                                         try { obj.error.standard_unexpected_error_alert('retrieving acp',E); } catch(F) { alert(E); }
336                                 }
337                         }
338                 );
339         },
340
341         'controller_init' : function() {
342                 var obj = this;
343
344                 JSAN.use('util.controller'); obj.controller = new util.controller();
345                 obj.controller.init(
346                         {
347                                 'control_map' : {
348                                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
349                                         'save_columns2' : [ [ 'command' ], function() { obj.list2.save_columns(); } ],
350                                         'sel_clip' : [ ['command'], function() { obj.list.clipboard(); } ],
351                                         'sel_clip2' : [ ['command'], function() { obj.list2.clipboard(); } ],
352                                         'sel_edit' : [ ['command'], function() { try { obj.spawn_copy_editor(0); } catch(E) { alert(E); } } ],
353                                         'sel_edit2' : [ ['command'], function() { try { obj.spawn_copy_editor(1); } catch(E) { alert(E); } } ],
354                                         'sel_opac' : [ ['command'], function() { JSAN.use('cat.util'); cat.util.show_in_opac(obj.selection_list); } ],
355                                         'sel_opac2' : [ ['command'], function() { JSAN.use('cat.util'); cat.util.show_in_opac(obj.selection_list2); } ],
356                                         'sel_transit_abort' : [ ['command'], function() { JSAN.use('circ.util'); circ.util.abort_transits(obj.selection_list); } ],
357                                         'sel_transit_abort2' : [ ['command'], function() { JSAN.use('circ.util'); circ.util.abort_transits(obj.selection_list2); } ],
358                                         'sel_patron' : [ ['command'], function() { JSAN.use('circ.util'); circ.util.show_last_few_circs(obj.selection_list); } ],
359                                         'sel_patron2' : [ ['command'], function() { JSAN.use('circ.util'); circ.util.show_last_few_circs(obj.selection_list2); } ],
360                                         'sel_copy_details' : [ ['command'], function() { JSAN.use('circ.util'); for (var i = 0; i < obj.selection_list.length; i++) { circ.util.show_copy_details( obj.selection_list[i].copy_id ); } } ],
361                                         'sel_copy_details2' : [ ['command'], function() { JSAN.use('circ.util'); for (var i = 0; i < obj.selection_list2.length; i++) { circ.util.show_copy_details( obj.selection_list2[i].copy_id ); } } ],
362                                         'sel_bucket' : [ ['command'], function() { JSAN.use('cat.util'); cat.util.add_copies_to_bucket(obj.selection_list); } ],
363                                         'sel_bucket2' : [ ['command'], function() { JSAN.use('cat.util'); cat.util.add_copies_to_bucket(obj.selection_list2); } ],
364                                         'cmd_print_list' : [ ['command'], function() { obj.print_list(0); } ],
365                                         'cmd_print_list2' : [ ['command'], function() { obj.print_list(1); } ],
366                                 }
367                         }
368                 );
369                 this.controller.render();
370
371         },
372
373         'print_list' : function(which_list) {
374                 var obj = this;
375                 try {
376
377                         var list = which_list == 0 ? obj.list : obj.list2;
378
379                         if (list.on_all_fleshed != null) {
380                                 var r = window.confirm('This list is busy retrieving/rendering rows for a pending action.  Would you like to abort the pending action and proceed?');
381                                 if (!r) return;
382                         }
383                         list.on_all_fleshed =
384                                 function() {
385                                         try {
386                                                 dump( js2JSON( list.dump_with_keys() ) + '\n' );
387                                                 obj.data.stash_retrieve();
388                                                 var lib = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
389                                                 lib.children(null);
390                                                 var p = { 
391                                                         'lib' : lib,
392                                                         'staff' : obj.data.list.au[0],
393                                                         'header' : obj.data.print_list_templates.transit_list.header,
394                                                         'line_item' : obj.data.print_list_templates.transit_list.line_item,
395                                                         'footer' : obj.data.print_list_templates.transit_list.footer,
396                                                         'type' : obj.data.print_list_templates.transit_list.type,
397                                                         'list' : list.dump_with_keys(),
398                                                 };
399                                                 JSAN.use('util.print'); var print = new util.print();
400                                                 print.tree_list( p );
401                                                 setTimeout(function(){ list.on_all_fleshed = null; },0);
402                                         } catch(E) {
403                                                 obj.error.standard_unexpected_error_alert('print',E); 
404                                         }
405                                 }
406                         list.full_retrieve();
407                 } catch(E) {
408                         obj.error.standard_unexpected_error_alert('print',E); 
409                 }
410         },
411         
412         'spawn_copy_editor' : function(which_list) {
413
414                 /* FIXME -  a lot of redundant calls here */
415
416                 var obj = this;
417
418                 JSAN.use('util.widgets'); JSAN.use('util.functional');
419
420                 var list = which_list == 0 ? obj.selection_list : obj.selection_list2;
421
422                 list = util.functional.map_list(
423                         list,
424                         function (o) {
425                                 return o.copy_id;
426                         }
427                 );
428
429                 var copies = util.functional.map_list(
430                         list,
431                         function (acp_id) {
432                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
433                         }
434                 );
435
436                 var edit = 0;
437                 try {
438                         edit = obj.network.request(
439                                 api.PERM_MULTI_ORG_CHECK.app,
440                                 api.PERM_MULTI_ORG_CHECK.method,
441                                 [ 
442                                         ses(), 
443                                         obj.data.list.au[0].id(), 
444                                         util.functional.map_list(
445                                                 copies,
446                                                 function (o) {
447                                                         return obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
448                                                 }
449                                         ),
450                                         copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
451                                 ]
452                         ).length == 0 ? 1 : 0;
453                 } catch(E) {
454                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
455                 }
456
457                 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
458
459         },
460
461 }
462
463 dump('exiting admin.transit_list.js\n');