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/open_ils_staff_client.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 <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">
32 var parentWindow = {};
37 var org_shortname2id = {};
39 var browse_meter_per = 0;
40 var orgs_with_copies = [];
41 var orgs_with_copies_hash = {};
43 function my_pre_init() {
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');
53 mw.G.main_test_variable = 'Hello World';
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); }
59 find_this_id = g.cgi.param('docid');
61 JSAN.use('util.network');
62 g.network = new util.network();
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;
75 var x = document.getElementById('cmd_copy_edit');
76 x.setAttribute('oncommand','try{spawn_copy_editor();}catch(E){alert(E);}');
78 x = document.getElementById('cmd_copy_add');
79 x.setAttribute('oncommand','try{spawn_copy_add_wizard();}catch(E){alert(E);}');
81 x = document.getElementById('cmd_volume_edit');
82 x.setAttribute('oncommand','try{spawn_volume_editor();}catch(E){alert(E);}');
84 x = document.getElementById('cmd_volume_add');
85 x.setAttribute('oncommand','try{spawn_volume_add_wizard();}catch(E){alert(E);}');
87 x = document.getElementById('browse_list_tree');
88 x.setAttribute('seltype','multiple');
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); }
100 function timer_init() {
104 function timer_elapsed() {
108 function handle_error(err) {
109 try { alert(js2JSON(err)); } catch(E) { alert(err); }
112 function user_request(a,b,c,d) {
113 return [ g.network.request(a,b,c,d) ];
116 function user_async_request(a,b,c,d) {
117 return [ g.network.request(a,b,c,d) ];
122 function counter_init(id) {
126 function counter_incr(id) {
127 if (! counter[id]) { counter_init(id); }
128 return ++counter[id];
131 function counter_peek(id) {
132 if (! counter[id]) { return 0; }
136 function disable_widgets() {
137 var d = document; var idx = 0;
138 if (arguments[0].nodeName == '#document') {
139 idx = 1; d = arguments[0];
141 for (var i = idx; i < arguments.length; i++) {
142 if (typeof(arguments[i]) == 'object') {
143 arguments[i].disabled = true;
145 var w = d.getElementById( arguments[i] );
153 function enable_widgets() {
154 var d = document; var idx = 0;
155 if (arguments[0].nodeName == '#document') {
156 idx = 1; d = arguments[0];
158 for (var i = idx; i < arguments.length; i++) {
159 if (typeof(arguments[i]) == 'object') {
160 arguments[i].disabled = false;
162 var w = d.getElementById( arguments[i] );
170 function find_ou(tree,id) {
171 if (typeof(id)=='object') { id = id.id(); }
175 for (var i in tree.children()) {
176 var child = tree.children()[i];
177 ou = find_ou( child, id );
178 if (ou) { return ou; }
183 function yesno(value) {
185 case true: case 'true': case '1': case 'on':
192 function empty_widget() {
194 if (arguments.length == 1) {
199 if (typeof(e) != 'object') { e = d.getElementById(e); }
201 if (typeof(e) != 'object') { dump('Failed on empty_widget\n'); return null; }
202 while (e.lastChild) { e.removeChild(e.lastChild); }
205 function get_list_from_tree_selection() {
206 var d = document; var tree_w;
207 if (arguments.length == 1) {
208 tree_w = arguments[0];
211 tree_w = arguments[1];
214 if (typeof(tree_w) != 'object') {
215 hitlist = d.getElementById(tree_w);
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');
234 function filter_list(list,f) {
236 for (var i in list) {
237 var t = f( list[i] );
238 if (t) new_list.push( list[i] );
243 function cycle_attribute() {
244 var d; var e; var a; var v;
245 if (arguments.length == 3) {
254 if (typeof(e) != 'object') { e = d.getElementById(e); }
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)); }
262 var toggle = e.getAttribute(a);
263 var next_one = false;
264 for (var i = 0; i < v.length; i++) {
266 e.setAttribute(a,v[i]);
269 if (toggle == v[i]) {
274 e.setAttribute(a,v[0]);
277 throw('current value not in list');
285 function mapChrome(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;
297 parentWindow.new_tab = function() { };
299 parentWindow.replace_tab = function(a,b,c) {
300 if (window.xulG && typeof window.xulG.new_tab == 'function') {
302 var f = window.xulG.new_tab( mapChrome(c), { 'tab_name' : b }, {} );
303 return f.contentWindow;
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 );
316 function spawn_copy_editor() {
318 JSAN.use('util.widgets'); JSAN.use('util.functional');
320 var list = util.widgets.get_list_from_tree_selection('browse_list_tree');
321 list = util.functional.filter_list(
324 return obj.getAttribute('object_type') == 'copy';
330 edit = g.network.request(
331 api.PERM_MULTI_ORG_CHECK.app,
332 api.PERM_MULTI_ORG_CHECK.method,
335 g.data.list.au[0].id(),
336 util.functional.map_list(
339 return obj.getAttribute('ou_id');
342 [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
344 ).length == 0 ? 1 : 0;
346 g.error.sdump('batch permission check: ' + E);
349 list = util.functional.map_list(
352 return obj.getAttribute('copy_id');
356 var title = list.length == 1 ? 'Copy' : 'Copies';
358 JSAN.use('util.window'); var win = new util.window();
360 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
361 +'?session='+window.escape(g.session)
362 +'©_ids='+window.escape(js2JSON(list))
365 'chrome,modal,resizable'
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);
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 ]
378 /* FIXME -- revisit the return value here */
380 alert('copy update error: ' + js2JSON(E));
382 refresh_browse_list();
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(
392 return obj.getAttribute('object_type') == 'volume';
398 edit = g.network.request(
399 api.PERM_MULTI_ORG_CHECK.app,
400 api.PERM_MULTI_ORG_CHECK.method,
403 g.data.list.au[0].id(),
404 util.functional.map_list(
407 return obj.getAttribute('ou_id');
412 ).length == 0 ? 1 : 0;
414 g.error.sdump('batch permission check: ' + E);
417 if (edit==0) return; // no read-only view for this interface
419 list = util.functional.map_list(
422 return [ obj.getAttribute('ou_id'), obj.getAttribute('volume_id'), obj.getAttribute('callnumber') ];
426 var title = list.length == 1 ? 'Volume' : 'Volumes';
428 JSAN.use('util.window'); var win = new util.window();
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) ),
434 'chrome,modal,resizable'
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);
442 volumes = util.functional.filter_list(
445 return obj.ischanged() == '1';
449 volumes = util.functional.map_list(
452 obj.record( find_this_id ); // staff client 2 didn't do this. Does it matter?
457 if (volumes.length == 0) return;
460 var r = g.network.request(
461 api.FM_ACN_TREE_UPDATE.app,
462 api.FM_ACN_TREE_UPDATE.method,
463 [ g.session, volumes ]
465 /* FIXME -- revisit the return value here */
467 alert('volume update error: ' + js2JSON(E));
469 refresh_browse_list();
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(
479 return obj.getAttribute('object_type') == 'org_unit';
482 list = util.functional.map_list(
485 return obj.getAttribute('ou_id');
490 edit = g.network.request(
491 api.PERM_MULTI_ORG_CHECK.app,
492 api.PERM_MULTI_ORG_CHECK.method,
495 g.data.list.au[0].id(),
497 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
499 ).length == 0 ? 1 : 0;
501 g.error.sdump('batch permission check: ' + E);
504 if (edit==0) return; // no read-only view for this interface
506 var title = 'Add Volume/Copy';
508 JSAN.use('util.window'); var win = new util.window();
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) ),
515 'chrome,modal,resizable'
518 refresh_browse_list();
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(
528 return obj.getAttribute('object_type') == 'volume';
531 list = util.functional.map_list(
534 return obj.getAttribute('volume_id');
539 alert('spawn copy add wizard with volume_ids = ' + js2JSON(list));
544 <!-- The logic for this app -->
545 <Evergreen id="browse_list_js" />
547 <!-- XUL'ified abstraction for logic to attach to widgets -->
548 <commandset id="browse_list_cmds" />
550 <!-- Accelerator Keys (Accessor Keys are in DTD's) -->
551 <keyset id="browse_list_keys" />
553 <!-- Context menus -->
554 <popupset id="browse_list_popupset" />
556 <!-- Layout to be filled in by overlays and javascript -->
558 <caption label="Copy Browser"/>
559 <vbox id="browse_list_vbox" class="test_class"/>