]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/legacy/_browse.xul
some i18n goodness and fixes. And an extra column for patron lists, and including...
[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                                 mw.G.auth_ses = [ ses() ];
58                                 mw.sdump = function(a,b) { g.error.sdump(a,b); }
59
60                                 find_this_id = g.cgi.param('docid');
61
62                                 JSAN.use('util.network');
63                                 g.network = new util.network();
64
65                                 JSAN.use('OpenILS.data');
66                                 g.data = new OpenILS.data(); g.data.init({'via':'stash'});
67                                 XML_HTTP_SERVER = g.data.server_unadorned;
68
69                                 mw.G.my_orgs = g.data.list.my_aou;
70                                 mw.G.my_orgs_hash = g.data.hash.my_aou;
71                                 mw.G.org_tree = g.data.tree.aou;
72                                 mw.G.user_ou = g.data.hash.aou[ g.data.list.au[0].home_ou() ];
73                                 mw.G.aout_list = g.data.list.aout;
74                                 mw.G.aout_hash = g.data.hash.aout;
75                                 mw.G.ccs_list = g.data.list.ccs;
76                                 mw.G.ccs_hash = g.data.hash.ccs;
77
78                                 var x = document.getElementById('cmd_copy_edit');
79                                 x.setAttribute('oncommand','try{spawn_copy_editor();}catch(E){alert(E);}');
80
81                                 x = document.getElementById('cmd_copy_add');
82                                 x.setAttribute('oncommand','try{spawn_copy_add_wizard();}catch(E){alert(E);}');
83
84                                 x = document.getElementById('cmd_volume_edit');
85                                 x.setAttribute('oncommand','try{spawn_volume_editor();}catch(E){alert(E);}');
86
87                                 x = document.getElementById('cmd_volume_add');
88                                 x.setAttribute('oncommand','try{spawn_volume_add_wizard();}catch(E){alert(E);}');
89
90                                 x = document.getElementById('browse_list_tree');
91                                 x.setAttribute('seltype','multiple');
92
93                                 my_init();
94         
95                         } catch(E) {
96                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
97                                         "system administrator or software developer the following:\nlegacy/_browse.xul\n" + E + '\n';
98                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
99                                 alert(err_msg);
100                         }
101                 }
102
103                 function timer_init() {
104                         return '';
105                 }
106
107                 function timer_elapsed() {
108                         return '';
109                 }
110
111                 function handle_error(err) {
112                         try { alert(js2JSON(err)); } catch(E) { alert(err); }
113                 }
114
115                 function user_request(a,b,c,d) {
116                         return [ g.network.request(a,b,c,d) ];
117                 }
118
119                 function user_async_request(a,b,c,d) {
120                         return [ g.network.request(a,b,c,d) ];
121                 }
122
123                 var counter = {};
124
125                 function counter_init(id) {
126                         counter[id] = 0;
127                 }
128
129                 function counter_incr(id) {
130                         if (! counter[id]) { counter_init(id); }
131                         return ++counter[id];
132                 }
133
134                 function counter_peek(id) {
135                         if (! counter[id]) { return 0; }
136                         return counter[id];
137                 }
138
139                 function disable_widgets() {
140                         var d = document; var idx = 0;
141                         if (arguments[0].nodeName == '#document') {
142                                 idx = 1; d = arguments[0];
143                         }
144                         for (var i = idx; i < arguments.length; i++) {
145                                 if (typeof(arguments[i]) == 'object') {
146                                         arguments[i].disabled = true;
147                                 } else {
148                                         var w = d.getElementById( arguments[i] );
149                                         if (w) { 
150                                                 w.disabled = true; 
151                                         }
152                                 }
153                         }
154                 }
155
156                 function enable_widgets() {
157                         var d = document; var idx = 0;
158                         if (arguments[0].nodeName == '#document') {
159                                 idx = 1; d = arguments[0];
160                         }
161                         for (var i = idx; i < arguments.length; i++) {
162                                 if (typeof(arguments[i]) == 'object') {
163                                         arguments[i].disabled = false;
164                                 } else {
165                                         var w = d.getElementById( arguments[i] );
166                                         if (w) { 
167                                                 w.disabled = false; 
168                                         }
169                                 }
170                         }
171                 }
172
173                 function find_ou(tree,id) {
174                         if (typeof(id)=='object') { id = id.id(); }
175                         if (tree.id()==id) {
176                                 return tree;
177                         }
178                         for (var i in tree.children()) {
179                                 var child = tree.children()[i];
180                                 ou = find_ou( child, id );
181                                 if (ou) { return ou; }
182                         }
183                         return null;
184                 }
185
186                 function yesno(value) {
187                         switch(value) {
188                                 case true: case 'true': case '1': case 'on':
189                                         return 'Yes';
190                                 default: 
191                                         return 'No';
192                         }
193                 }
194
195                 function empty_widget() {
196                         var d; var e;
197                         if (arguments.length == 1) {
198                                 e = arguments[0];
199                         } else {
200                                 d = arguments[0];
201                                 e = arguments[1];
202                                 if (typeof(e) != 'object') { e = d.getElementById(e); }
203                         }
204                         if (typeof(e) != 'object') { dump('Failed on empty_widget\n'); return null; }
205                         while (e.lastChild) { e.removeChild(e.lastChild); }
206                 }
207
208                 function get_list_from_tree_selection() {
209                         var d = document; var tree_w;
210                         if (arguments.length == 1) {
211                                 tree_w = arguments[0];
212                         } else {
213                                 d = arguments[0];
214                                 tree_w = arguments[1];
215                         }
216                         var hitlist;
217                         if (typeof(tree_w) != 'object') {
218                                 hitlist = d.getElementById(tree_w);
219                         } else {
220                                 hitlist = tree_w;
221                         }
222                         var list = [];
223                         var start = new Object();
224                         var end = new Object();
225                         var numRanges = hitlist.view.selection.getRangeCount();
226                         for (var t=0; t<numRanges; t++){
227                                 hitlist.view.selection.getRangeAt(t,start,end);
228                                 for (var v=start.value; v<=end.value; v++){
229                                         var i = hitlist.contentView.getItemAtIndex(v);
230                                         //sdump('D_WIDGETS',i.tagName + '\n');
231                                         list.push( i );
232                                 }
233                         }
234                         return list;
235                 }
236
237                 function filter_list(list,f) {
238                         var new_list = [];
239                         for (var i in list) {
240                                 var t = f( list[i] );
241                                 if (t) new_list.push( list[i] );
242                         }
243                         return new_list;
244                 }
245
246                 function cycle_attribute() {
247                         var d; var e; var a; var v;
248                         if (arguments.length == 3) {
249                                 e = arguments[0];
250                                 a = arguments[1];
251                                 v = arguments[2];
252                         } else {
253                                 d = arguments[0];
254                                 e = arguments[1];
255                                 a = arguments[2];
256                                 v = arguments[3];
257                                 if (typeof(e) != 'object') { e = d.getElementById(e); }
258                         }
259                         try {
260                                 if (typeof(e) != 'object') { throw('typeof e != object : typeof e = ' + typeof(e)); }
261                                 if (!a) { throw('!a : a = ' + a); }
262                                 if (! e.getAttribute(a) ) { throw(' ! e.getAttribute(a) : a = ' + a); }
263                                 if (typeof(v) != 'object') { throw('typeof v != object : typeof v = ' + typeof(v)); }
264
265                                 var toggle = e.getAttribute(a);
266                                 var next_one = false;
267                                 for (var i = 0; i < v.length; i++) {
268                                         if (next_one) {
269                                                 e.setAttribute(a,v[i]);
270                                                 return v[i];
271                                         }
272                                         if (toggle == v[i]) {
273                                                 next_one = true;
274                                         }
275                                 }
276                                 if (next_one) {
277                                         e.setAttribute(a,v[0]);
278                                         return v[0];
279                                 } else {
280                                         throw('current value not in list');
281                                 }
282                         } catch(E) {
283                                 return null;
284                         }
285                 }
286
287
288                 function mapChrome(chrome) {
289                         switch(chrome) {
290                                 case 'chrome://open_ils_staff_client/content/cat/volume_copy_add_wizard.xul':
291                                         return 'chrome://open_ils_staff_client/content/legacy/_volume_copy_add_wizard.xul'; break;
292                                 case 'chrome://open_ils_staff_client/content/cat/copy_add_wizard.xul':
293                                         return 'chrome://open_ils_staff_client/content/legacy/_copy_add_wizard.xul'; break;
294                                 case 'chrome://open_ils_staff_client/content/cat/volume_edit_wizard.xul':
295                                         return 'chrome://open_ils_staff_client/content/legacy/_volume_edit_wizard.xul'; break;
296                         }
297                         return '';
298                 }
299
300                 parentWindow.new_tab = function() { };
301
302                 parentWindow.replace_tab = function(a,b,c) {
303                         if (window.xulG && typeof window.xulG.new_tab == 'function') {
304                                 try {
305                                         var f = window.xulG.new_tab( mapChrome(c), { 'tab_name' : b }, {} );
306                                         return f.contentWindow;
307                                 } catch(E) {
308                                         alert(E);
309                                 }
310                         }
311                 }
312
313                 mw.new_window = function(a,b,c) {
314                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
315                         JSAN.use('util.window'); var win = new util.window();
316                         return win.open( mapChrome(a), b, c );
317                 }
318
319                 function spawn_copy_editor() {
320
321                         JSAN.use('util.widgets'); JSAN.use('util.functional');
322
323                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
324                         list = util.functional.filter_list(
325                                 list,
326                                 function (o) {
327                                         return o.getAttribute('object_type') == 'copy';
328                                 }
329                         );
330
331                         var edit = 0;
332                         try {
333                                 edit = g.network.request(
334                                         api.PERM_MULTI_ORG_CHECK.app,
335                                         api.PERM_MULTI_ORG_CHECK.method,
336                                         [ 
337                                                 ses(), 
338                                                 g.data.list.au[0].id(), 
339                                                 util.functional.map_list(
340                                                         list,
341                                                         function (o) {
342                                                                 return o.getAttribute('ou_id');
343                                                         }
344                                                 ),
345                                                 [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
346                                         ]
347                                 ).length == 0 ? 1 : 0;
348                         } catch(E) {
349                                 g.error.sdump('D_ERROR','batch permission check: ' + E);
350                         }
351
352                         list = util.functional.map_list(
353                                 list,
354                                 function (o) {
355                                         return o.getAttribute('copy_id');
356                                 }
357                         );
358
359                         var title = list.length == 1 ? 'Copy' : 'Copies';
360
361                         JSAN.use('util.window'); var win = new util.window();
362                         g.data.temp = '';
363                         g.data.stash('temp');
364                         var w = win.open(
365                                 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
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                                                 ses(), 
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                                         +'?ou_id_volume_id_callnumber_tuples=' + window.escape( js2JSON(list) ),
430                                 title,
431                                 'chrome,modal,resizable'
432                         );
433
434                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
435                         g.data.stash_retrieve();
436                         var volumes = JSON2js( g.data.temp );
437                         g.error.sdump('D_CAT','in browse, g.data.temp =\n' + g.data.temp);
438                         if (volumes=='') return;
439                 
440                         volumes = util.functional.filter_list(
441                                 volumes,
442                                 function (o) {
443                                         return o.ischanged() == '1';
444                                 }
445                         );
446
447                         volumes = util.functional.map_list(
448                                 volumes,
449                                 function (o) {
450                                         o.record( find_this_id ); // staff client 2 didn't do this.  Does it matter?
451                                         return o;
452                                 }
453                         );
454
455                         if (volumes.length == 0) return;
456
457                         try {
458                                 var r = g.network.request(
459                                         api.FM_ACN_TREE_UPDATE.app,
460                                         api.FM_ACN_TREE_UPDATE.method,
461                                         [ ses(), volumes ]
462                                 );
463                                 /* FIXME -- revisit the return value here */
464                         } catch(E) {
465                                 alert('volume update error: ' + js2JSON(E));
466                         }
467                         refresh_browse_list();
468
469                 }
470
471                 function spawn_volume_add_wizard() {
472                         JSAN.use('util.widgets'); JSAN.use('util.functional');
473                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
474                         list = util.functional.filter_list(
475                                 list,
476                                 function (o) {
477                                         return o.getAttribute('object_type') == 'org_unit';
478                                 }
479                         );
480                         list = util.functional.map_list(
481                                 list,
482                                 function (o) {
483                                         return o.getAttribute('ou_id');
484                                 }
485                         )               
486                         var edit = 0;
487                         try {
488                                 edit = g.network.request(
489                                         api.PERM_MULTI_ORG_CHECK.app,
490                                         api.PERM_MULTI_ORG_CHECK.method,
491                                         [ 
492                                                 ses(), 
493                                                 g.data.list.au[0].id(), 
494                                                 list,
495                                                 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
496                                         ]
497                                 ).length == 0 ? 1 : 0;
498                         } catch(E) {
499                                 g.error.sdump('batch permission check: ' + E);
500                         }
501
502                         if (edit==0) return; // no read-only view for this interface
503
504                         var title = 'Add Volume/Copy';
505
506                         JSAN.use('util.window'); var win = new util.window();
507                         var w = win.open(
508                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
509                                         +'?doc_id=' + window.escape(find_this_id)
510                                         +'&ou_ids=' + window.escape( js2JSON(list) ),
511                                 title,
512                                 'chrome,modal,resizable'
513                         );
514
515                         refresh_browse_list();
516                 }
517
518                 function spawn_copy_add_wizard() {
519                         JSAN.use('util.widgets'); JSAN.use('util.functional');
520                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
521                         list = util.functional.filter_list(
522                                 list,
523                                 function (o) {
524                                         return o.getAttribute('object_type') == 'volume';
525                                 }
526                         );
527                         var copy_shortcut = {};
528                         list = util.functional.map_list(
529                                 list,
530                                 function (o) {
531                                         var ou_id = o.getAttribute('ou_id');
532                                         var volume_id = o.getAttribute('volume_id');
533                                         var label = o.getAttribute('callnumber');
534                                         if (!copy_shortcut[ou_id]) copy_shortcut[ou_id] = {};
535                                         copy_shortcut[ou_id][ label ] = volume_id;
536
537                                         return ou_id;
538                                 }
539                         );
540                         /* quick fix */
541                         list = []; for (var i in copy_shortcut) { list.push( i ); }
542
543                         var edit = 0;
544                         try {
545                                 edit = g.network.request(
546                                         api.PERM_MULTI_ORG_CHECK.app,
547                                         api.PERM_MULTI_ORG_CHECK.method,
548                                         [ 
549                                                 ses(), 
550                                                 g.data.list.au[0].id(), 
551                                                 list,
552                                                 [ 'CREATE_COPY' ]
553                                         ]
554                                 ).length == 0 ? 1 : 0;
555                         } catch(E) {
556                                 g.error.sdump('batch permission check: ' + E);
557                         }
558
559                         if (edit==0) return; // no read-only view for this interface
560
561                         var title = 'Add Copy';
562
563                         JSAN.use('util.window'); var win = new util.window();
564                         var w = win.open(
565                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
566                                         +'?doc_id=' + window.escape(find_this_id)
567                                         +'&ou_ids=' + window.escape( js2JSON(list) )
568                                         +'&copy_shortcut=' + window.escape( js2JSON(copy_shortcut) ),
569                                 title,
570                                 'chrome,modal,resizable'
571                         );
572                         refresh_browse_list();
573                 }
574                 
575                 function mark_volume() {
576                         JSAN.use('util.widgets'); JSAN.use('util.functional');
577                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
578                         list = util.functional.filter_list(
579                                 list,
580                                 function (o) {
581                                         return o.getAttribute('object_type') == 'volume';
582                                 }
583                         );
584                         list = util.functional.map_list(
585                                 list,
586                                 function (o) {
587                                         return o.getAttribute('volume_id');
588                                 }
589                         );
590
591                         g.data.marked_volume = list[0];
592                         g.data.stash('marked_volume');
593                         alert('Volume marked as Copy Transfer Destination');
594                 }
595
596                 function add_to_bucket() {
597
598                         JSAN.use('util.widgets'); JSAN.use('util.functional');
599
600                         var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
601                         list = util.functional.filter_list(
602                                 list,
603                                 function (o) {
604                                         return o.getAttribute('object_type') == 'copy';
605                                 }
606                         );
607
608                         list = util.functional.map_list(
609                                 list,
610                                 function (o) {
611                                         return o.getAttribute('copy_id');
612                                 }
613                         );
614                         
615                         JSAN.use('util.window'); var win = new util.window();
616                         win.open( 
617                                 xulG.url_prefix(urls.XUL_COPY_BUCKETS) 
618                                 + '?copy_ids=' + js2JSON( list ),
619                                 'sel_bucket_win' + win.window_name_increment(),
620                                 'chrome,resizable,modal,center'
621                         );
622                 }
623
624         ]]>
625         </script>
626
627         <!-- The logic for this app -->
628         <Evergreen id="browse_list_js" />
629
630         <!-- XUL'ified abstraction for logic to attach to widgets -->
631         <commandset id="browse_list_cmds" />
632
633         <!-- Accelerator Keys (Accessor Keys are in DTD's) -->
634         <keyset id="browse_list_keys" />
635
636         <!-- Context menus -->
637         <popupset id="browse_list_popupset" />
638
639         <!-- Layout to be filled in by overlays and javascript -->
640         <groupbox flex="1">
641                 <caption label="Holdings Maintenance"/>
642                 <vbox id="browse_list_vbox" class="test_class"/>
643         </groupbox>
644
645 </window>
646