]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_browser.js
scary removal of cgi param session
[Evergreen.git] / Open-ILS / xul / staff_client / server / cat / copy_browser.js
1 dump('entering cat.copy_browser.js\n');
2
3 if (typeof cat == 'undefined') cat = {};
4 cat.copy_browser = function (params) {
5         try {
6                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
7                 JSAN.use('util.error'); this.error = new util.error();
8                 this.docid = 278434;
9         } catch(E) {
10                 dump('cat.copy_browser: ' + E + '\n');
11         }
12 }
13
14 cat.copy_browser.prototype = {
15
16         'map_tree' : {},
17         'map_acn' : {},
18         'map_acp' : {},
19
20         'init' : function( params ) {
21
22                 try {
23                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
24                         var obj = this;
25
26                         JSAN.use('util.network'); obj.network = new util.network();
27                         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
28                         JSAN.use('util.controller'); obj.controller = new util.controller();
29                         obj.controller.init(
30                                 {
31                                         control_map : {
32                                                 'cmd_broken' : [
33                                                         ['command'],
34                                                         function() { alert('Not Yet Implemented'); }
35                                                 ],
36                                                 'cmd_show_my_libs' : [
37                                                         ['command'],
38                                                         function() { 
39                                                                 obj.show_my_libs(); 
40                                                         }
41                                                 ],
42                                                 'cmd_show_all_libs' : [
43                                                         ['command'],
44                                                         function() {
45                                                                 obj.show_all_libs();
46                                                         }
47                                                 ],
48                                                 'cmd_show_libs_with_copies' : [
49                                                         ['command'],
50                                                         function() {
51                                                                 obj.show_libs_with_copies();
52                                                         }
53                                                 ],
54                                                 'cmd_clear' : [
55                                                         ['command'],
56                                                         function() {
57                                                                 obj.map_tree = {};
58                                                                 obj.list.clear();
59                                                         }
60                                                 ],
61                                         }
62                                 }
63                         );
64
65                         obj.list_init(params);
66
67                         obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
68
69                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
70                         obj.show_libs( org );
71
72                 } catch(E) {
73                         this.error.sdump('D_ERROR','cat.copy_browser.init: ' + E + '\n');
74                 }
75         },
76
77         'show_my_libs' : function() {
78                 var obj = this;
79                 try {
80                         var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
81                         obj.show_libs( org );
82                 
83                         var p_org = obj.data.hash.aou[ org.parent_ou() ];
84                         if (p_org) {
85                                 JSAN.use('util.exec'); var exec = new util.exec();
86                                 var funcs = [];
87                                 for (var i = 0; i < p_org.children().length; i++) {
88                                         funcs.push(
89                                                 function(o) {
90                                                         return function() {
91                                                                 obj.show_libs( o );
92                                                         }
93                                                 }( p_org.children()[i] )
94                                         );
95                                 }
96                                 exec.chain( funcs );
97                         }
98                 } catch(E) {
99                         alert(E);
100                 }
101         },
102
103         'show_all_libs' : function() {
104                 var obj = this;
105                 try {
106                         obj.show_libs( obj.data.tree.aou );
107
108                         JSAN.use('util.exec'); var exec = new util.exec();
109                         var funcs = [];
110                         for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
111                                 funcs.push(
112                                         function(o) {
113                                                 return function() {
114                                                         obj.show_libs( o );
115                                                 }
116                                         }( obj.data.tree.aou.children()[i] )
117                                 );
118                         }
119                         exec.chain( funcs );
120                 } catch(E) {
121                         alert(E);
122                 }
123         },
124
125         'show_libs_with_copies' : function() {
126                 var obj = this;
127                 try {
128                         JSAN.use('util.exec'); var exec = new util.exec();
129                         JSAN.use('util.functional');
130
131                         var orgs = util.functional.map_list(
132                                 obj.org_ids,
133                                 function(id) { return obj.data.hash.aou[id]; }
134                         ).sort(
135                                 function( a, b ) {
136                                         if (a.shortname() < b.shortname()) return -1;
137                                         if (a.shortname() > b.shortname()) return 1;
138                                         return 0;
139                                 }
140                         );
141                         var funcs = [];
142                         for (var i = 0; i < orgs.length; i++) {
143                                 funcs.push(
144                                         function(o) {
145                                                 return function() {
146                                                         obj.show_libs(o);
147                                                 }
148                                         }( orgs[i] )
149                                 );
150                         }
151                         exec.chain( funcs );
152                 } catch(E) {
153                         alert(E);
154                 }
155         },
156
157         'show_libs' : function(start_aou) {
158                 var obj = this;
159                 try {
160                         if (!start_aou) throw('show_libs: Need a start_aou');
161                         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
162                         JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
163
164                         var funcs = [];
165
166                         var parents = [];
167                         var temp_aou = start_aou;
168                         while ( temp_aou.parent_ou() ) {
169                                 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
170                                 parents.push( temp_aou );
171                         }
172                         parents.reverse();
173
174                         for (var i = 0; i < parents.length; i++) {
175                                 funcs.push(
176                                         function(o,p) {
177                                                 return function() { 
178                                                         obj.append_org(o,p,{'container':'true'}); 
179                                                 };
180                                         }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
181                                 );
182                         }
183
184                         funcs.push(
185                                 function(o,p) {
186                                         return function() { obj.append_org(o,p); };
187                                 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
188                         );
189
190                         funcs.push(
191                                 function() {
192                                         if (start_aou.children()) {
193                                                 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
194                                                 x.setAttribute('container','true');
195                                                 //x.setAttribute('open','true');
196                                                 for (var i = 0; i < start_aou.children().length; i++) {
197                                                         funcs.push(
198                                                                 function(o,p) {
199                                                                         return function() { obj.append_org(o,p); };
200                                                                 }( start_aou.children()[i], start_aou )
201                                                         );
202                                                 }
203                                         }
204                                 }
205                         );
206
207                         exec.chain( funcs );
208
209                 } catch(E) {
210                         alert(E);
211                 }
212         },
213
214         'on_select' : function(list) {
215                 var obj = this;
216                 for (var i = 0; i < list.length; i++) {
217                         var node = obj.map_tree[ list[i] ];
218                         //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
219                         var row_type = list[i].split('_')[0];
220                         var id = list[i].split('_')[1];
221                         switch(row_type) {
222                                 case 'aou' : obj.on_select_org(id); break;
223                                 case 'acn' : obj.on_select_acn(id); break;
224                                 default: break;
225                         }
226                 }
227         },
228
229         'on_select_acn' : function(acn_id) {
230                 var obj = this;
231                 try {
232                         var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
233                         var funcs = [];
234                         if (acn_tree.copies()) {
235                                 for (var i = 0; i < acn_tree.copies().length; i++) {
236                                         funcs.push(
237                                                 function(c,a) {
238                                                         return function() {
239                                                                 obj.append_acp(c,a);
240                                                         }
241                                                 }( acn_tree.copies()[i], acn_tree )
242                                         )
243                                 }
244                         }
245                         JSAN.use('util.exec'); var exec = new util.exec();
246                         exec.chain( funcs );
247                 } catch(E) {
248                         alert(E);
249                 }
250         },
251
252         'on_select_org' : function(org_id) {
253                 var obj = this;
254                 var org = obj.data.hash.aou[ org_id ];
255                 var funcs = [];
256                 if (org.children()) {
257                         for (var i = 0; i < org.children().length; i++) {
258                                 funcs.push(
259                                         function(o,p) {
260                                                 return function() {
261                                                         obj.append_org(o,p)
262                                                 }
263                                         }(org.children()[i],org)
264                                 );
265                         }
266                 } 
267                 if (obj.map_acn[ 'aou_' + org_id ]) {
268                         for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
269                                 funcs.push(
270                                         function(o,a) {
271                                                 return function() {
272                                                         obj.append_acn(o,a);
273                                                 }
274                                         }( org, obj.map_acn[ 'aou_' + org_id ][i] )
275                                 );
276                         }
277                 }
278                 JSAN.use('util.exec'); var exec = new util.exec();
279                 exec.chain( funcs );
280         },
281
282         'append_org' : function (org,parent_org,params) {
283                 var obj = this;
284                 try {
285                         if (obj.map_tree[ 'aou_' + org.id() ]) {
286                                 var x = obj.map_tree[ 'aou_' + org.id() ];
287                                 if (params) {
288                                         for (var i in params) {
289                                                 x.setAttribute(i,params[i]);
290                                         }
291                                 }
292                                 return x;
293                         }
294
295                         var data = {
296                                 'row' : {
297                                         'my' : {
298                                                 'aou' : org,
299                                         }
300                                 },
301                                 'skip_all_columns_except' : [0,1,2],
302                                 'retrieve_id' : 'aou_' + org.id(),
303                         };
304                 
305                         var acn_tree_list;
306                         if ( obj.org_ids.indexOf( org.id() ) == -1 ) {
307                                 if ( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) {
308                                         data.row.my.volume_count = '0';
309                                         data.row.my.copy_count = '<0>';
310                                 } else {
311                                         data.row.my.volume_count = '';
312                                         data.row.my.copy_count = '';
313                                 }
314                         } else {
315                                 var v_count = 0; var c_count = 0;
316                                 acn_tree_list = obj.network.simple_request(
317                                         'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS',
318                                         [ ses(), obj.docid, [ org.id() ] ]
319                                 );
320                                 for (var i = 0; i < acn_tree_list.length; i++) {
321                                         v_count++;
322                                         if (acn_tree_list[i].copies()) c_count += acn_tree_list[i].copies().length;
323                                 }
324                                 data.row.my.volume_count = v_count;
325                                 data.row.my.copy_count = '<' + c_count + '>';
326                         }
327                         if (parent_org) {
328                                 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
329                         }
330
331                         var node = obj.list.append(data);
332                         if (params) {
333                                 for (var i in params) {
334                                         node.setAttribute(i,params[i]);
335                                 }
336                         }
337                         obj.map_tree[ 'aou_' + org.id() ] = node;
338
339                         if (org.children()) {
340                                 node.setAttribute('container','true');
341                         }
342
343                         if (parent_org) {
344                                 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
345                                         data.node.setAttribute('open','true');
346                                 }
347                         } else {
348                                 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
349                         }
350
351                         if (acn_tree_list) {
352                                 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
353                                 node.setAttribute('container','true');
354                         }
355
356                 } catch(E) {
357                         dump(E+'\n');
358                         alert(E);
359                 }
360         },
361
362         'append_acn' : function( org, acn_tree, params ) {
363                 var obj = this;
364                 try {
365                         if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
366                                 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
367                                 if (params) {
368                                         for (var i in params) {
369                                                 x.setAttribute(i,params[i]);
370                                         }
371                                 }
372                                 return x;
373                         }
374
375                         var parent_node = obj.map_tree[ 'aou_' + org.id() ];
376                         var data = {
377                                 'row' : {
378                                         'my' : {
379                                                 'aou' : org,
380                                                 'acn' : acn_tree,
381                                                 'volume_count' : '',
382                                                 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
383                                         }
384                                 },
385                                 'skip_all_columns_except' : [0,1,2],
386                                 'retrieve_id' : 'acn_' + acn_tree.id(),
387                                 'node' : parent_node,
388                         };
389                         var node = obj.list.append(data);
390                         obj.map_tree[ 'acn_' + acn_tree.id() ] =  node;
391                         if (params) {
392                                 for (var i in params) {
393                                         node.setAttribute(i,params[i]);
394                                 }
395                         }
396                         if (acn_tree.copies()) {
397                                 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
398                                 node.setAttribute('container','true');
399                         }
400
401                 } catch(E) {
402                         dump(E+'\n');
403                         alert(E);
404                 }
405         },
406
407         'append_acp' : function( acp_item, acn_tree, params ) {
408                 var obj = this;
409                 try {
410                         if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
411                                 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
412                                 if (params) {
413                                         for (var i in params) {
414                                                 x.setAttribute(i,params[i]);
415                                         }
416                                 }
417                                 return x;
418                         }
419
420                         var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
421                         var data = {
422                                 'row' : {
423                                         'my' : {
424                                                 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
425                                                 'acn' : acn_tree,
426                                                 'acp' : acp_item,
427                                                 'volume_count' : '',
428                                                 'copy_count' : '',
429                                         }
430                                 },
431                                 'retrieve_id' : 'acp_' + acp_item.id(),
432                                 'node' : parent_node,
433                         };
434                         var node = obj.list.append(data);
435                         obj.map_tree[ 'acp_' + acp_item.id() ] =  node;
436                         if (params) {
437                                 for (var i in params) {
438                                         node.setAttribute(i,params[i]);
439                                 }
440                         }
441
442                 } catch(E) {
443                         dump(E+'\n');
444                         alert(E);
445                 }
446         },
447
448         'list_init' : function( params ) {
449
450                 try {
451                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
452                         var obj = this;
453                         
454                         JSAN.use('circ.util');
455                         var columns = [
456                                 {
457                                         'id' : 'tree_location', 'label' : 'Location/Barcode', 'flex' : 1,
458                                         'primary' : true, 'hidden' : false, 
459                                         'render' : 'my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"'
460                                 },
461                                 {
462                                         'id' : 'volume_count', 'label' : 'Volumes', 'flex' : 0,
463                                         'primary' : false, 'hidden' : false, 
464                                         'render' : 'my.volume_count'
465                                 },
466                                 {
467                                         'id' : 'copy_count', 'label' : 'Copies', 'flex' : 0,
468                                         'primary' : false, 'hidden' : false, 
469                                         'render' : 'my.copy_count'
470                                 },
471                         ].concat(
472                                 circ.util.columns( 
473                                         { 
474                                                 'location' : { 'hidden' : false },
475                                                 'circ_lib' : { 'hidden' : false },
476                                                 'owning_lib' : { 'hidden' : false },
477                                                 'call_number' : { 'hidden' : false },
478                                                 'status' : { 'hidden' : false },
479                                         },
480                                         {
481                                                 'just_these' : [
482                                                         'owning_lib',
483                                                         'circ_lib',
484                                                         'call_number',
485                                                         'copy_number',
486                                                         'location',
487                                                         'barcode',
488                                                         'loan_duration',
489                                                         'fine_level',
490                                                         'circulate',
491                                                         'holdable',
492                                                         'opac_visible',
493                                                         'ref',
494                                                         'deposit',
495                                                         'deposit_amount',
496                                                         'price',
497                                                         'circ_as_type',
498                                                         'circ_modifier',
499                                                         'status',
500                                                         'alert_message',
501                                                         'acp_id',
502                                                 ]
503                                         }
504                                 )
505                         );
506                         JSAN.use('util.list'); obj.list = new util.list('copy_tree');
507                         obj.list.init(
508                                 {
509                                         'columns' : columns,
510                                         'map_row_to_column' : circ.util.std_map_row_to_column(' '),
511                                         'retrieve_row' : function(params) {
512
513                                                 var row = params.row;
514
515                                                 var funcs = [];
516                                         /*      
517                                                 if (!row.my.mvr) funcs.push(
518                                                         function() {
519
520                                                                 row.my.mvr = obj.network.request(
521                                                                         api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
522                                                                         api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
523                                                                         [ row.my.circ.target_copy() ]
524                                                                 );
525
526                                                         }
527                                                 );
528                                                 if (!row.my.acp) {
529                                                         funcs.push(     
530                                                                 function() {
531
532                                                                         row.my.acp = obj.network.request(
533                                                                                 api.FM_ACP_RETRIEVE.app,
534                                                                                 api.FM_ACP_RETRIEVE.method,
535                                                                                 [ row.my.circ.target_copy() ]
536                                                                         );
537
538                                                                         params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
539
540                                                                 }
541                                                         );
542                                                 } else {
543                                                         params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
544                                                 }
545                                         */
546                                                 funcs.push(
547                                                         function() {
548
549                                                                 if (typeof params.on_retrieve == 'function') {
550                                                                         params.on_retrieve(row);
551                                                                 }
552
553                                                         }
554                                                 );
555
556                                                 JSAN.use('util.exec'); var exec = new util.exec();
557                                                 exec.on_error = function(E) {
558                                                         var err = 'items chain: ' + js2JSON(E);
559                                                         obj.error.sdump('D_ERROR',err);
560                                                         return true; /* keep going */
561                                                 }
562                                                 exec.chain( funcs );
563
564                                                 return row;
565                                         },
566                                         'on_click' : function(ev) {
567                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
568                                                 var row = {}; var col = {}; var nobj = {};
569                                                 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
570                                                 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
571                                                 var node = obj.list.node.contentView.getItemAtIndex(row.value);
572                                                 var list = [ node.getAttribute('retrieve_id') ];
573                                                 if (typeof obj.on_select == 'function') {
574                                                         obj.on_select(list);
575                                                 }
576                                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
577                                                         window.xulG.on_select(list);
578                                                 }
579                                         },
580                                         'on_select' : function(ev) {
581                                                 JSAN.use('util.functional');
582                                                 var sel = obj.list.retrieve_selection();
583                                                 var list = util.functional.map_list(
584                                                         sel,
585                                                         function(o) { return o.getAttribute('retrieve_id'); }
586                                                 );
587                                                 if (typeof obj.on_select == 'function') {
588                                                         obj.on_select(list);
589                                                 }
590                                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
591                                                         window.xulG.on_select(list);
592                                                 }
593                                         },
594                                 }
595                         );
596         
597
598                 } catch(E) {
599                         this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
600                         alert(E);
601                 }
602         },
603 }
604
605 dump('exiting cat.copy_browser.js\n');