]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/OPEN_ILS_STAFF_CLIENT/legacy/_browse.xul
another great renaming. package names have to be lowercase apparently
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / OPEN_ILS_STAFF_CLIENT / 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/open_ils_staff_client.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         <scripts id="openils_util_scripts"/>
28         <script type="text/javascript" src="chrome://open_ils_staff_client/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.hash.aou[ g.data.list.au[0].home_ou() ];
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://open_ils_staff_client/content/cat/volume_copy_add_wizard.xul':
288                                         return 'chrome://open_ils_staff_client/content/legacy/_volume_copy_add_wizard.xul'; break;
289                                 case 'chrome://open_ils_staff_client/content/cat/copy_add_wizard.xul':
290                                         return 'chrome://open_ils_staff_client/content/legacy/_copy_add_wizard.xul'; break;
291                                 case 'chrome://open_ils_staff_client/content/cat/volume_edit_wizard.xul':
292                                         return 'chrome://open_ils_staff_client/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
318                         JSAN.use('util.widgets'); JSAN.use('util.functional');
319
320                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
321                         list = util.functional.filter_list(
322                                 list,
323                                 function (obj) {
324                                         return obj.getAttribute('object_type') == 'copy';
325                                 }
326                         );
327
328                         var edit = 0;
329                         try {
330                                 edit = g.network.request(
331                                         api.PERM_MULTI_ORG_CHECK.app,
332                                         api.PERM_MULTI_ORG_CHECK.method,
333                                         [ 
334                                                 g.session, 
335                                                 g.data.list.au[0].id(), 
336                                                 util.functional.map_list(
337                                                         list,
338                                                         function (obj) {
339                                                                 return obj.getAttribute('ou_id');
340                                                         }
341                                                 ),
342                                                 [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
343                                         ]
344                                 ).length == 0 ? 1 : 0;
345                         } catch(E) {
346                                 g.error.sdump('batch permission check: ' + E);
347                         }
348
349                         list = util.functional.map_list(
350                                 list,
351                                 function (obj) {
352                                         return obj.getAttribute('copy_id');
353                                 }
354                         );
355
356                         var title = list.length == 1 ? 'Copy' : 'Copies';
357
358                         JSAN.use('util.window'); var win = new util.window();
359                         var w = win.open(
360                                 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
361                                         +'?session='+window.escape(g.session)
362                                         +'&copy_ids='+window.escape(js2JSON(list))
363                                         +'&edit='+edit,
364                                 title,
365                                 'chrome,modal,resizable'
366                         );
367                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
368                         g.data.stash_retrieve();
369                         var copies = JSON2js( g.data.temp );
370                         g.error.sdump('D_CAT','in browse, g.data.temp =\n' + g.data.temp);
371                         if (edit=='1') {
372                                 try {
373                                         var r = g.network.request(
374                                                 api.FM_ACP_FLESHED_BATCH_UPDATE.app,
375                                                 api.FM_ACP_FLESHED_BATCH_UPDATE.method,
376                                                 [ g.session, copies ]
377                                         );
378                                         /* FIXME -- revisit the return value here */
379                                 } catch(E) {
380                                         alert('copy update error: ' + js2JSON(E));
381                                 }
382                                 refresh_browse_list();
383                         }
384                 }
385
386                 function spawn_volume_editor() {
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                         
396                         var edit = 0;
397                         try {
398                                 edit = g.network.request(
399                                         api.PERM_MULTI_ORG_CHECK.app,
400                                         api.PERM_MULTI_ORG_CHECK.method,
401                                         [ 
402                                                 g.session, 
403                                                 g.data.list.au[0].id(), 
404                                                 util.functional.map_list(
405                                                         list,
406                                                         function (obj) {
407                                                                 return obj.getAttribute('ou_id');
408                                                         }
409                                                 ),
410                                                 [ 'UPDATE_VOLUME' ]
411                                         ]
412                                 ).length == 0 ? 1 : 0;
413                         } catch(E) {
414                                 g.error.sdump('batch permission check: ' + E);
415                         }
416
417                         if (edit==0) return; // no read-only view for this interface
418
419                         list = util.functional.map_list(
420                                 list,
421                                 function (obj) {
422                                         return [ obj.getAttribute('ou_id'), obj.getAttribute('volume_id'), obj.getAttribute('callnumber') ];
423                                 }
424                         );
425
426                         var title = list.length == 1 ? 'Volume' : 'Volumes';
427
428                         JSAN.use('util.window'); var win = new util.window();
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                 
442                         volumes = util.functional.filter_list(
443                                 volumes,
444                                 function (obj) {
445                                         return obj.ischanged() == '1';
446                                 }
447                         );
448
449                         volumes = util.functional.map_list(
450                                 volumes,
451                                 function (obj) {
452                                         obj.record( find_this_id ); // staff client 2 didn't do this.  Does it matter?
453                                         return obj;
454                                 }
455                         );
456
457                         if (volumes.length == 0) return;
458
459                         try {
460                                 var r = g.network.request(
461                                         api.FM_ACN_TREE_UPDATE.app,
462                                         api.FM_ACN_TREE_UPDATE.method,
463                                         [ g.session, volumes ]
464                                 );
465                                 /* FIXME -- revisit the return value here */
466                         } catch(E) {
467                                 alert('volume update error: ' + js2JSON(E));
468                         }
469                         refresh_browse_list();
470
471                 }
472
473                 function spawn_volume_add_wizard() {
474                         JSAN.use('util.widgets'); JSAN.use('util.functional');
475                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
476                         list = util.functional.filter_list(
477                                 list,
478                                 function (obj) {
479                                         return obj.getAttribute('object_type') == 'org_unit';
480                                 }
481                         );
482                         list = util.functional.map_list(
483                                 list,
484                                 function (obj) {
485                                         return obj.getAttribute('ou_id');
486                                 }
487                         )               
488                         var edit = 0;
489                         try {
490                                 edit = g.network.request(
491                                         api.PERM_MULTI_ORG_CHECK.app,
492                                         api.PERM_MULTI_ORG_CHECK.method,
493                                         [ 
494                                                 g.session, 
495                                                 g.data.list.au[0].id(), 
496                                                 list,
497                                                 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
498                                         ]
499                                 ).length == 0 ? 1 : 0;
500                         } catch(E) {
501                                 g.error.sdump('batch permission check: ' + E);
502                         }
503
504                         if (edit==0) return; // no read-only view for this interface
505
506                         var title = 'Add Volume/Copy';
507
508                         JSAN.use('util.window'); var win = new util.window();
509                         var w = win.open(
510                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
511                                         +'?session='+window.escape(g.session)
512                                         +'&doc_id=' + window.escape(find_this_id)
513                                         +'&ou_ids=' + window.escape( js2JSON(list) ),
514                                 title,
515                                 'chrome,modal,resizable'
516                         );
517
518                         refresh_browse_list();
519                 }
520
521                 function spawn_copy_add_wizard() {
522                         /* <command id="cmd_copy_add" oncommand="copy_add(false,{ 'tree' : 'browse_list_tree', 'refresh_func' : refresh_browse_list });"/> */
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 (obj) {
528                                         return obj.getAttribute('object_type') == 'volume';
529                                 }
530                         );
531                         list = util.functional.map_list(
532                                 list,
533                                 function (obj) {
534                                         return obj.getAttribute('volume_id');
535                                 }
536                         );
537
538
539                         alert('spawn copy add wizard with volume_ids = ' + js2JSON(list));
540                 }
541         ]]>
542         </script>
543
544         <!-- The logic for this app -->
545         <Evergreen id="browse_list_js" />
546
547         <!-- XUL'ified abstraction for logic to attach to widgets -->
548         <commandset id="browse_list_cmds" />
549
550         <!-- Accelerator Keys (Accessor Keys are in DTD's) -->
551         <keyset id="browse_list_keys" />
552
553         <!-- Context menus -->
554         <popupset id="browse_list_popupset" />
555
556         <!-- Layout to be filled in by overlays and javascript -->
557         <groupbox flex="1">
558                 <caption label="Copy Browser"/>
559                 <vbox id="browse_list_vbox" class="test_class"/>
560         </groupbox>
561
562 </window>
563