]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/legacy/_browse.xul
9de97003c14f745184b0872d9657067636fcd4e3
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / evergreen / 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://evergreen/skin/evergreen.css" type="text/css"?>
9
10 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
11 <!-- LOCALIZATION -->
12 <!DOCTYPE window SYSTEM "chrome://evergreen/locale/lang.dtd">
13
14 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
15 <!-- OVERLAYS -->
16 <?xul-overlay href="chrome://evergreen/content/OpenILS/util_overlay.xul"?>
17 <?xul-overlay href="chrome://evergreen/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 = 'evergreen'; var IAMXUL = true; var g = {};</script>
27         <scripts id="openils_util_scripts"/>
28         <script type="text/javascript" src="chrome://evergreen/content/main/JSAN.js"/>
29         <script type="text/javascript">
30         <![CDATA[
31
32                 var parentWindow = {};
33                 var params = {};
34                 var mw = {};
35                 var find_this_id;
36
37                 var org_shortname2id = {};
38                 var my_treerow;
39                 var browse_meter_per = 0;
40                 var orgs_with_copies = [];
41                 var orgs_with_copies_hash = {};
42
43                 function my_pre_init() {
44                         try {
45                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
46                                 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
47                                 JSAN.errorLevel = "die"; // none, warn, or die
48                                 JSAN.addRepository('..');
49                                 JSAN.use('util.error'); g.error = new util.error();
50                                 g.error.sdump('D_TRACE','my_pre_init() for legacy/_browse.xul');
51
52                                 mw.G = {};
53                                 mw.G.main_test_variable = 'Hello World';
54                                 g.cgi = new CGI();
55                                 g.session = g.cgi.param('session');
56                                 mw.G.auth_ses = [ g.session ];
57                                 mw.sdump = function(a,b) { g.error.sdump(a,b); }
58
59                                 find_this_id = g.cgi.param('docid');
60
61                                 JSAN.use('util.network');
62                                 g.network = new util.network();
63
64                                 JSAN.use('OpenILS.data');
65                                 g.data = new OpenILS.data(); g.data.init({'via':'stash'});
66                                 mw.G.my_orgs = g.data.list.my_aou;
67                                 mw.G.my_orgs_hash = g.data.hash.my_aou;
68                                 mw.G.org_tree = g.data.tree.aou;
69                                 mw.G.user_ou = g.data.list.au[0];
70                                 mw.G.aout_list = g.data.list.aout;
71                                 mw.G.aout_hash = g.data.hash.aout;
72                                 mw.G.ccs_list = g.data.list.ccs;
73                                 mw.G.ccs_hash = g.data.hash.ccs;
74
75                                 var x = document.getElementById('cmd_copy_edit');
76                                 x.setAttribute('oncommand','try{spawn_copy_editor();}catch(E){alert(E);}');
77
78                                 x = document.getElementById('cmd_copy_add');
79                                 x.setAttribute('oncommand','try{spawn_copy_add_wizard();}catch(E){alert(E);}');
80
81                                 x = document.getElementById('cmd_volume_edit');
82                                 x.setAttribute('oncommand','try{spawn_volume_editor();}catch(E){alert(E);}');
83
84                                 x = document.getElementById('cmd_volume_add');
85                                 x.setAttribute('oncommand','try{spawn_volume_add_wizard();}catch(E){alert(E);}');
86
87                                 x = document.getElementById('browse_list_tree');
88                                 x.setAttribute('seltype','multiple');
89
90                                 my_init();
91         
92                         } catch(E) {
93                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
94                                         "system administrator or software developer the following:\nlegacy/_browse.xul\n" + E + '\n';
95                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
96                                 alert(err_msg);
97                         }
98                 }
99
100                 function timer_init() {
101                         return '';
102                 }
103
104                 function timer_elapsed() {
105                         return '';
106                 }
107
108                 function handle_error(err) {
109                         try { alert(js2JSON(err)); } catch(E) { alert(err); }
110                 }
111
112                 function user_request(a,b,c,d) {
113                         return [ g.network.request(a,b,c,d) ];
114                 }
115
116                 function user_async_request(a,b,c,d) {
117                         return [ g.network.request(a,b,c,d) ];
118                 }
119
120                 var counter = {};
121
122                 function counter_init(id) {
123                         counter[id] = 0;
124                 }
125
126                 function counter_incr(id) {
127                         if (! counter[id]) { counter_init(id); }
128                         return ++counter[id];
129                 }
130
131                 function counter_peek(id) {
132                         if (! counter[id]) { return 0; }
133                         return counter[id];
134                 }
135
136                 function disable_widgets() {
137                         var d = document; var idx = 0;
138                         if (arguments[0].nodeName == '#document') {
139                                 idx = 1; d = arguments[0];
140                         }
141                         for (var i = idx; i < arguments.length; i++) {
142                                 if (typeof(arguments[i]) == 'object') {
143                                         arguments[i].disabled = true;
144                                 } else {
145                                         var w = d.getElementById( arguments[i] );
146                                         if (w) { 
147                                                 w.disabled = true; 
148                                         }
149                                 }
150                         }
151                 }
152
153                 function enable_widgets() {
154                         var d = document; var idx = 0;
155                         if (arguments[0].nodeName == '#document') {
156                                 idx = 1; d = arguments[0];
157                         }
158                         for (var i = idx; i < arguments.length; i++) {
159                                 if (typeof(arguments[i]) == 'object') {
160                                         arguments[i].disabled = false;
161                                 } else {
162                                         var w = d.getElementById( arguments[i] );
163                                         if (w) { 
164                                                 w.disabled = false; 
165                                         }
166                                 }
167                         }
168                 }
169
170                 function find_ou(tree,id) {
171                         if (typeof(id)=='object') { id = id.id(); }
172                         if (tree.id()==id) {
173                                 return tree;
174                         }
175                         for (var i in tree.children()) {
176                                 var child = tree.children()[i];
177                                 ou = find_ou( child, id );
178                                 if (ou) { return ou; }
179                         }
180                         return null;
181                 }
182
183                 function yesno(value) {
184                         switch(value) {
185                                 case true: case 'true': case '1': case 'on':
186                                         return 'Yes';
187                                 default: 
188                                         return 'No';
189                         }
190                 }
191
192                 function empty_widget() {
193                         var d; var e;
194                         if (arguments.length == 1) {
195                                 e = arguments[0];
196                         } else {
197                                 d = arguments[0];
198                                 e = arguments[1];
199                                 if (typeof(e) != 'object') { e = d.getElementById(e); }
200                         }
201                         if (typeof(e) != 'object') { dump('Failed on empty_widget\n'); return null; }
202                         while (e.lastChild) { e.removeChild(e.lastChild); }
203                 }
204
205                 function get_list_from_tree_selection() {
206                         var d = document; var tree_w;
207                         if (arguments.length == 1) {
208                                 tree_w = arguments[0];
209                         } else {
210                                 d = arguments[0];
211                                 tree_w = arguments[1];
212                         }
213                         var hitlist;
214                         if (typeof(tree_w) != 'object') {
215                                 hitlist = d.getElementById(tree_w);
216                         } else {
217                                 hitlist = tree_w;
218                         }
219                         var list = [];
220                         var start = new Object();
221                         var end = new Object();
222                         var numRanges = hitlist.view.selection.getRangeCount();
223                         for (var t=0; t<numRanges; t++){
224                                 hitlist.view.selection.getRangeAt(t,start,end);
225                                 for (var v=start.value; v<=end.value; v++){
226                                         var i = hitlist.contentView.getItemAtIndex(v);
227                                         //sdump('D_WIDGETS',i.tagName + '\n');
228                                         list.push( i );
229                                 }
230                         }
231                         return list;
232                 }
233
234                 function filter_list(list,f) {
235                         var new_list = [];
236                         for (var i in list) {
237                                 var t = f( list[i] );
238                                 if (t) new_list.push( list[i] );
239                         }
240                         return new_list;
241                 }
242
243                 function cycle_attribute() {
244                         var d; var e; var a; var v;
245                         if (arguments.length == 3) {
246                                 e = arguments[0];
247                                 a = arguments[1];
248                                 v = arguments[2];
249                         } else {
250                                 d = arguments[0];
251                                 e = arguments[1];
252                                 a = arguments[2];
253                                 v = arguments[3];
254                                 if (typeof(e) != 'object') { e = d.getElementById(e); }
255                         }
256                         try {
257                                 if (typeof(e) != 'object') { throw('typeof e != object : typeof e = ' + typeof(e)); }
258                                 if (!a) { throw('!a : a = ' + a); }
259                                 if (! e.getAttribute(a) ) { throw(' ! e.getAttribute(a) : a = ' + a); }
260                                 if (typeof(v) != 'object') { throw('typeof v != object : typeof v = ' + typeof(v)); }
261
262                                 var toggle = e.getAttribute(a);
263                                 var next_one = false;
264                                 for (var i = 0; i < v.length; i++) {
265                                         if (next_one) {
266                                                 e.setAttribute(a,v[i]);
267                                                 return v[i];
268                                         }
269                                         if (toggle == v[i]) {
270                                                 next_one = true;
271                                         }
272                                 }
273                                 if (next_one) {
274                                         e.setAttribute(a,v[0]);
275                                         return v[0];
276                                 } else {
277                                         throw('current value not in list');
278                                 }
279                         } catch(E) {
280                                 return null;
281                         }
282                 }
283
284
285                 function mapChrome(chrome) {
286                         switch(chrome) {
287                                 case 'chrome://evergreen/content/cat/volume_copy_add_wizard.xul':
288                                         return 'chrome://evergreen/content/legacy/_volume_copy_add_wizard.xul'; break;
289                                 case 'chrome://evergreen/content/cat/copy_add_wizard.xul':
290                                         return 'chrome://evergreen/content/legacy/_copy_add_wizard.xul'; break;
291                                 case 'chrome://evergreen/content/cat/volume_edit_wizard.xul':
292                                         return 'chrome://evergreen/content/legacy/_volume_edit_wizard.xul'; break;
293                         }
294                         return '';
295                 }
296
297                 parentWindow.new_tab = function() { };
298
299                 parentWindow.replace_tab = function(a,b,c) {
300                         if (window.xulG && typeof window.xulG.new_tab == 'function') {
301                                 try {
302                                         var f = window.xulG.new_tab( mapChrome(c), { 'tab_name' : b }, {} );
303                                         return f.contentWindow;
304                                 } catch(E) {
305                                         alert(E);
306                                 }
307                         }
308                 }
309
310                 mw.new_window = function(a,b,c) {
311                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
312                         JSAN.use('util.window'); var win = new util.window();
313                         return win.open( mapChrome(a), b, c );
314                 }
315
316                 function spawn_copy_editor() {
317                         /* <command id="cmd_copy_edit" oncommand="spawn_batch_copy_editor(window.parent_window.document, 'replace_iframe', 'copy_editor', { 'tree' : document.getElementById('browse_list_tree') , 'refresh_func' : refresh_browse_list }); window.parent_window.document.getElementById('copy_editor_tab').disabled = false;"/> */
318                         JSAN.use('util.widgets'); JSAN.use('util.functional');
319                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
320                         list = util.functional.filter_list(
321                                 list,
322                                 function (obj) {
323                                         return obj.getAttribute('object_type') == 'copy';
324                                 }
325                         );
326                         list = util.functional.map_list(
327                                 list,
328                                 function (obj) {
329                                         return obj.getAttribute('copy_id');
330                                 }
331                         );
332
333                         JSAN.use('util.window'); var win = new util.window();
334                         win.open(
335                                 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
336                                         +'?session='+window.escape(g.session)
337                                         +'&copy_ids='+window.escape(js2JSON(list))
338                                         +'&edit=1',
339                                 'Copies',
340                                 'chrome,modal,resizable'
341                         ); 
342                 }
343
344                 function spawn_volume_editor() {
345                         /* <command id="cmd_volume_edit" oncommand="volume_edit(false,{ 'tree' : 'browse_list_tree', 'refresh_func' : refresh_browse_list });"/> */
346                         JSAN.use('util.widgets'); JSAN.use('util.functional');
347                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
348                         list = util.functional.filter_list(
349                                 list,
350                                 function (obj) {
351                                         return obj.getAttribute('object_type') == 'volume';
352                                 }
353                         );
354                         list = util.functional.map_list(
355                                 list,
356                                 function (obj) {
357                                         return obj.getAttribute('volume_id');
358                                 }
359                         );
360
361                         alert('spawn volume editor with volume_ids = ' + js2JSON(list));
362                 }
363
364                 function spawn_volume_add_wizard() {
365                         /* <command id="cmd_volume_add" oncommand="volume_add(false,{ 'tree' : 'browse_list_tree', 'refresh_func' : refresh_browse_list });"/> */
366                         JSAN.use('util.widgets'); JSAN.use('util.functional');
367                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
368                         list = util.functional.filter_list(
369                                 list,
370                                 function (obj) {
371                                         return obj.getAttribute('object_type') == 'org_unit';
372                                 }
373                         );
374                         list = util.functional.map_list(
375                                 list,
376                                 function (obj) {
377                                         return obj.getAttribute('ou_id');
378                                 }
379                         );
380
381
382                         alert('spawn volume add wizard with ou_ids = ' + js2JSON(list) );
383                 }
384
385                 function spawn_copy_add_wizard() {
386                         /* <command id="cmd_copy_add" oncommand="copy_add(false,{ 'tree' : 'browse_list_tree', 'refresh_func' : refresh_browse_list });"/> */
387                         JSAN.use('util.widgets'); JSAN.use('util.functional');
388                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
389                         list = util.functional.filter_list(
390                                 list,
391                                 function (obj) {
392                                         return obj.getAttribute('object_type') == 'volume';
393                                 }
394                         );
395                         list = util.functional.map_list(
396                                 list,
397                                 function (obj) {
398                                         return obj.getAttribute('volume_id');
399                                 }
400                         );
401
402
403                         alert('spawn copy add wizard with volume_ids = ' + js2JSON(list));
404                 }
405         ]]>
406         </script>
407
408         <!-- The logic for this app -->
409         <Evergreen id="browse_list_js" />
410
411         <!-- XUL'ified abstraction for logic to attach to widgets -->
412         <commandset id="browse_list_cmds" />
413
414         <!-- Accelerator Keys (Accessor Keys are in DTD's) -->
415         <keyset id="browse_list_keys" />
416
417         <!-- Context menus -->
418         <popupset id="browse_list_popupset" />
419
420         <!-- Layout to be filled in by overlays and javascript -->
421         <groupbox flex="1">
422                 <caption label="Copy Browser"/>
423                 <vbox id="browse_list_vbox" class="test_class"/>
424         </groupbox>
425
426 </window>
427