1 dump('entering cat.copy_browser.js\n');
3 if (typeof cat == 'undefined') cat = {};
4 cat.copy_browser = function (params) {
6 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
7 JSAN.use('util.error'); this.error = new util.error();
9 dump('cat.copy_browser: ' + E + '\n');
13 cat.copy_browser.prototype = {
20 'init' : function( params ) {
23 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
26 obj.docid = params.docid;
28 JSAN.use('util.network'); obj.network = new util.network();
29 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
30 JSAN.use('util.controller'); obj.controller = new util.controller();
34 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
37 function() { obj.list.clipboard(); }
41 function() { alert('Not Yet Implemented'); }
43 'cmd_show_my_libs' : [
49 'cmd_show_all_libs' : [
55 'cmd_show_libs_with_copies' : [
58 obj.show_libs_with_copies();
68 'sel_mark_items_damaged' : [
71 JSAN.use('cat.util'); JSAN.use('util.functional');
73 var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; });
75 list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; });
77 cat.util.mark_item_damaged( list );
82 'sel_mark_items_missing' : [
85 JSAN.use('cat.util'); JSAN.use('util.functional');
87 var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; });
89 list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; });
91 cat.util.mark_item_missing( list );
99 JSAN.use('util.functional');
101 var list = util.functional.filter_list(
104 return o.split(/_/)[0] == 'acp';
108 list = util.functional.map_list(
111 return { 'copy_id' : o.split(/_/)[1] };
115 JSAN.use('circ.util');
116 circ.util.show_last_few_circs(list);
119 'sel_copy_details' : [
122 JSAN.use('util.functional');
124 var list = util.functional.filter_list(
127 return o.split(/_/)[0] == 'acp';
131 list = util.functional.map_list(
134 return o.split(/_/)[1];
138 JSAN.use('circ.util');
139 for (var i = 0; i < list.length; i++) {
140 circ.util.show_copy_details( list[i] );
148 JSAN.use('util.functional');
149 var list = util.functional.map_list(
150 util.functional.filter_list(
153 return o.split(/_/)[0] == 'acn';
157 return o.split(/_/)[1];
160 if (list.length == 0) return;
162 var copy_shortcut = {};
163 list = util.functional.map_list(
166 var ou_id = obj.map_acn['acn_' + o].owning_lib();
168 var label = obj.map_acn['acn_' + o].label();
169 if (!copy_shortcut[ou_id]) copy_shortcut[ou_id] = {};
170 copy_shortcut[ou_id][ label ] = volume_id;
175 /* quick fix */ /* what was this fixing? */
176 list = []; for (var i in copy_shortcut) { list.push( i ); }
180 edit = obj.network.request(
181 api.PERM_MULTI_ORG_CHECK.app,
182 api.PERM_MULTI_ORG_CHECK.method,
185 obj.data.list.au[0].id(),
189 ).length == 0 ? 1 : 0;
191 obj.error.sdump('D_ERROR','batch permission check: ' + E);
194 if (edit==0) return; // no read-only view for this interface
196 var title = 'Add Item';
198 JSAN.use('util.window'); var win = new util.window();
200 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR),
201 //+'?doc_id=' + window.escape(obj.docid)
202 //+'&ou_ids=' + window.escape( js2JSON(list) )
203 //+'©_shortcut=' + window.escape( js2JSON(copy_shortcut) ),
207 w.refresh = function() { obj.refresh_list(); }
208 w.xulG = { 'doc_id':obj.docid, 'ou_ids' : list, 'copy_shortcut' : copy_shortcut };
210 obj.error.standard_unexpected_error_alert('copy browser -> add copies',E);
214 'cmd_add_items_to_buckets' : [
218 JSAN.use('util.functional');
220 var list = util.functional.filter_list(
223 return o.split(/_/)[0] == 'acp';
227 list = util.functional.map_list(
230 return o.split(/_/)[1];
234 JSAN.use('cat.util');
235 cat.util.add_copies_to_bucket( list );
238 obj.error.standard_unexpected_error_alert('copy browser -> add copies to bucket',E);
242 'cmd_replace_barcode' : [
246 JSAN.use('util.functional');
248 var list = util.functional.filter_list(
251 return o.split(/_/)[0] == 'acp';
255 list = util.functional.map_list(
258 return obj.map_acp[ o ].barcode();
262 JSAN.use('cat.util');
263 for (var i = 0; i < list.length; i++) {
265 cat.util.replace_barcode(list[i]);
267 obj.error.standard_unexpected_error_alert('Barcode ' +list[i] + ' not likely replaced.',E);
273 obj.error.standard_unexpected_error_alert('copy browser -> replace barcode',E);
282 JSAN.use('util.functional');
284 var list = util.functional.filter_list(
287 return o.split(/_/)[0] == 'acp';
291 list = util.functional.map_list(
294 return o.split(/_/)[1];
298 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
302 obj.error.standard_unexpected_error_alert('Copy Browser -> Edit Items',E);
306 'cmd_delete_items' : [
310 JSAN.use('util.functional');
312 var list = util.functional.filter_list(
315 return o.split(/_/)[0] == 'acp';
319 list = util.functional.map_list(
322 return JSON2js( js2JSON( obj.map_acp[ 'acp_' + o.split(/_/)[1] ] ) );
326 var r = obj.error.yns_alert('Are you sure you would like to delete ' + (list.length != 1 ? 'these ' + list.length + ' items' : 'this one item') + '?', 'Delete Items?', 'Delete', 'Cancel', null, 'Check here to confirm this action');
329 var acn_hash = {}; var acn_list = [];
330 for (var i = 0; i < list.length; i++) {
331 list[i].isdeleted('1');
332 var acn_id = list[i].call_number();
333 if ( ! acn_hash[ acn_id ] ) {
334 acn_hash[ acn_id ] = obj.map_acn[ 'acn_' + acn_id ];
335 acn_hash[ acn_id ].copies( [] );
337 var temp = acn_hash[ acn_id ].copies();
338 temp.push( list[i] );
339 acn_hash[ acn_id ].copies( temp );
341 for (var i in acn_hash) acn_list.push( acn_hash[i] );
342 var robj = obj.network.simple_request(
343 'FM_ACN_TREE_UPDATE',
344 [ ses(), acn_list, true ],
347 'title' : 'Override Delete Failure?',
348 'overridable_events' : [
349 1208 /* TITLE_LAST_COPY */,
350 1227 /* COPY_DELETE_WARNING */,
354 if (robj == null) throw(robj);
355 if (typeof robj.ilsevent != 'undefined') {
356 if ( (robj.ilsevent != 0) && (robj.ilsevent != 1227 /* COPY_DELETE_WARNING */) && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */) ) throw(robj);
358 alert('Action complete.');
364 obj.error.standard_unexpected_error_alert('copy browser -> delete items',E);
369 'cmd_print_spine_labels' : [
373 JSAN.use('util.functional');
375 var list = util.functional.filter_list(
378 return o.split(/_/)[0] == 'acp';
382 list = util.functional.map_list(
385 return obj.map_acp[ o ];
389 obj.data.temp_barcodes_for_labels = util.functional.map_list( list, function(o){return o.barcode();}) ;
390 obj.data.stash('temp_barcodes_for_labels');
392 xulG.url_prefix( urls.XUL_SPINE_LABEL ),
393 { 'tab_name' : 'Spine Labels' },
397 obj.error.standard_unexpected_error_alert('copy browser -> Spine Labels',E);
401 'cmd_add_volumes' : [
405 JSAN.use('util.functional');
406 var list = util.functional.filter_list(
409 return o.split(/_/)[0] == 'aou';
412 list = util.functional.map_list(
415 return o.split(/_/)[1];
420 edit = obj.network.request(
421 api.PERM_MULTI_ORG_CHECK.app,
422 api.PERM_MULTI_ORG_CHECK.method,
425 obj.data.list.au[0].id(),
427 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
429 ).length == 0 ? 1 : 0;
431 obj.error.sdump('D_ERROR','batch permission check: ' + E);
435 alert("You don't have permission to add volumes to that library.");
436 return; // no read-only view for this interface
439 var title = 'Add Volume/Item';
441 JSAN.use('util.window'); var win = new util.window();
443 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR),
444 //+'?doc_id=' + window.escape(obj.docid)
445 //+'&ou_ids=' + window.escape( js2JSON(list) ),
450 w.refresh = function() { obj.refresh_list() };
451 w.xulG = { 'doc_id' : obj.docid, 'ou_ids' : list };
453 obj.error.standard_unexpected_error_alert('copy browser -> add volumes',E);
457 'cmd_edit_volumes' : [
461 JSAN.use('util.functional');
462 var list = util.functional.map_list(
463 util.functional.filter_list(
466 return o.split(/_/)[0] == 'acn';
470 return o.split(/_/)[1];
473 if (list.length == 0) return;
477 edit = obj.network.request(
478 api.PERM_MULTI_ORG_CHECK.app,
479 api.PERM_MULTI_ORG_CHECK.method,
482 obj.data.list.au[0].id(),
483 util.functional.map_list(
486 return obj.map_acn[ 'acn_' + o ].owning_lib();
491 ).length == 0 ? 1 : 0;
493 obj.error.sdump('D_ERROR','batch permission check: ' + E);
497 alert("You don't have permission to edit this volume.");
498 return; // no read-only view for this interface
501 list = util.functional.map_list(
504 var my_acn = obj.map_acn['acn_' + o];
505 return function(r){return r;}(my_acn);
509 var title = list.length == 1 ? 'Volume' : 'Volumes';
511 JSAN.use('util.window'); var win = new util.window();
512 //obj.data.volumes_temp = js2JSON( list );
513 //obj.data.stash('volumes_temp');
514 var my_xulG = win.open(
515 window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR),
517 'chrome,modal,resizable',
521 /* FIXME -- need to unique the temp space, and not rely on modalness of window */
522 //obj.data.stash_retrieve();
523 var volumes = my_xulG.volumes;
524 if (!volumes) return;
526 volumes = util.functional.filter_list(
529 return o.ischanged() == '1';
533 volumes = util.functional.map_list(
536 o.record( obj.docid ); // staff client 2 did not do this. Does it matter?
541 if (volumes.length == 0) return;
544 var r = obj.network.request(
545 api.FM_ACN_TREE_UPDATE.app,
546 api.FM_ACN_TREE_UPDATE.method,
547 [ ses(), volumes, true ]
549 if (typeof r.ilsevent != 'undefined') {
550 switch(Number(r.ilsevent)) {
551 case 1705 /* VOLUME_LABEL_EXISTS */ :
552 alert("Edit failed: You tried to change a volume's callnumber to one that is already in use for the given library. You should transfer the items to the desired callnumber instead.");
557 alert('Volumes modified.');
560 obj.error.standard_unexpected_error_alert('volume update error: ',E);
565 obj.error.standard_unexpected_error_alert('Copy Browser -> Volume Edit',E);
569 'cmd_delete_volumes' : [
573 JSAN.use('util.functional');
575 var list = util.functional.filter_list(
578 return o.split(/_/)[0] == 'acn';
582 list = util.functional.map_list(
585 return JSON2js( js2JSON( obj.map_acn[ 'acn_' + o.split(/_/)[1] ] ) );
589 var r = obj.error.yns_alert('Are you sure you would like to delete ' + (list.length != 1 ? 'these ' + list.length + ' volumes' : 'this one volume') + '?', 'Delete Volumes?', 'Delete', 'Cancel', null, 'Check here to confirm this action');
592 for (var i = 0; i < list.length; i++) {
593 list[i].isdeleted('1');
595 var robj = obj.network.simple_request(
596 'FM_ACN_TREE_UPDATE',
597 [ ses(), list, true ],
600 'title' : 'Override Delete Failure?',
601 'overridable_events' : [
605 if (robj == null) throw(robj);
606 if (typeof robj.ilsevent != 'undefined') {
607 if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
608 alert('You must delete all the copies on the volume before you may delete the volume itself.');
611 if (robj.ilsevent != 0) throw(robj);
613 alert('Volumes deleted.');
617 obj.error.standard_unexpected_error_alert('copy browser -> delete volumes',E);
623 'cmd_mark_library' : [
627 var list = util.functional.filter_list(
630 return o.split(/_/)[0] == 'aou';
634 list = util.functional.map_list(
637 return o.split(/_/)[1];
641 if (list.length == 1) {
642 obj.data.marked_library = { 'lib' : list[0], 'docid' : obj.docid };
643 obj.data.stash('marked_library');
644 alert('Library + Record marked as Volume Transfer Destination');
646 obj.error.yns_alert('Choose just one Library to mark as Volume Transfer Destination','Limit Selection','OK',null,null,'Check here to confirm this dialog');
649 obj.error.standard_unexpected_error_alert('copy browser -> mark library',E);
654 'cmd_mark_volume' : [
658 var list = util.functional.filter_list(
661 return o.split(/_/)[0] == 'acn';
665 list = util.functional.map_list(
668 return o.split(/_/)[1];
672 if (list.length == 1) {
673 obj.data.marked_volume = list[0];
674 obj.data.stash('marked_volume');
675 alert('Volume marked as Item Transfer Destination');
677 obj.error.yns_alert('Choose just one Volume to mark as Item Transfer Destination','Limit Selection','OK',null,null,'Check here to confirm this dialog');
680 obj.error.standard_unexpected_error_alert('copy browser -> mark volume',E);
684 'cmd_refresh_list' : [
690 'cmd_transfer_volume' : [
694 obj.data.stash_retrieve();
695 if (!obj.data.marked_library) {
696 alert('Please mark a library as the destination from within holdings maintenance and then try this again.');
700 JSAN.use('util.functional');
702 var list = util.functional.filter_list(
705 return o.split(/_/)[0] == 'acn';
709 list = util.functional.map_list(
712 return o.split(/_/)[1];
716 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
717 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
718 xml += '<description>Transfer volumes ';
720 xml += util.functional.map_list(
723 return obj.map_acn[ 'acn_' + o ].label();
727 xml += ' to library ' + obj.data.hash.aou[ obj.data.marked_library.lib ].shortname();
728 xml += ' on the following record?</description>';
729 xml += '<hbox><button label="Transfer" name="fancy_submit"/>';
730 xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
731 xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + obj.data.marked_library.docid + '"/>';
733 JSAN.use('OpenILS.data');
734 var data = new OpenILS.data(); data.init({'via':'stash'});
735 //data.temp_transfer = xml; data.stash('temp_transfer');
736 JSAN.use('util.window'); var win = new util.window();
737 var fancy_prompt_data = win.open(
738 urls.XUL_FANCY_PROMPT,
739 //+ '?xml_in_stash=temp_transfer'
740 //+ '&title=' + window.escape('Volume Transfer'),
741 'fancy_prompt', 'chrome,resizable,modal,width=500,height=300',
742 { 'xml' : xml, 'title' : 'Volume Transfer' }
745 if (fancy_prompt_data.fancy_status == 'incomplete') { alert('Transfer Aborted'); return; }
747 var robj = obj.network.simple_request(
749 [ ses(), { 'docid' : obj.data.marked_library.docid, 'lib' : obj.data.marked_library.lib, 'volumes' : list } ],
752 'title' : 'Override Volume Transfer Failure?',
753 'overridable_events' : [
754 1208 /* TITLE_LAST_COPY */,
755 1219 /* COPY_REMOTE_CIRC_LIB */,
760 if (typeof robj.ilsevent != 'undefined') {
761 if (robj.ilsevent == 1221 /* ORG_CANNOT_HAVE_VOLS */) {
762 alert('That destination cannot have volumes.');
767 alert('Volumes transferred.');
771 obj.error.standard_unexpected_error_alert('All volumes not likely transferred.',E);
777 'cmd_transfer_items' : [
781 obj.data.stash_retrieve();
782 if (!obj.data.marked_volume) {
783 alert('Please mark a volume as the destination from within holdings maintenance and then try this again.');
787 JSAN.use('util.functional');
789 var list = util.functional.filter_list(
792 return o.split(/_/)[0] == 'acp';
796 list = util.functional.map_list(
799 return o.split(/_/)[1];
803 var volume = obj.network.simple_request('FM_ACN_RETRIEVE',[ obj.data.marked_volume ]);
805 JSAN.use('cat.util'); cat.util.transfer_copies( {
807 'docid' : volume.record(),
808 'volume_label' : volume.label(),
809 'owning_lib' : volume.owning_lib(),
813 obj.error.standard_unexpected_error_alert('All copies not likely transferred.',E);
822 obj.list_init(params);
824 obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
825 if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
826 JSAN.use('util.functional');
827 obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
829 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
830 //obj.show_libs( org );
832 //obj.show_my_libs();
834 JSAN.use('util.file'); JSAN.use('util.widgets');
836 var file; var list_data; var ml;
838 file = new util.file('offline_ou_list');
839 if (file._file.exists()) {
840 list_data = file.get_object(); file.close();
841 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
842 ml.setAttribute('id','lib_menu'); document.getElementById('x_lib_menu').appendChild(ml);
843 for (var i = 0; i < obj.org_ids.length; i++) {
844 ml.getElementsByAttribute('value',obj.org_ids[i])[0].setAttribute('class','has_copies');
846 ml.firstChild.addEventListener(
849 document.getElementById('legend').setAttribute('hidden','false');
853 ml.firstChild.addEventListener(
856 document.getElementById('legend').setAttribute('hidden','true');
863 //obj.show_my_libs(ev.target.value);
864 //alert('lib picker, command caught - ml = ' + ml + '\nml.value = ' + ml.value + '\n');
865 if (document.getElementById('refresh_button')) document.getElementById('refresh_button').focus();
866 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
867 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
873 throw('Missing library list.\n');
876 JSAN.use('util.widgets');
878 file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
879 util.widgets.load_attributes(file);
880 ml.value = ml.getAttribute('value');
883 ml.setAttribute('value',ml.value);
886 document.getElementById('show_acns').addEventListener(
889 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
890 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
895 document.getElementById('show_acps').addEventListener(
898 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
899 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
904 obj.show_my_libs( ml.value );
906 obj.show_consortial_count();
909 this.error.standard_unexpected_error_alert('cat.copy_browser.init: ',E);
913 'show_consortial_count' : function() {
916 obj.network.simple_request('FM_ACP_COUNT',[ obj.data.tree.aou.id(), obj.docid ],function(req){
918 var robj = req.getResultObject();
919 var x = document.getElementById('consortial_total');
920 if (x) x.setAttribute('value',robj[0].count);
921 x = document.getElementById('consortial_available');
922 if (x) x.setAttribute('value',robj[0].available);
924 obj.error.standard_unexpected_error_alert('Error retrieving consortial copy count.',E);
928 this.error.standard_unexpected_error_alert('cat.copy_browser.show_consortial_count: ',E);
932 'show_my_libs' : function(org) {
936 org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
938 if (typeof org != 'object') org = obj.data.hash.aou[ org ];
940 obj.show_libs( org, false );
942 var p_org = obj.data.hash.aou[ org.parent_ou() ];
944 JSAN.use('util.exec'); var exec = new util.exec();
946 funcs.push( function() {
947 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
948 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
949 document.getElementById('lib_menu').setAttribute('disabled','true');
951 for (var i = 0; i < p_org.children().length; i++) {
955 obj.show_libs( o, false );
957 }( p_org.children()[i] )
960 funcs.push( function() {
961 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
962 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
963 document.getElementById('lib_menu').setAttribute('disabled','false');
972 'show_all_libs' : function() {
977 obj.show_libs( obj.data.tree.aou );
979 JSAN.use('util.exec'); var exec = new util.exec();
981 funcs.push( function() {
982 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
983 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
984 document.getElementById('lib_menu').setAttribute('disabled','true');
987 for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
993 }( obj.data.tree.aou.children()[i] )
996 funcs.push( function() {
997 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
998 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
999 document.getElementById('lib_menu').setAttribute('disabled','false');
1002 exec.chain( funcs );
1008 'show_libs_with_copies' : function() {
1011 JSAN.use('util.exec'); var exec = new util.exec();
1012 JSAN.use('util.functional');
1014 var orgs = util.functional.map_list(
1016 function(id) { return obj.data.hash.aou[id]; }
1019 if (a.shortname() < b.shortname()) return -1;
1020 if (a.shortname() > b.shortname()) return 1;
1025 funcs.push( function() {
1026 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1027 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
1028 document.getElementById('lib_menu').setAttribute('disabled','true');
1031 for (var i = 0; i < orgs.length; i++) {
1035 obj.show_libs(o,false);
1040 funcs.push( function() {
1041 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1042 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
1043 document.getElementById('lib_menu').setAttribute('disabled','false');
1046 exec.chain( funcs );
1052 'show_libs' : function(start_aou,show_open) {
1055 if (!start_aou) throw('show_libs: Need a start_aou');
1056 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1057 JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
1062 var temp_aou = start_aou;
1063 while ( temp_aou.parent_ou() ) {
1064 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
1065 parents.push( temp_aou );
1069 for (var i = 0; i < parents.length; i++) {
1074 obj.append_org(o,p,{'container':'true','open':'true'});
1076 obj.append_org(o,p,{'container':'true'});
1079 }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
1085 return function() { obj.append_org(o,p); };
1086 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
1091 if (start_aou.children()) {
1092 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
1093 x.setAttribute('container','true');
1094 if (show_open) x.setAttribute('open','true');
1095 for (var i = 0; i < start_aou.children().length; i++) {
1098 return function() { obj.append_org(o,p); };
1099 }( start_aou.children()[i], start_aou )
1106 exec.chain( funcs );
1113 'on_select' : function(list,twisty) {
1115 for (var i = 0; i < list.length; i++) {
1116 var node = obj.map_tree[ list[i] ];
1117 //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
1118 var row_type = list[i].split('_')[0];
1119 var id = list[i].split('_')[1];
1121 case 'aou' : obj.on_select_org(id,twisty); break;
1122 case 'acn' : obj.on_select_acn(id,twisty); break;
1128 'on_select_acn' : function(acn_id,twisty) {
1131 var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
1133 funcs.push( function() {
1134 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1135 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
1136 document.getElementById('lib_menu').setAttribute('disabled','true');
1138 if (acn_tree.copies()) {
1139 for (var i = 0; i < acn_tree.copies().length; i++) {
1143 obj.append_acp(c,a);
1145 }( acn_tree.copies()[i], acn_tree )
1149 funcs.push( function() {
1150 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1151 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
1152 document.getElementById('lib_menu').setAttribute('disabled','false');
1154 JSAN.use('util.exec'); var exec = new util.exec();
1155 exec.chain( funcs );
1161 'on_select_org' : function(org_id,twisty) {
1163 var org = obj.data.hash.aou[ org_id ];
1164 if (obj.data.hash.aout[ org.ou_type() ].depth() == 0) return;
1165 /* otherwise, we'd show every system in the consortia */
1167 funcs.push( function() {
1168 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1169 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
1170 document.getElementById('lib_menu').setAttribute('disabled','true');
1172 if (org.children()) {
1173 for (var i = 0; i < org.children().length; i++) {
1179 }(org.children()[i],org)
1183 if (obj.map_acn[ 'aou_' + org_id ]) {
1184 for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
1188 obj.append_acn(o,a);
1190 }( org, obj.map_acn[ 'aou_' + org_id ][i] )
1194 funcs.push( function() {
1195 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1196 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
1197 document.getElementById('lib_menu').setAttribute('disabled','false');
1199 JSAN.use('util.exec'); var exec = new util.exec();
1200 exec.chain( funcs );
1203 'append_org' : function (org,parent_org,params) {
1206 if (obj.map_tree[ 'aou_' + org.id() ]) {
1207 var x = obj.map_tree[ 'aou_' + org.id() ];
1209 for (var i in params) {
1210 x.setAttribute(i,params[i]);
1222 'skip_all_columns_except' : [0,1,2],
1223 'retrieve_id' : 'aou_' + org.id(),
1225 'no_auto_select' : true,
1229 if ( obj.org_ids.indexOf( Number( org.id() ) ) == -1 ) {
1230 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) {
1231 data.row.my.volume_count = '0';
1232 data.row.my.copy_count = '<0>';
1234 data.row.my.volume_count = '';
1235 data.row.my.copy_count = '';
1238 var v_count = 0; var c_count = 0;
1239 acn_tree_list = obj.network.simple_request(
1240 'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS',
1241 [ ses(), obj.docid, [ org.id() ] ]
1243 for (var i = 0; i < acn_tree_list.length; i++) {
1245 obj.map_acn[ 'acn_' + acn_tree_list[i].id() ] = function(r){return r;}(acn_tree_list[i]);
1246 var copies = acn_tree_list[i].copies(); if (copies) c_count += copies.length;
1247 for (var j = 0; j < copies.length; j++) {
1248 obj.map_acp[ 'acp_' + copies[j].id() ] = function(r){return r;}(copies[j]);
1251 data.row.my.volume_count = v_count;
1252 data.row.my.copy_count = '<' + c_count + '>';
1255 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
1257 var nparams = obj.list.append(data);
1258 var node = nparams.my_node;
1260 for (var i in params) {
1261 node.setAttribute(i,params[i]);
1264 obj.map_tree[ 'aou_' + org.id() ] = node;
1266 if (org.children()) {
1267 node.setAttribute('container','true');
1271 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
1272 data.node.setAttribute('open','true');
1275 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
1278 if (acn_tree_list) {
1279 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
1280 node.setAttribute('container','true');
1283 if (document.getElementById('show_acns').checked) {
1284 if ( obj.data.hash.aout[ org.ou_type() ].depth() != 0 ) {
1285 node.setAttribute('open','true');
1286 setTimeout( function() { obj.on_select_org( org.id() ); }, 0 );
1296 'append_acn' : function( org, acn_tree, params ) {
1299 if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
1300 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
1302 for (var i in params) {
1303 x.setAttribute(i,params[i]);
1309 var parent_node = obj.map_tree[ 'aou_' + org.id() ];
1315 'volume_count' : '',
1316 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
1319 'skip_all_columns_except' : [0,1,2],
1320 'retrieve_id' : 'acn_' + acn_tree.id(),
1321 'node' : parent_node,
1323 'no_auto_select' : true,
1325 var nparams = obj.list.append(data);
1326 var node = nparams.my_node;
1327 obj.map_tree[ 'acn_' + acn_tree.id() ] = node;
1329 for (var i in params) {
1330 node.setAttribute(i,params[i]);
1333 if (acn_tree.copies()) {
1334 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
1335 node.setAttribute('container','true');
1337 if (document.getElementById('show_acps').checked) {
1338 node.setAttribute('open','true');
1339 setTimeout( function() { obj.on_select_acn( acn_tree.id() ); }, 0 );
1348 'append_acp' : function( acp_item, acn_tree, params ) {
1351 if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
1352 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
1354 for (var i in params) {
1355 x.setAttribute(i,params[i]);
1361 var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
1365 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
1368 'volume_count' : '',
1372 'retrieve_id' : 'acp_' + acp_item.id(),
1373 'node' : parent_node,
1375 'no_auto_select' : true,
1377 var nparams = obj.list.append(data);
1378 var node = nparams.my_node;
1379 obj.map_tree[ 'acp_' + acp_item.id() ] = node;
1381 for (var i in params) {
1382 node.setAttribute(i,params[i]);
1392 'list_init' : function( params ) {
1395 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1398 JSAN.use('circ.util');
1401 'id' : 'tree_location', 'label' : 'Location/Barcode', 'flex' : 1,
1402 'primary' : true, 'hidden' : false,
1403 'render' : function(my) { return my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"; },
1406 'id' : 'volume_count', 'label' : 'Volumes', 'flex' : 0,
1407 'primary' : false, 'hidden' : false,
1408 'render' : function(my) { return my.volume_count; },
1411 'id' : 'copy_count', 'label' : 'Copies', 'flex' : 0,
1412 'primary' : false, 'hidden' : false,
1413 'render' : function(my) { return my.copy_count; },
1418 'location' : { 'hidden' : false },
1419 'circ_lib' : { 'hidden' : false },
1420 'owning_lib' : { 'hidden' : false },
1421 'call_number' : { 'hidden' : false },
1422 'due_date' : { 'hidden' : false },
1423 'status' : { 'hidden' : false },
1452 JSAN.use('util.list'); obj.list = new util.list('copy_tree');
1455 'no_auto_select' : true,
1456 'columns' : columns,
1457 'map_row_to_columns' : circ.util.std_map_row_to_columns(' '),
1458 'retrieve_row' : function(params) {
1460 var row = params.row;
1464 if (!row.my.mvr) funcs.push(
1467 row.my.mvr = obj.network.request(
1468 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
1469 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
1470 [ row.my.circ.target_copy() ]
1479 row.my.acp = obj.network.request(
1480 api.FM_ACP_RETRIEVE.app,
1481 api.FM_ACP_RETRIEVE.method,
1482 [ row.my.circ.target_copy() ]
1485 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1490 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1496 if (typeof params.on_retrieve == 'function') {
1497 params.on_retrieve(row);
1503 JSAN.use('util.exec'); var exec = new util.exec();
1504 exec.on_error = function(E) {
1505 var err = 'items chain: ' + js2JSON(E);
1506 obj.error.sdump('D_ERROR',err);
1507 return true; /* keep going */
1509 exec.chain( funcs );
1513 'on_click' : function(ev) {
1514 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
1515 var row = {}; var col = {}; var nobj = {};
1516 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
1517 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
1518 var node = obj.list.node.contentView.getItemAtIndex(row.value);
1519 var list = [ node.getAttribute('retrieve_id') ];
1520 if (typeof obj.on_select == 'function') {
1521 obj.on_select(list,true);
1523 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1524 window.xulG.on_select(list);
1527 'on_select' : function(ev) {
1528 JSAN.use('util.functional');
1529 var sel = obj.list.retrieve_selection();
1530 obj.controller.view.sel_clip.disabled = sel.length < 1;
1531 obj.sel_list = util.functional.map_list(
1533 function(o) { return o.getAttribute('retrieve_id'); }
1535 obj.toggle_actions();
1536 if (typeof obj.on_select == 'function') {
1537 obj.on_select(obj.sel_list);
1539 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1540 window.xulG.on_select(obj.sel_list);
1546 obj.controller.render();
1549 this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
1554 'toggle_actions' : function() {
1557 var found_aou = false; var found_acn = false; var found_acp = false;
1558 var found_aou_with_can_have_vols = false;
1559 for (var i = 0; i < obj.sel_list.length; i++) {
1560 var type = obj.sel_list[i].split(/_/)[0];
1564 var org = obj.data.hash.aou[ obj.sel_list[i].split(/_/)[1] ];
1565 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) found_aou_with_can_have_vols = true;
1567 case 'acn' : found_acn = true; break;
1568 case 'acp' : found_acp = true; break;
1571 obj.controller.view.cmd_add_items.setAttribute('disabled','true');
1572 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','true');
1573 obj.controller.view.cmd_edit_items.setAttribute('disabled','true');
1574 obj.controller.view.cmd_replace_barcode.setAttribute('disabled','true');
1575 obj.controller.view.cmd_delete_items.setAttribute('disabled','true');
1576 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','true');
1577 obj.controller.view.cmd_add_volumes.setAttribute('disabled','true');
1578 obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
1579 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','true');
1580 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','true');
1581 obj.controller.view.cmd_mark_volume.setAttribute('disabled','true');
1582 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','true');
1583 obj.controller.view.cmd_transfer_items.setAttribute('disabled','true');
1584 obj.controller.view.sel_copy_details.setAttribute('disabled','true');
1585 obj.controller.view.sel_patron.setAttribute('disabled','true');
1586 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
1587 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
1588 if (found_aou && found_aou_with_can_have_vols) {
1589 obj.controller.view.cmd_add_volumes.setAttribute('disabled','false');
1590 obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
1593 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','false');
1594 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','false');
1595 obj.controller.view.cmd_mark_volume.setAttribute('disabled','false');
1596 obj.controller.view.cmd_add_items.setAttribute('disabled','false');
1597 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','false');
1600 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
1601 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
1602 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','false');
1603 obj.controller.view.cmd_edit_items.setAttribute('disabled','false');
1604 obj.controller.view.cmd_replace_barcode.setAttribute('disabled','false');
1605 obj.controller.view.cmd_delete_items.setAttribute('disabled','false');
1606 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','false');
1607 obj.controller.view.cmd_transfer_items.setAttribute('disabled','false');
1608 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
1609 obj.controller.view.sel_patron.setAttribute('disabled','false');
1612 obj.error.standard_unexpected_error_alert('Copy Browser Actions',E);
1616 'refresh_list' : function() {
1623 obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
1624 if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
1625 JSAN.use('util.functional');
1626 obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
1628 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1629 obj.show_libs( org );
1631 obj.show_my_libs( document.getElementById('lib_menu').value );
1632 // FIXME - we get a null from the copy_count call if we call it too quickly here
1633 setTimeout( function() { obj.show_consortial_count(); }, 2000 );
1635 this.error.standard_unexpected_error_alert('Problem refreshing the volume/copy tree.',E);
1640 dump('exiting cat.copy_browser.js\n');