2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Cataloger's Search Result Screen -->
5 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
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"?>
10 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
12 <!DOCTYPE window SYSTEM "chrome://open_ils_staff_client/locale/lang.dtd">
14 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
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"?>
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">
24 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
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">
34 var parentWindow = {};
39 var org_shortname2id = {};
41 var browse_meter_per = 0;
42 var orgs_with_copies = [];
43 var orgs_with_copies_hash = {};
45 function my_pre_init() {
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');
55 mw.G.main_test_variable = 'Hello World';
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); }
61 find_this_id = g.cgi.param('docid');
63 JSAN.use('util.network');
64 g.network = new util.network();
66 JSAN.use('OpenILS.data');
67 g.data = new OpenILS.data(); g.data.init({'via':'stash'});
68 mw.G.my_orgs = g.data.list.my_aou;
69 mw.G.my_orgs_hash = g.data.hash.my_aou;
70 mw.G.org_tree = g.data.tree.aou;
71 mw.G.user_ou = g.data.hash.aou[ g.data.list.au[0].home_ou() ];
72 mw.G.aout_list = g.data.list.aout;
73 mw.G.aout_hash = g.data.hash.aout;
74 mw.G.ccs_list = g.data.list.ccs;
75 mw.G.ccs_hash = g.data.hash.ccs;
77 var x = document.getElementById('cmd_copy_edit');
78 x.setAttribute('oncommand','try{spawn_copy_editor();}catch(E){alert(E);}');
80 x = document.getElementById('cmd_copy_add');
81 x.setAttribute('oncommand','try{spawn_copy_add_wizard();}catch(E){alert(E);}');
83 x = document.getElementById('cmd_volume_edit');
84 x.setAttribute('oncommand','try{spawn_volume_editor();}catch(E){alert(E);}');
86 x = document.getElementById('cmd_volume_add');
87 x.setAttribute('oncommand','try{spawn_volume_add_wizard();}catch(E){alert(E);}');
89 x = document.getElementById('browse_list_tree');
90 x.setAttribute('seltype','multiple');
95 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
96 "system administrator or software developer the following:\nlegacy/_browse.xul\n" + E + '\n';
97 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
102 function timer_init() {
106 function timer_elapsed() {
110 function handle_error(err) {
111 try { alert(js2JSON(err)); } catch(E) { alert(err); }
114 function user_request(a,b,c,d) {
115 return [ g.network.request(a,b,c,d) ];
118 function user_async_request(a,b,c,d) {
119 return [ g.network.request(a,b,c,d) ];
124 function counter_init(id) {
128 function counter_incr(id) {
129 if (! counter[id]) { counter_init(id); }
130 return ++counter[id];
133 function counter_peek(id) {
134 if (! counter[id]) { return 0; }
138 function disable_widgets() {
139 var d = document; var idx = 0;
140 if (arguments[0].nodeName == '#document') {
141 idx = 1; d = arguments[0];
143 for (var i = idx; i < arguments.length; i++) {
144 if (typeof(arguments[i]) == 'object') {
145 arguments[i].disabled = true;
147 var w = d.getElementById( arguments[i] );
155 function enable_widgets() {
156 var d = document; var idx = 0;
157 if (arguments[0].nodeName == '#document') {
158 idx = 1; d = arguments[0];
160 for (var i = idx; i < arguments.length; i++) {
161 if (typeof(arguments[i]) == 'object') {
162 arguments[i].disabled = false;
164 var w = d.getElementById( arguments[i] );
172 function find_ou(tree,id) {
173 if (typeof(id)=='object') { id = id.id(); }
177 for (var i in tree.children()) {
178 var child = tree.children()[i];
179 ou = find_ou( child, id );
180 if (ou) { return ou; }
185 function yesno(value) {
187 case true: case 'true': case '1': case 'on':
194 function empty_widget() {
196 if (arguments.length == 1) {
201 if (typeof(e) != 'object') { e = d.getElementById(e); }
203 if (typeof(e) != 'object') { dump('Failed on empty_widget\n'); return null; }
204 while (e.lastChild) { e.removeChild(e.lastChild); }
207 function get_list_from_tree_selection() {
208 var d = document; var tree_w;
209 if (arguments.length == 1) {
210 tree_w = arguments[0];
213 tree_w = arguments[1];
216 if (typeof(tree_w) != 'object') {
217 hitlist = d.getElementById(tree_w);
222 var start = new Object();
223 var end = new Object();
224 var numRanges = hitlist.view.selection.getRangeCount();
225 for (var t=0; t<numRanges; t++){
226 hitlist.view.selection.getRangeAt(t,start,end);
227 for (var v=start.value; v<=end.value; v++){
228 var i = hitlist.contentView.getItemAtIndex(v);
229 //sdump('D_WIDGETS',i.tagName + '\n');
236 function filter_list(list,f) {
238 for (var i in list) {
239 var t = f( list[i] );
240 if (t) new_list.push( list[i] );
245 function cycle_attribute() {
246 var d; var e; var a; var v;
247 if (arguments.length == 3) {
256 if (typeof(e) != 'object') { e = d.getElementById(e); }
259 if (typeof(e) != 'object') { throw('typeof e != object : typeof e = ' + typeof(e)); }
260 if (!a) { throw('!a : a = ' + a); }
261 if (! e.getAttribute(a) ) { throw(' ! e.getAttribute(a) : a = ' + a); }
262 if (typeof(v) != 'object') { throw('typeof v != object : typeof v = ' + typeof(v)); }
264 var toggle = e.getAttribute(a);
265 var next_one = false;
266 for (var i = 0; i < v.length; i++) {
268 e.setAttribute(a,v[i]);
271 if (toggle == v[i]) {
276 e.setAttribute(a,v[0]);
279 throw('current value not in list');
287 function mapChrome(chrome) {
289 case 'chrome://open_ils_staff_client/content/cat/volume_copy_add_wizard.xul':
290 return 'chrome://open_ils_staff_client/content/legacy/_volume_copy_add_wizard.xul'; break;
291 case 'chrome://open_ils_staff_client/content/cat/copy_add_wizard.xul':
292 return 'chrome://open_ils_staff_client/content/legacy/_copy_add_wizard.xul'; break;
293 case 'chrome://open_ils_staff_client/content/cat/volume_edit_wizard.xul':
294 return 'chrome://open_ils_staff_client/content/legacy/_volume_edit_wizard.xul'; break;
299 parentWindow.new_tab = function() { };
301 parentWindow.replace_tab = function(a,b,c) {
302 if (window.xulG && typeof window.xulG.new_tab == 'function') {
304 var f = window.xulG.new_tab( mapChrome(c), { 'tab_name' : b }, {} );
305 return f.contentWindow;
312 mw.new_window = function(a,b,c) {
313 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
314 JSAN.use('util.window'); var win = new util.window();
315 return win.open( mapChrome(a), b, c );
318 function spawn_copy_editor() {
320 JSAN.use('util.widgets'); JSAN.use('util.functional');
322 var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
323 list = util.functional.filter_list(
326 return o.getAttribute('object_type') == 'copy';
332 edit = g.network.request(
333 api.PERM_MULTI_ORG_CHECK.app,
334 api.PERM_MULTI_ORG_CHECK.method,
337 g.data.list.au[0].id(),
338 util.functional.map_list(
341 return o.getAttribute('ou_id');
344 [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
346 ).length == 0 ? 1 : 0;
348 g.error.sdump('D_ERROR','batch permission check: ' + E);
351 list = util.functional.map_list(
354 return o.getAttribute('copy_id');
358 var title = list.length == 1 ? 'Copy' : 'Copies';
360 JSAN.use('util.window'); var win = new util.window();
362 g.data.stash('temp');
364 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
365 +'?session='+window.escape(g.session)
366 +'©_ids='+window.escape(js2JSON(list))
367 +'&docid='+window.escape(find_this_id)
371 'chrome,modal,resizable'
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();
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(
388 return o.getAttribute('object_type') == 'volume';
394 edit = g.network.request(
395 api.PERM_MULTI_ORG_CHECK.app,
396 api.PERM_MULTI_ORG_CHECK.method,
399 g.data.list.au[0].id(),
400 util.functional.map_list(
403 return o.getAttribute('ou_id');
408 ).length == 0 ? 1 : 0;
410 g.error.sdump('batch permission check: ' + E);
413 if (edit==0) return; // no read-only view for this interface
415 list = util.functional.map_list(
418 return [ o.getAttribute('ou_id'), o.getAttribute('volume_id'), o.getAttribute('callnumber') ];
422 var title = list.length == 1 ? 'Volume' : 'Volumes';
424 JSAN.use('util.window'); var win = new util.window();
426 g.data.stash('temp');
428 window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR)
429 +'?session='+window.escape(g.session)
430 +'&ou_id_volume_id_callnumber_tuples=' + window.escape( js2JSON(list) ),
432 'chrome,modal,resizable'
435 /* FIXME -- need to unique the temp space, and not rely on modalness of window */
436 g.data.stash_retrieve();
437 var volumes = JSON2js( g.data.temp );
438 g.error.sdump('D_CAT','in browse, g.data.temp =\n' + g.data.temp);
439 if (volumes=='') return;
441 volumes = util.functional.filter_list(
444 return o.ischanged() == '1';
448 volumes = util.functional.map_list(
451 o.record( find_this_id ); // staff client 2 didn't do this. Does it matter?
456 if (volumes.length == 0) return;
459 var r = g.network.request(
460 api.FM_ACN_TREE_UPDATE.app,
461 api.FM_ACN_TREE_UPDATE.method,
462 [ g.session, volumes ]
464 /* FIXME -- revisit the return value here */
466 alert('volume update error: ' + js2JSON(E));
468 refresh_browse_list();
472 function spawn_volume_add_wizard() {
473 JSAN.use('util.widgets'); JSAN.use('util.functional');
474 var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
475 list = util.functional.filter_list(
478 return o.getAttribute('object_type') == 'org_unit';
481 list = util.functional.map_list(
484 return o.getAttribute('ou_id');
489 edit = g.network.request(
490 api.PERM_MULTI_ORG_CHECK.app,
491 api.PERM_MULTI_ORG_CHECK.method,
494 g.data.list.au[0].id(),
496 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
498 ).length == 0 ? 1 : 0;
500 g.error.sdump('batch permission check: ' + E);
503 if (edit==0) return; // no read-only view for this interface
505 var title = 'Add Volume/Copy';
507 JSAN.use('util.window'); var win = new util.window();
509 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
510 +'?session='+window.escape(g.session)
511 +'&doc_id=' + window.escape(find_this_id)
512 +'&ou_ids=' + window.escape( js2JSON(list) ),
514 'chrome,modal,resizable'
517 refresh_browse_list();
520 function spawn_copy_add_wizard() {
521 JSAN.use('util.widgets'); JSAN.use('util.functional');
522 var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
523 list = util.functional.filter_list(
526 return o.getAttribute('object_type') == 'volume';
529 var copy_shortcut = {};
530 list = util.functional.map_list(
533 var cn = g.network.simple_request(
535 o.getAttribute('volume_id')
537 var ou_id = cn.owning_lib();
538 var label = cn.label();
539 if (!copy_shortcut[ou_id]) copy_shortcut[ou_id] = {};
540 copy_shortcut[ou_id][label] = 1;
548 edit = g.network.request(
549 api.PERM_MULTI_ORG_CHECK.app,
550 api.PERM_MULTI_ORG_CHECK.method,
553 g.data.list.au[0].id(),
557 ).length == 0 ? 1 : 0;
559 g.error.sdump('batch permission check: ' + E);
562 if (edit==0) return; // no read-only view for this interface
564 var title = 'Add Copy';
566 JSAN.use('util.window'); var win = new util.window();
568 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
569 +'?session='+window.escape(g.session)
570 +'&doc_id=' + window.escape(find_this_id)
571 +'&ou_ids=' + window.escape( js2JSON(list) ),
572 +'©_shortcut=' + window.escape( js2JSON(copy_shortcut) )
574 'chrome,modal,resizable'
577 refresh_browse_list();
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(
586 return o.getAttribute('object_type') == 'volume';
589 list = util.functional.map_list(
592 return o.getAttribute('volume_id');
596 g.data.marked_volume = list[0];
597 g.data.stash('marked_volume');
598 alert('Volume marked as Copy Transfer Destination');
601 function add_to_bucket() {
603 JSAN.use('util.widgets'); JSAN.use('util.functional');
605 var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
606 list = util.functional.filter_list(
609 return o.getAttribute('object_type') == 'copy';
613 list = util.functional.map_list(
616 return o.getAttribute('copy_id');
620 JSAN.use('util.window'); var win = new util.window();
622 xulG.url_prefix(urls.XUL_COPY_BUCKETS)
623 + '?session=' + window.escape(g.session)
624 + '©_ids=' + js2JSON( list ),
625 'sel_bucket_win' + win.window_name_increment(),
626 'chrome,resizable,modal,center'
633 <!-- The logic for this app -->
634 <Evergreen id="browse_list_js" />
636 <!-- XUL'ified abstraction for logic to attach to widgets -->
637 <commandset id="browse_list_cmds" />
639 <!-- Accelerator Keys (Accessor Keys are in DTD's) -->
640 <keyset id="browse_list_keys" />
642 <!-- Context menus -->
643 <popupset id="browse_list_popupset" />
645 <!-- Layout to be filled in by overlays and javascript -->
647 <caption label="Copy Browser"/>
648 <vbox id="browse_list_vbox" class="test_class"/>