]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/legacy/_browse.xul
we changed RemoteRequest.. local chrome needs XML_HTTP_SERVER set, always
[working/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                                 XML_HTTP_SERVER = g.data.server_unadorned;
69
70                                 mw.G.my_orgs = g.data.list.my_aou;
71                                 mw.G.my_orgs_hash = g.data.hash.my_aou;
72                                 mw.G.org_tree = g.data.tree.aou;
73                                 mw.G.user_ou = g.data.hash.aou[ g.data.list.au[0].home_ou() ];
74                                 mw.G.aout_list = g.data.list.aout;
75                                 mw.G.aout_hash = g.data.hash.aout;
76                                 mw.G.ccs_list = g.data.list.ccs;
77                                 mw.G.ccs_hash = g.data.hash.ccs;
78
79                                 var x = document.getElementById('cmd_copy_edit');
80                                 x.setAttribute('oncommand','try{spawn_copy_editor();}catch(E){alert(E);}');
81
82                                 x = document.getElementById('cmd_copy_add');
83                                 x.setAttribute('oncommand','try{spawn_copy_add_wizard();}catch(E){alert(E);}');
84
85                                 x = document.getElementById('cmd_volume_edit');
86                                 x.setAttribute('oncommand','try{spawn_volume_editor();}catch(E){alert(E);}');
87
88                                 x = document.getElementById('cmd_volume_add');
89                                 x.setAttribute('oncommand','try{spawn_volume_add_wizard();}catch(E){alert(E);}');
90
91                                 x = document.getElementById('browse_list_tree');
92                                 x.setAttribute('seltype','multiple');
93
94                                 my_init();
95         
96                         } catch(E) {
97                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
98                                         "system administrator or software developer the following:\nlegacy/_browse.xul\n" + E + '\n';
99                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
100                                 alert(err_msg);
101                         }
102                 }
103
104                 function timer_init() {
105                         return '';
106                 }
107
108                 function timer_elapsed() {
109                         return '';
110                 }
111
112                 function handle_error(err) {
113                         try { alert(js2JSON(err)); } catch(E) { alert(err); }
114                 }
115
116                 function user_request(a,b,c,d) {
117                         return [ g.network.request(a,b,c,d) ];
118                 }
119
120                 function user_async_request(a,b,c,d) {
121                         return [ g.network.request(a,b,c,d) ];
122                 }
123
124                 var counter = {};
125
126                 function counter_init(id) {
127                         counter[id] = 0;
128                 }
129
130                 function counter_incr(id) {
131                         if (! counter[id]) { counter_init(id); }
132                         return ++counter[id];
133                 }
134
135                 function counter_peek(id) {
136                         if (! counter[id]) { return 0; }
137                         return counter[id];
138                 }
139
140                 function disable_widgets() {
141                         var d = document; var idx = 0;
142                         if (arguments[0].nodeName == '#document') {
143                                 idx = 1; d = arguments[0];
144                         }
145                         for (var i = idx; i < arguments.length; i++) {
146                                 if (typeof(arguments[i]) == 'object') {
147                                         arguments[i].disabled = true;
148                                 } else {
149                                         var w = d.getElementById( arguments[i] );
150                                         if (w) { 
151                                                 w.disabled = true; 
152                                         }
153                                 }
154                         }
155                 }
156
157                 function enable_widgets() {
158                         var d = document; var idx = 0;
159                         if (arguments[0].nodeName == '#document') {
160                                 idx = 1; d = arguments[0];
161                         }
162                         for (var i = idx; i < arguments.length; i++) {
163                                 if (typeof(arguments[i]) == 'object') {
164                                         arguments[i].disabled = false;
165                                 } else {
166                                         var w = d.getElementById( arguments[i] );
167                                         if (w) { 
168                                                 w.disabled = false; 
169                                         }
170                                 }
171                         }
172                 }
173
174                 function find_ou(tree,id) {
175                         if (typeof(id)=='object') { id = id.id(); }
176                         if (tree.id()==id) {
177                                 return tree;
178                         }
179                         for (var i in tree.children()) {
180                                 var child = tree.children()[i];
181                                 ou = find_ou( child, id );
182                                 if (ou) { return ou; }
183                         }
184                         return null;
185                 }
186
187                 function yesno(value) {
188                         switch(value) {
189                                 case true: case 'true': case '1': case 'on':
190                                         return 'Yes';
191                                 default: 
192                                         return 'No';
193                         }
194                 }
195
196                 function empty_widget() {
197                         var d; var e;
198                         if (arguments.length == 1) {
199                                 e = arguments[0];
200                         } else {
201                                 d = arguments[0];
202                                 e = arguments[1];
203                                 if (typeof(e) != 'object') { e = d.getElementById(e); }
204                         }
205                         if (typeof(e) != 'object') { dump('Failed on empty_widget\n'); return null; }
206                         while (e.lastChild) { e.removeChild(e.lastChild); }
207                 }
208
209                 function get_list_from_tree_selection() {
210                         var d = document; var tree_w;
211                         if (arguments.length == 1) {
212                                 tree_w = arguments[0];
213                         } else {
214                                 d = arguments[0];
215                                 tree_w = arguments[1];
216                         }
217                         var hitlist;
218                         if (typeof(tree_w) != 'object') {
219                                 hitlist = d.getElementById(tree_w);
220                         } else {
221                                 hitlist = tree_w;
222                         }
223                         var list = [];
224                         var start = new Object();
225                         var end = new Object();
226                         var numRanges = hitlist.view.selection.getRangeCount();
227                         for (var t=0; t<numRanges; t++){
228                                 hitlist.view.selection.getRangeAt(t,start,end);
229                                 for (var v=start.value; v<=end.value; v++){
230                                         var i = hitlist.contentView.getItemAtIndex(v);
231                                         //sdump('D_WIDGETS',i.tagName + '\n');
232                                         list.push( i );
233                                 }
234                         }
235                         return list;
236                 }
237
238                 function filter_list(list,f) {
239                         var new_list = [];
240                         for (var i in list) {
241                                 var t = f( list[i] );
242                                 if (t) new_list.push( list[i] );
243                         }
244                         return new_list;
245                 }
246
247                 function cycle_attribute() {
248                         var d; var e; var a; var v;
249                         if (arguments.length == 3) {
250                                 e = arguments[0];
251                                 a = arguments[1];
252                                 v = arguments[2];
253                         } else {
254                                 d = arguments[0];
255                                 e = arguments[1];
256                                 a = arguments[2];
257                                 v = arguments[3];
258                                 if (typeof(e) != 'object') { e = d.getElementById(e); }
259                         }
260                         try {
261                                 if (typeof(e) != 'object') { throw('typeof e != object : typeof e = ' + typeof(e)); }
262                                 if (!a) { throw('!a : a = ' + a); }
263                                 if (! e.getAttribute(a) ) { throw(' ! e.getAttribute(a) : a = ' + a); }
264                                 if (typeof(v) != 'object') { throw('typeof v != object : typeof v = ' + typeof(v)); }
265
266                                 var toggle = e.getAttribute(a);
267                                 var next_one = false;
268                                 for (var i = 0; i < v.length; i++) {
269                                         if (next_one) {
270                                                 e.setAttribute(a,v[i]);
271                                                 return v[i];
272                                         }
273                                         if (toggle == v[i]) {
274                                                 next_one = true;
275                                         }
276                                 }
277                                 if (next_one) {
278                                         e.setAttribute(a,v[0]);
279                                         return v[0];
280                                 } else {
281                                         throw('current value not in list');
282                                 }
283                         } catch(E) {
284                                 return null;
285                         }
286                 }
287
288
289                 function mapChrome(chrome) {
290                         switch(chrome) {
291                                 case 'chrome://open_ils_staff_client/content/cat/volume_copy_add_wizard.xul':
292                                         return 'chrome://open_ils_staff_client/content/legacy/_volume_copy_add_wizard.xul'; break;
293                                 case 'chrome://open_ils_staff_client/content/cat/copy_add_wizard.xul':
294                                         return 'chrome://open_ils_staff_client/content/legacy/_copy_add_wizard.xul'; break;
295                                 case 'chrome://open_ils_staff_client/content/cat/volume_edit_wizard.xul':
296                                         return 'chrome://open_ils_staff_client/content/legacy/_volume_edit_wizard.xul'; break;
297                         }
298                         return '';
299                 }
300
301                 parentWindow.new_tab = function() { };
302
303                 parentWindow.replace_tab = function(a,b,c) {
304                         if (window.xulG && typeof window.xulG.new_tab == 'function') {
305                                 try {
306                                         var f = window.xulG.new_tab( mapChrome(c), { 'tab_name' : b }, {} );
307                                         return f.contentWindow;
308                                 } catch(E) {
309                                         alert(E);
310                                 }
311                         }
312                 }
313
314                 mw.new_window = function(a,b,c) {
315                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
316                         JSAN.use('util.window'); var win = new util.window();
317                         return win.open( mapChrome(a), b, c );
318                 }
319
320                 function spawn_copy_editor() {
321
322                         JSAN.use('util.widgets'); JSAN.use('util.functional');
323
324                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
325                         list = util.functional.filter_list(
326                                 list,
327                                 function (o) {
328                                         return o.getAttribute('object_type') == 'copy';
329                                 }
330                         );
331
332                         var edit = 0;
333                         try {
334                                 edit = g.network.request(
335                                         api.PERM_MULTI_ORG_CHECK.app,
336                                         api.PERM_MULTI_ORG_CHECK.method,
337                                         [ 
338                                                 g.session, 
339                                                 g.data.list.au[0].id(), 
340                                                 util.functional.map_list(
341                                                         list,
342                                                         function (o) {
343                                                                 return o.getAttribute('ou_id');
344                                                         }
345                                                 ),
346                                                 [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
347                                         ]
348                                 ).length == 0 ? 1 : 0;
349                         } catch(E) {
350                                 g.error.sdump('D_ERROR','batch permission check: ' + E);
351                         }
352
353                         list = util.functional.map_list(
354                                 list,
355                                 function (o) {
356                                         return o.getAttribute('copy_id');
357                                 }
358                         );
359
360                         var title = list.length == 1 ? 'Copy' : 'Copies';
361
362                         JSAN.use('util.window'); var win = new util.window();
363                         g.data.temp = '';
364                         g.data.stash('temp');
365                         var w = win.open(
366                                 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
367                                         +'?session='+window.escape(g.session)
368                                         +'&copy_ids='+window.escape(js2JSON(list))
369                                         +'&docid='+window.escape(find_this_id)
370                                         +'&edit='+edit
371                                         +'&handle_update=1',
372                                 title,
373                                 'chrome,modal,resizable'
374                         );
375                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
376                         g.data.stash_retrieve();
377                         var copies = JSON2js( g.data.temp );
378                         g.error.sdump('D_CAT','in browse, copies =\n<<' + copies + '>>');
379                         if (edit=='1' && copies!='' && typeof copies != 'undefined') {
380                                 refresh_browse_list();
381                         }
382                 }
383
384                 function spawn_volume_editor() {
385                         JSAN.use('util.widgets'); JSAN.use('util.functional');
386                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
387                         list = util.functional.filter_list(
388                                 list,
389                                 function (o) {
390                                         return o.getAttribute('object_type') == 'volume';
391                                 }
392                         );
393                         
394                         var edit = 0;
395                         try {
396                                 edit = g.network.request(
397                                         api.PERM_MULTI_ORG_CHECK.app,
398                                         api.PERM_MULTI_ORG_CHECK.method,
399                                         [ 
400                                                 g.session, 
401                                                 g.data.list.au[0].id(), 
402                                                 util.functional.map_list(
403                                                         list,
404                                                         function (o) {
405                                                                 return o.getAttribute('ou_id');
406                                                         }
407                                                 ),
408                                                 [ 'UPDATE_VOLUME' ]
409                                         ]
410                                 ).length == 0 ? 1 : 0;
411                         } catch(E) {
412                                 g.error.sdump('batch permission check: ' + E);
413                         }
414
415                         if (edit==0) return; // no read-only view for this interface
416
417                         list = util.functional.map_list(
418                                 list,
419                                 function (o) {
420                                         return [ o.getAttribute('ou_id'), o.getAttribute('volume_id'), o.getAttribute('callnumber') ];
421                                 }
422                         );
423
424                         var title = list.length == 1 ? 'Volume' : 'Volumes';
425
426                         JSAN.use('util.window'); var win = new util.window();
427                         g.data.temp = '';
428                         g.data.stash('temp');
429                         var w = win.open(
430                                 window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR)
431                                         +'?session='+window.escape(g.session)
432                                         +'&ou_id_volume_id_callnumber_tuples=' + window.escape( js2JSON(list) ),
433                                 title,
434                                 'chrome,modal,resizable'
435                         );
436
437                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
438                         g.data.stash_retrieve();
439                         var volumes = JSON2js( g.data.temp );
440                         g.error.sdump('D_CAT','in browse, g.data.temp =\n' + g.data.temp);
441                         if (volumes=='') return;
442                 
443                         volumes = util.functional.filter_list(
444                                 volumes,
445                                 function (o) {
446                                         return o.ischanged() == '1';
447                                 }
448                         );
449
450                         volumes = util.functional.map_list(
451                                 volumes,
452                                 function (o) {
453                                         o.record( find_this_id ); // staff client 2 didn't do this.  Does it matter?
454                                         return o;
455                                 }
456                         );
457
458                         if (volumes.length == 0) return;
459
460                         try {
461                                 var r = g.network.request(
462                                         api.FM_ACN_TREE_UPDATE.app,
463                                         api.FM_ACN_TREE_UPDATE.method,
464                                         [ g.session, volumes ]
465                                 );
466                                 /* FIXME -- revisit the return value here */
467                         } catch(E) {
468                                 alert('volume update error: ' + js2JSON(E));
469                         }
470                         refresh_browse_list();
471
472                 }
473
474                 function spawn_volume_add_wizard() {
475                         JSAN.use('util.widgets'); JSAN.use('util.functional');
476                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
477                         list = util.functional.filter_list(
478                                 list,
479                                 function (o) {
480                                         return o.getAttribute('object_type') == 'org_unit';
481                                 }
482                         );
483                         list = util.functional.map_list(
484                                 list,
485                                 function (o) {
486                                         return o.getAttribute('ou_id');
487                                 }
488                         )               
489                         var edit = 0;
490                         try {
491                                 edit = g.network.request(
492                                         api.PERM_MULTI_ORG_CHECK.app,
493                                         api.PERM_MULTI_ORG_CHECK.method,
494                                         [ 
495                                                 g.session, 
496                                                 g.data.list.au[0].id(), 
497                                                 list,
498                                                 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
499                                         ]
500                                 ).length == 0 ? 1 : 0;
501                         } catch(E) {
502                                 g.error.sdump('batch permission check: ' + E);
503                         }
504
505                         if (edit==0) return; // no read-only view for this interface
506
507                         var title = 'Add Volume/Copy';
508
509                         JSAN.use('util.window'); var win = new util.window();
510                         var w = win.open(
511                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
512                                         +'?session='+window.escape(g.session)
513                                         +'&doc_id=' + window.escape(find_this_id)
514                                         +'&ou_ids=' + window.escape( js2JSON(list) ),
515                                 title,
516                                 'chrome,modal,resizable'
517                         );
518
519                         refresh_browse_list();
520                 }
521
522                 function spawn_copy_add_wizard() {
523                         JSAN.use('util.widgets'); JSAN.use('util.functional');
524                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
525                         list = util.functional.filter_list(
526                                 list,
527                                 function (o) {
528                                         return o.getAttribute('object_type') == 'volume';
529                                 }
530                         );
531                         var copy_shortcut = {};
532                         list = util.functional.map_list(
533                                 list,
534                                 function (o) {
535                                         var ou_id = o.getAttribute('ou_id');
536                                         var volume_id = o.getAttribute('volume_id');
537                                         var label = o.getAttribute('callnumber');
538                                         if (!copy_shortcut[ou_id]) copy_shortcut[ou_id] = {};
539                                         copy_shortcut[ou_id][ label ] = volume_id;
540
541                                         return ou_id;
542                                 }
543                         );
544                         /* quick fix */
545                         list = []; for (var i in copy_shortcut) { list.push( i ); }
546
547                         var edit = 0;
548                         try {
549                                 edit = g.network.request(
550                                         api.PERM_MULTI_ORG_CHECK.app,
551                                         api.PERM_MULTI_ORG_CHECK.method,
552                                         [ 
553                                                 g.session, 
554                                                 g.data.list.au[0].id(), 
555                                                 list,
556                                                 [ 'CREATE_COPY' ]
557                                         ]
558                                 ).length == 0 ? 1 : 0;
559                         } catch(E) {
560                                 g.error.sdump('batch permission check: ' + E);
561                         }
562
563                         if (edit==0) return; // no read-only view for this interface
564
565                         var title = 'Add Copy';
566
567                         JSAN.use('util.window'); var win = new util.window();
568                         var w = win.open(
569                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
570                                         +'?session='+window.escape(g.session)
571                                         +'&doc_id=' + window.escape(find_this_id)
572                                         +'&ou_ids=' + window.escape( js2JSON(list) )
573                                         +'&copy_shortcut=' + window.escape( js2JSON(copy_shortcut) ),
574                                 title,
575                                 'chrome,modal,resizable'
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