6636d0fdbf7c5f366adf1e9c0bd7c541344bd7ba
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / legacy / _browse.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Cataloger's Search Result Screen -->
4
5 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
6 <!-- PRESENTATION -->
7 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
8 <?xml-stylesheet href="chrome://open_ils_staff_client/skin/global.css" type="text/css"?>
9
10 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
11 <!-- LOCALIZATION -->
12 <!DOCTYPE window SYSTEM "chrome://open_ils_staff_client/locale/lang.dtd">
13
14 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
15 <!-- OVERLAYS -->
16 <?xul-overlay href="chrome://open_ils_staff_client/content/OpenILS/util_overlay.xul"?>
17 <?xul-overlay href="chrome://open_ils_staff_client/content/legacy/browse_list_overlay.xul"?>
18
19 <window id="browse_list_win"
20         orient="vertical" style="overflow: scroll" 
21         onload="try { my_pre_init(); } catch(E) { alert(E); }"
22         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
23
24         <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
25         <!-- BEHAVIOR -->
26         <script type="text/javascript">var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};</script>
27         <script type="text/javascript" src="chrome://open_ils_staff_client/content/main/JSAN.js"/>
28         <script type="text/javascript" src="chrome://open_ils_staff_client/content/main/constants.js"/>
29         <script type="text/javascript" src="chrome://open_ils_staff_client/content/OpenILS/util/fmall.js"/>
30         <scripts id="openils_util_scripts"/>
31         <script type="text/javascript">
32         <![CDATA[
33
34                 var parentWindow = {};
35                 var params = {};
36                 var mw = {};
37                 var find_this_id;
38
39                 var org_shortname2id = {};
40                 var my_treerow;
41                 var browse_meter_per = 0;
42                 var orgs_with_copies = [];
43                 var orgs_with_copies_hash = {};
44
45                 function my_pre_init() {
46                         try {
47                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
48                                 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
49                                 JSAN.errorLevel = "die"; // none, warn, or die
50                                 JSAN.addRepository('..');
51                                 JSAN.use('util.error'); g.error = new util.error();
52                                 g.error.sdump('D_TRACE','my_pre_init() for legacy/_browse.xul');
53
54                                 mw.G = {};
55                                 mw.G.main_test_variable = 'Hello World';
56                                 g.cgi = new CGI();
57                                 g.session = g.cgi.param('session');
58                                 mw.G.auth_ses = [ g.session ];
59                                 mw.sdump = function(a,b) { g.error.sdump(a,b); }
60
61                                 find_this_id = g.cgi.param('docid');
62
63                                 JSAN.use('util.network');
64                                 g.network = new util.network();
65
66                                 JSAN.use('OpenILS.data');
67                                 g.data = new OpenILS.data(); g.data.init({'via':'stash'});
68                                 mw.G.my_orgs = g.data.list.my_aou;
69                                 mw.G.my_orgs_hash = g.data.hash.my_aou;
70                                 mw.G.org_tree = g.data.tree.aou;
71                                 mw.G.user_ou = g.data.hash.aou[ g.data.list.au[0].home_ou() ];
72                                 mw.G.aout_list = g.data.list.aout;
73                                 mw.G.aout_hash = g.data.hash.aout;
74                                 mw.G.ccs_list = g.data.list.ccs;
75                                 mw.G.ccs_hash = g.data.hash.ccs;
76
77                                 var x = document.getElementById('cmd_copy_edit');
78                                 x.setAttribute('oncommand','try{spawn_copy_editor();}catch(E){alert(E);}');
79
80                                 x = document.getElementById('cmd_copy_add');
81                                 x.setAttribute('oncommand','try{spawn_copy_add_wizard();}catch(E){alert(E);}');
82
83                                 x = document.getElementById('cmd_volume_edit');
84                                 x.setAttribute('oncommand','try{spawn_volume_editor();}catch(E){alert(E);}');
85
86                                 x = document.getElementById('cmd_volume_add');
87                                 x.setAttribute('oncommand','try{spawn_volume_add_wizard();}catch(E){alert(E);}');
88
89                                 x = document.getElementById('browse_list_tree');
90                                 x.setAttribute('seltype','multiple');
91
92                                 my_init();
93         
94                         } catch(E) {
95                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
96                                         "system administrator or software developer the following:\nlegacy/_browse.xul\n" + E + '\n';
97                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
98                                 alert(err_msg);
99                         }
100                 }
101
102                 function timer_init() {
103                         return '';
104                 }
105
106                 function timer_elapsed() {
107                         return '';
108                 }
109
110                 function handle_error(err) {
111                         try { alert(js2JSON(err)); } catch(E) { alert(err); }
112                 }
113
114                 function user_request(a,b,c,d) {
115                         return [ g.network.request(a,b,c,d) ];
116                 }
117
118                 function user_async_request(a,b,c,d) {
119                         return [ g.network.request(a,b,c,d) ];
120                 }
121
122                 var counter = {};
123
124                 function counter_init(id) {
125                         counter[id] = 0;
126                 }
127
128                 function counter_incr(id) {
129                         if (! counter[id]) { counter_init(id); }
130                         return ++counter[id];
131                 }
132
133                 function counter_peek(id) {
134                         if (! counter[id]) { return 0; }
135                         return counter[id];
136                 }
137
138                 function disable_widgets() {
139                         var d = document; var idx = 0;
140                         if (arguments[0].nodeName == '#document') {
141                                 idx = 1; d = arguments[0];
142                         }
143                         for (var i = idx; i < arguments.length; i++) {
144                                 if (typeof(arguments[i]) == 'object') {
145                                         arguments[i].disabled = true;
146                                 } else {
147                                         var w = d.getElementById( arguments[i] );
148                                         if (w) { 
149                                                 w.disabled = true; 
150                                         }
151                                 }
152                         }
153                 }
154
155                 function enable_widgets() {
156                         var d = document; var idx = 0;
157                         if (arguments[0].nodeName == '#document') {
158                                 idx = 1; d = arguments[0];
159                         }
160                         for (var i = idx; i < arguments.length; i++) {
161                                 if (typeof(arguments[i]) == 'object') {
162                                         arguments[i].disabled = false;
163                                 } else {
164                                         var w = d.getElementById( arguments[i] );
165                                         if (w) { 
166                                                 w.disabled = false; 
167                                         }
168                                 }
169                         }
170                 }
171
172                 function find_ou(tree,id) {
173                         if (typeof(id)=='object') { id = id.id(); }
174                         if (tree.id()==id) {
175                                 return tree;
176                         }
177                         for (var i in tree.children()) {
178                                 var child = tree.children()[i];
179                                 ou = find_ou( child, id );
180                                 if (ou) { return ou; }
181                         }
182                         return null;
183                 }
184
185                 function yesno(value) {
186                         switch(value) {
187                                 case true: case 'true': case '1': case 'on':
188                                         return 'Yes';
189                                 default: 
190                                         return 'No';
191                         }
192                 }
193
194                 function empty_widget() {
195                         var d; var e;
196                         if (arguments.length == 1) {
197                                 e = arguments[0];
198                         } else {
199                                 d = arguments[0];
200                                 e = arguments[1];
201                                 if (typeof(e) != 'object') { e = d.getElementById(e); }
202                         }
203                         if (typeof(e) != 'object') { dump('Failed on empty_widget\n'); return null; }
204                         while (e.lastChild) { e.removeChild(e.lastChild); }
205                 }
206
207                 function get_list_from_tree_selection() {
208                         var d = document; var tree_w;
209                         if (arguments.length == 1) {
210                                 tree_w = arguments[0];
211                         } else {
212                                 d = arguments[0];
213                                 tree_w = arguments[1];
214                         }
215                         var hitlist;
216                         if (typeof(tree_w) != 'object') {
217                                 hitlist = d.getElementById(tree_w);
218                         } else {
219                                 hitlist = tree_w;
220                         }
221                         var list = [];
222                         var start = new Object();
223                         var end = new Object();
224                         var numRanges = hitlist.view.selection.getRangeCount();
225                         for (var t=0; t<numRanges; t++){
226                                 hitlist.view.selection.getRangeAt(t,start,end);
227                                 for (var v=start.value; v<=end.value; v++){
228                                         var i = hitlist.contentView.getItemAtIndex(v);
229                                         //sdump('D_WIDGETS',i.tagName + '\n');
230                                         list.push( i );
231                                 }
232                         }
233                         return list;
234                 }
235
236                 function filter_list(list,f) {
237                         var new_list = [];
238                         for (var i in list) {
239                                 var t = f( list[i] );
240                                 if (t) new_list.push( list[i] );
241                         }
242                         return new_list;
243                 }
244
245                 function cycle_attribute() {
246                         var d; var e; var a; var v;
247                         if (arguments.length == 3) {
248                                 e = arguments[0];
249                                 a = arguments[1];
250                                 v = arguments[2];
251                         } else {
252                                 d = arguments[0];
253                                 e = arguments[1];
254                                 a = arguments[2];
255                                 v = arguments[3];
256                                 if (typeof(e) != 'object') { e = d.getElementById(e); }
257                         }
258                         try {
259                                 if (typeof(e) != 'object') { throw('typeof e != object : typeof e = ' + typeof(e)); }
260                                 if (!a) { throw('!a : a = ' + a); }
261                                 if (! e.getAttribute(a) ) { throw(' ! e.getAttribute(a) : a = ' + a); }
262                                 if (typeof(v) != 'object') { throw('typeof v != object : typeof v = ' + typeof(v)); }
263
264                                 var toggle = e.getAttribute(a);
265                                 var next_one = false;
266                                 for (var i = 0; i < v.length; i++) {
267                                         if (next_one) {
268                                                 e.setAttribute(a,v[i]);
269                                                 return v[i];
270                                         }
271                                         if (toggle == v[i]) {
272                                                 next_one = true;
273                                         }
274                                 }
275                                 if (next_one) {
276                                         e.setAttribute(a,v[0]);
277                                         return v[0];
278                                 } else {
279                                         throw('current value not in list');
280                                 }
281                         } catch(E) {
282                                 return null;
283                         }
284                 }
285
286
287                 function mapChrome(chrome) {
288                         switch(chrome) {
289                                 case 'chrome://open_ils_staff_client/content/cat/volume_copy_add_wizard.xul':
290                                         return 'chrome://open_ils_staff_client/content/legacy/_volume_copy_add_wizard.xul'; break;
291                                 case 'chrome://open_ils_staff_client/content/cat/copy_add_wizard.xul':
292                                         return 'chrome://open_ils_staff_client/content/legacy/_copy_add_wizard.xul'; break;
293                                 case 'chrome://open_ils_staff_client/content/cat/volume_edit_wizard.xul':
294                                         return 'chrome://open_ils_staff_client/content/legacy/_volume_edit_wizard.xul'; break;
295                         }
296                         return '';
297                 }
298
299                 parentWindow.new_tab = function() { };
300
301                 parentWindow.replace_tab = function(a,b,c) {
302                         if (window.xulG && typeof window.xulG.new_tab == 'function') {
303                                 try {
304                                         var f = window.xulG.new_tab( mapChrome(c), { 'tab_name' : b }, {} );
305                                         return f.contentWindow;
306                                 } catch(E) {
307                                         alert(E);
308                                 }
309                         }
310                 }
311
312                 mw.new_window = function(a,b,c) {
313                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
314                         JSAN.use('util.window'); var win = new util.window();
315                         return win.open( mapChrome(a), b, c );
316                 }
317
318                 function spawn_copy_editor() {
319
320                         JSAN.use('util.widgets'); JSAN.use('util.functional');
321
322                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
323                         list = util.functional.filter_list(
324                                 list,
325                                 function (o) {
326                                         return o.getAttribute('object_type') == 'copy';
327                                 }
328                         );
329
330                         var edit = 0;
331                         try {
332                                 edit = g.network.request(
333                                         api.PERM_MULTI_ORG_CHECK.app,
334                                         api.PERM_MULTI_ORG_CHECK.method,
335                                         [ 
336                                                 g.session, 
337                                                 g.data.list.au[0].id(), 
338                                                 util.functional.map_list(
339                                                         list,
340                                                         function (o) {
341                                                                 return o.getAttribute('ou_id');
342                                                         }
343                                                 ),
344                                                 [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
345                                         ]
346                                 ).length == 0 ? 1 : 0;
347                         } catch(E) {
348                                 g.error.sdump('D_ERROR','batch permission check: ' + E);
349                         }
350
351                         list = util.functional.map_list(
352                                 list,
353                                 function (o) {
354                                         return o.getAttribute('copy_id');
355                                 }
356                         );
357
358                         var title = list.length == 1 ? 'Copy' : 'Copies';
359
360                         JSAN.use('util.window'); var win = new util.window();
361                         g.data.temp = '';
362                         g.data.stash('temp');
363                         var w = win.open(
364                                 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
365                                         +'?session='+window.escape(g.session)
366                                         +'&copy_ids='+window.escape(js2JSON(list))
367                                         +'&docid='+window.escape(find_this_id)
368                                         +'&edit='+edit
369                                         +'&handle_update=1',
370                                 title,
371                                 'chrome,modal,resizable'
372                         );
373                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
374                         g.data.stash_retrieve();
375                         var copies = JSON2js( g.data.temp );
376                         g.error.sdump('D_CAT','in browse, copies =\n<<' + copies + '>>');
377                         if (edit=='1' && copies!='' && typeof copies != 'undefined') {
378                                 refresh_browse_list();
379                         }
380                 }
381
382                 function spawn_volume_editor() {
383                         JSAN.use('util.widgets'); JSAN.use('util.functional');
384                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
385                         list = util.functional.filter_list(
386                                 list,
387                                 function (o) {
388                                         return o.getAttribute('object_type') == 'volume';
389                                 }
390                         );
391                         
392                         var edit = 0;
393                         try {
394                                 edit = g.network.request(
395                                         api.PERM_MULTI_ORG_CHECK.app,
396                                         api.PERM_MULTI_ORG_CHECK.method,
397                                         [ 
398                                                 g.session, 
399                                                 g.data.list.au[0].id(), 
400                                                 util.functional.map_list(
401                                                         list,
402                                                         function (o) {
403                                                                 return o.getAttribute('ou_id');
404                                                         }
405                                                 ),
406                                                 [ 'UPDATE_VOLUME' ]
407                                         ]
408                                 ).length == 0 ? 1 : 0;
409                         } catch(E) {
410                                 g.error.sdump('batch permission check: ' + E);
411                         }
412
413                         if (edit==0) return; // no read-only view for this interface
414
415                         list = util.functional.map_list(
416                                 list,
417                                 function (o) {
418                                         return [ o.getAttribute('ou_id'), o.getAttribute('volume_id'), o.getAttribute('callnumber') ];
419                                 }
420                         );
421
422                         var title = list.length == 1 ? 'Volume' : 'Volumes';
423
424                         JSAN.use('util.window'); var win = new util.window();
425                         g.data.temp = '';
426                         g.data.stash('temp');
427                         var w = win.open(
428                                 window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR)
429                                         +'?session='+window.escape(g.session)
430                                         +'&ou_id_volume_id_callnumber_tuples=' + window.escape( js2JSON(list) ),
431                                 title,
432                                 'chrome,modal,resizable'
433                         );
434
435                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
436                         g.data.stash_retrieve();
437                         var volumes = JSON2js( g.data.temp );
438                         g.error.sdump('D_CAT','in browse, g.data.temp =\n' + g.data.temp);
439                         if (volumes=='') return;
440                 
441                         volumes = util.functional.filter_list(
442                                 volumes,
443                                 function (o) {
444                                         return o.ischanged() == '1';
445                                 }
446                         );
447
448                         volumes = util.functional.map_list(
449                                 volumes,
450                                 function (o) {
451                                         o.record( find_this_id ); // staff client 2 didn't do this.  Does it matter?
452                                         return o;
453                                 }
454                         );
455
456                         if (volumes.length == 0) return;
457
458                         try {
459                                 var r = g.network.request(
460                                         api.FM_ACN_TREE_UPDATE.app,
461                                         api.FM_ACN_TREE_UPDATE.method,
462                                         [ g.session, volumes ]
463                                 );
464                                 /* FIXME -- revisit the return value here */
465                         } catch(E) {
466                                 alert('volume update error: ' + js2JSON(E));
467                         }
468                         refresh_browse_list();
469
470                 }
471
472                 function spawn_volume_add_wizard() {
473                         JSAN.use('util.widgets'); JSAN.use('util.functional');
474                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
475                         list = util.functional.filter_list(
476                                 list,
477                                 function (o) {
478                                         return o.getAttribute('object_type') == 'org_unit';
479                                 }
480                         );
481                         list = util.functional.map_list(
482                                 list,
483                                 function (o) {
484                                         return o.getAttribute('ou_id');
485                                 }
486                         )               
487                         var edit = 0;
488                         try {
489                                 edit = g.network.request(
490                                         api.PERM_MULTI_ORG_CHECK.app,
491                                         api.PERM_MULTI_ORG_CHECK.method,
492                                         [ 
493                                                 g.session, 
494                                                 g.data.list.au[0].id(), 
495                                                 list,
496                                                 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
497                                         ]
498                                 ).length == 0 ? 1 : 0;
499                         } catch(E) {
500                                 g.error.sdump('batch permission check: ' + E);
501                         }
502
503                         if (edit==0) return; // no read-only view for this interface
504
505                         var title = 'Add Volume/Copy';
506
507                         JSAN.use('util.window'); var win = new util.window();
508                         var w = win.open(
509                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
510                                         +'?session='+window.escape(g.session)
511                                         +'&doc_id=' + window.escape(find_this_id)
512                                         +'&ou_ids=' + window.escape( js2JSON(list) ),
513                                 title,
514                                 'chrome,modal,resizable'
515                         );
516
517                         refresh_browse_list();
518                 }
519
520                 function spawn_copy_add_wizard() {
521                         JSAN.use('util.widgets'); JSAN.use('util.functional');
522                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
523                         list = util.functional.filter_list(
524                                 list,
525                                 function (o) {
526                                         return o.getAttribute('object_type') == 'volume';
527                                 }
528                         );
529                         var copy_shortcut = {};
530                         list = util.functional.map_list(
531                                 list,
532                                 function (o) {
533                                         var cn =  g.network.simple_request(
534                                                 'FM_ACN_RETRIEVE',
535                                                 o.getAttribute('volume_id')
536                                         );
537                                         var ou_id = cn.owning_lib();
538                                         var label = cn.label();
539                                         if (!copy_shortcut[ou_id]) copy_shortcut[ou_id] = {};
540                                         copy_shortcut[ou_id][label] = 1;
541
542                                         return ou_id;
543                                 }
544                         );
545
546                         var edit = 0;
547                         try {
548                                 edit = g.network.request(
549                                         api.PERM_MULTI_ORG_CHECK.app,
550                                         api.PERM_MULTI_ORG_CHECK.method,
551                                         [ 
552                                                 g.session, 
553                                                 g.data.list.au[0].id(), 
554                                                 list,
555                                                 [ 'CREATE_COPY' ]
556                                         ]
557                                 ).length == 0 ? 1 : 0;
558                         } catch(E) {
559                                 g.error.sdump('batch permission check: ' + E);
560                         }
561
562                         if (edit==0) return; // no read-only view for this interface
563
564                         var title = 'Add Copy';
565
566                         JSAN.use('util.window'); var win = new util.window();
567                         var w = win.open(
568                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
569                                         +'?session='+window.escape(g.session)
570                                         +'&doc_id=' + window.escape(find_this_id)
571                                         +'&ou_ids=' + window.escape( js2JSON(list) ),
572                                         +'&copy_shortcut=' + window.escape( js2JSON(copy_shortcut) )
573                                 title,
574                                 'chrome,modal,resizable'
575                         );
576
577                         refresh_browse_list();
578                 }
579                 
580                 function mark_volume() {
581                         JSAN.use('util.widgets'); JSAN.use('util.functional');
582                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
583                         list = util.functional.filter_list(
584                                 list,
585                                 function (o) {
586                                         return o.getAttribute('object_type') == 'volume';
587                                 }
588                         );
589                         list = util.functional.map_list(
590                                 list,
591                                 function (o) {
592                                         return o.getAttribute('volume_id');
593                                 }
594                         );
595
596                         g.data.marked_volume = list[0];
597                         g.data.stash('marked_volume');
598                         alert('Volume marked as Copy Transfer Destination');
599                 }
600
601                 function add_to_bucket() {
602
603                         JSAN.use('util.widgets'); JSAN.use('util.functional');
604
605                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
606                         list = util.functional.filter_list(
607                                 list,
608                                 function (o) {
609                                         return o.getAttribute('object_type') == 'copy';
610                                 }
611                         );
612
613                         list = util.functional.map_list(
614                                 list,
615                                 function (o) {
616                                         return o.getAttribute('copy_id');
617                                 }
618                         );
619                         
620                         JSAN.use('util.window'); var win = new util.window();
621                         win.open( 
622                                 xulG.url_prefix(urls.XUL_COPY_BUCKETS) 
623                                 + '?session=' + window.escape(g.session)
624                                 + '&copy_ids=' + js2JSON( list ),
625                                 'sel_bucket_win' + win.window_name_increment(),
626                                 'chrome,resizable,modal,center'
627                         );
628                 }
629
630         ]]>
631         </script>
632
633         <!-- The logic for this app -->
634         <Evergreen id="browse_list_js" />
635
636         <!-- XUL'ified abstraction for logic to attach to widgets -->
637         <commandset id="browse_list_cmds" />
638
639         <!-- Accelerator Keys (Accessor Keys are in DTD's) -->
640         <keyset id="browse_list_keys" />
641
642         <!-- Context menus -->
643         <popupset id="browse_list_popupset" />
644
645         <!-- Layout to be filled in by overlays and javascript -->
646         <groupbox flex="1">
647                 <caption label="Copy Browser"/>
648                 <vbox id="browse_list_vbox" class="test_class"/>
649         </groupbox>
650
651 </window>
652