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];
300 edit = obj.network.request(
301 api.PERM_MULTI_ORG_CHECK.app,
302 api.PERM_MULTI_ORG_CHECK.method,
305 obj.data.list.au[0].id(),
306 util.functional.map_list(
309 var o_acp = obj.map_acp[ 'acp_' + o ];
310 if (o_acp.call_number() == -1) {
311 return o_acp.circ_lib();
313 return obj.map_acn[ 'acn_' + o_acp.call_number() ].owning_lib();
317 list.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
319 ).length == 0 ? 1 : 0;
321 obj.error.sdump('D_ERROR','batch permission check: ' + E);
324 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
328 obj.error.standard_unexpected_error_alert('Copy Browser -> Edit Items',E);
332 'cmd_delete_items' : [
336 JSAN.use('util.functional');
338 var list = util.functional.filter_list(
341 return o.split(/_/)[0] == 'acp';
345 list = util.functional.map_list(
348 return JSON2js( js2JSON( obj.map_acp[ 'acp_' + o.split(/_/)[1] ] ) );
352 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');
355 var acn_hash = {}; var acn_list = [];
356 for (var i = 0; i < list.length; i++) {
357 list[i].isdeleted('1');
358 var acn_id = list[i].call_number();
359 if ( ! acn_hash[ acn_id ] ) {
360 acn_hash[ acn_id ] = obj.map_acn[ 'acn_' + acn_id ];
361 acn_hash[ acn_id ].copies( [] );
363 var temp = acn_hash[ acn_id ].copies();
364 temp.push( list[i] );
365 acn_hash[ acn_id ].copies( temp );
367 for (var i in acn_hash) acn_list.push( acn_hash[i] );
368 var robj = obj.network.simple_request(
369 'FM_ACN_TREE_UPDATE',
370 [ ses(), acn_list, true ],
373 'title' : 'Override Delete Failure?',
374 'overridable_events' : [
375 1208 /* TITLE_LAST_COPY */,
376 1227 /* COPY_DELETE_WARNING */,
380 if (robj == null) throw(robj);
381 if (typeof robj.ilsevent != 'undefined') {
382 if ( (robj.ilsevent != 0) && (robj.ilsevent != 1227 /* COPY_DELETE_WARNING */) && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */) ) throw(robj);
384 alert('Action complete.');
390 obj.error.standard_unexpected_error_alert('copy browser -> delete items',E);
395 'cmd_print_spine_labels' : [
399 JSAN.use('util.functional');
401 var list = util.functional.filter_list(
404 return o.split(/_/)[0] == 'acp';
408 list = util.functional.map_list(
411 return obj.map_acp[ o ];
415 obj.data.temp_barcodes_for_labels = util.functional.map_list( list, function(o){return o.barcode();}) ;
416 obj.data.stash('temp_barcodes_for_labels');
418 xulG.url_prefix( urls.XUL_SPINE_LABEL ),
419 { 'tab_name' : 'Spine Labels' },
423 obj.error.standard_unexpected_error_alert('copy browser -> Spine Labels',E);
427 'cmd_add_volumes' : [
431 JSAN.use('util.functional');
432 var list = util.functional.filter_list(
435 return o.split(/_/)[0] == 'aou';
438 list = util.functional.map_list(
441 return o.split(/_/)[1];
446 edit = obj.network.request(
447 api.PERM_MULTI_ORG_CHECK.app,
448 api.PERM_MULTI_ORG_CHECK.method,
451 obj.data.list.au[0].id(),
453 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
455 ).length == 0 ? 1 : 0;
457 obj.error.sdump('D_ERROR','batch permission check: ' + E);
461 alert("You don't have permission to add volumes to that library.");
462 return; // no read-only view for this interface
465 var title = 'Add Volume/Item';
467 JSAN.use('util.window'); var win = new util.window();
469 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR),
470 //+'?doc_id=' + window.escape(obj.docid)
471 //+'&ou_ids=' + window.escape( js2JSON(list) ),
476 w.refresh = function() { obj.refresh_list() };
477 w.xulG = { 'doc_id' : obj.docid, 'ou_ids' : list };
479 obj.error.standard_unexpected_error_alert('copy browser -> add volumes',E);
483 'cmd_edit_volumes' : [
487 JSAN.use('util.functional');
488 var list = util.functional.map_list(
489 util.functional.filter_list(
492 return o.split(/_/)[0] == 'acn';
496 return o.split(/_/)[1];
499 if (list.length == 0) return;
503 edit = obj.network.request(
504 api.PERM_MULTI_ORG_CHECK.app,
505 api.PERM_MULTI_ORG_CHECK.method,
508 obj.data.list.au[0].id(),
509 util.functional.map_list(
512 return obj.map_acn[ 'acn_' + o ].owning_lib();
517 ).length == 0 ? 1 : 0;
519 obj.error.sdump('D_ERROR','batch permission check: ' + E);
523 alert("You don't have permission to edit this volume.");
524 return; // no read-only view for this interface
527 list = util.functional.map_list(
530 var my_acn = obj.map_acn['acn_' + o];
531 return function(r){return r;}(my_acn);
535 var title = list.length == 1 ? 'Volume' : 'Volumes';
537 JSAN.use('util.window'); var win = new util.window();
538 //obj.data.volumes_temp = js2JSON( list );
539 //obj.data.stash('volumes_temp');
540 var my_xulG = win.open(
541 window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR),
543 'chrome,modal,resizable',
547 /* FIXME -- need to unique the temp space, and not rely on modalness of window */
548 //obj.data.stash_retrieve();
549 var volumes = my_xulG.volumes;
550 if (!volumes) return;
552 volumes = util.functional.filter_list(
555 return o.ischanged() == '1';
559 volumes = util.functional.map_list(
562 o.record( obj.docid ); // staff client 2 did not do this. Does it matter?
567 if (volumes.length == 0) return;
570 var r = obj.network.request(
571 api.FM_ACN_TREE_UPDATE.app,
572 api.FM_ACN_TREE_UPDATE.method,
573 [ ses(), volumes, true ]
575 if (typeof r.ilsevent != 'undefined') {
577 case 1705 /* VOLUME_LABEL_EXISTS */ :
578 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.");
583 alert('Volumes modified.');
586 obj.error.standard_unexpected_error_alert('volume update error: ',E);
591 obj.error.standard_unexpected_error_alert('Copy Browser -> Volume Edit',E);
595 'cmd_delete_volumes' : [
599 JSAN.use('util.functional');
601 var list = util.functional.filter_list(
604 return o.split(/_/)[0] == 'acn';
608 list = util.functional.map_list(
611 return JSON2js( js2JSON( obj.map_acn[ 'acn_' + o.split(/_/)[1] ] ) );
615 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');
618 for (var i = 0; i < list.length; i++) {
619 list[i].isdeleted('1');
621 var robj = obj.network.simple_request(
622 'FM_ACN_TREE_UPDATE',
623 [ ses(), list, true ],
626 'title' : 'Override Delete Failure?',
627 'overridable_events' : [
631 if (robj == null) throw(robj);
632 if (typeof robj.ilsevent != 'undefined') {
633 if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
634 alert('You must delete all the copies on the volume before you may delete the volume itself.');
637 if (robj.ilsevent != 0) throw(robj);
639 alert('Volumes deleted.');
643 obj.error.standard_unexpected_error_alert('copy browser -> delete volumes',E);
649 'cmd_mark_library' : [
653 var list = util.functional.filter_list(
656 return o.split(/_/)[0] == 'aou';
660 list = util.functional.map_list(
663 return o.split(/_/)[1];
667 if (list.length == 1) {
668 obj.data.marked_library = { 'lib' : list[0], 'docid' : obj.docid };
669 obj.data.stash('marked_library');
670 alert('Library + Record marked as Volume Transfer Destination');
672 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');
675 obj.error.standard_unexpected_error_alert('copy browser -> mark library',E);
680 'cmd_mark_volume' : [
684 var list = util.functional.filter_list(
687 return o.split(/_/)[0] == 'acn';
691 list = util.functional.map_list(
694 return o.split(/_/)[1];
698 if (list.length == 1) {
699 obj.data.marked_volume = list[0];
700 obj.data.stash('marked_volume');
701 alert('Volume marked as Item Transfer Destination');
703 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');
706 obj.error.standard_unexpected_error_alert('copy browser -> mark volume',E);
710 'cmd_refresh_list' : [
716 'cmd_transfer_volume' : [
720 obj.data.stash_retrieve();
721 if (!obj.data.marked_library) {
722 alert('Please mark a library as the destination from within holdings maintenance and then try this again.');
726 JSAN.use('util.functional');
728 var list = util.functional.filter_list(
731 return o.split(/_/)[0] == 'acn';
735 list = util.functional.map_list(
738 return o.split(/_/)[1];
742 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
743 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
744 xml += '<description>Transfer volumes ';
746 xml += util.functional.map_list(
749 return obj.map_acn[ 'acn_' + o ].label();
753 xml += ' to library ' + obj.data.hash.aou[ obj.data.marked_library.lib ].shortname();
754 xml += ' on the following record?</description>';
755 xml += '<hbox><button label="Transfer" name="fancy_submit"/>';
756 xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
757 xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + obj.data.marked_library.docid + '"/>';
759 JSAN.use('OpenILS.data');
760 var data = new OpenILS.data(); data.init({'via':'stash'});
761 //data.temp_transfer = xml; data.stash('temp_transfer');
762 JSAN.use('util.window'); var win = new util.window();
763 var fancy_prompt_data = win.open(
764 urls.XUL_FANCY_PROMPT,
765 //+ '?xml_in_stash=temp_transfer'
766 //+ '&title=' + window.escape('Volume Transfer'),
767 'fancy_prompt', 'chrome,resizable,modal,width=500,height=300',
768 { 'xml' : xml, 'title' : 'Volume Transfer' }
771 if (fancy_prompt_data.fancy_status == 'incomplete') { alert('Transfer Aborted'); return; }
773 var robj = obj.network.simple_request(
775 [ ses(), { 'docid' : obj.data.marked_library.docid, 'lib' : obj.data.marked_library.lib, 'volumes' : list } ],
778 'title' : 'Override Volume Transfer Failure?',
779 'overridable_events' : [
780 1208 /* TITLE_LAST_COPY */,
781 1219 /* COPY_REMOTE_CIRC_LIB */,
786 if (typeof robj.ilsevent != 'undefined') {
787 if (robj.ilsevent == 1221 /* ORG_CANNOT_HAVE_VOLS */) {
788 alert('That destination cannot have volumes.');
793 alert('Volumes transferred.');
797 obj.error.standard_unexpected_error_alert('All volumes not likely transferred.',E);
803 'cmd_transfer_items' : [
807 obj.data.stash_retrieve();
808 if (!obj.data.marked_volume) {
809 alert('Please mark a volume as the destination from within holdings maintenance and then try this again.');
813 JSAN.use('util.functional');
815 var list = util.functional.filter_list(
818 return o.split(/_/)[0] == 'acp';
822 list = util.functional.map_list(
825 return o.split(/_/)[1];
829 var volume = obj.network.simple_request('FM_ACN_RETRIEVE',[ obj.data.marked_volume ]);
831 JSAN.use('cat.util'); cat.util.transfer_copies( {
833 'docid' : volume.record(),
834 'volume_label' : volume.label(),
835 'owning_lib' : volume.owning_lib(),
839 obj.error.standard_unexpected_error_alert('All copies not likely transferred.',E);
848 obj.list_init(params);
850 obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
851 if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
853 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
854 //obj.show_libs( org );
856 //obj.show_my_libs();
858 JSAN.use('util.file'); JSAN.use('util.widgets');
860 var file; var list_data; var ml;
862 file = new util.file('offline_ou_list');
863 if (file._file.exists()) {
864 list_data = file.get_object(); file.close();
865 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
866 ml.setAttribute('id','lib_menu'); document.getElementById('x_lib_menu').appendChild(ml);
867 for (var i = 0; i < obj.org_ids.length; i++) {
868 ml.getElementsByAttribute('value',obj.org_ids[i])[0].setAttribute('class','has_copies');
870 ml.firstChild.addEventListener(
873 document.getElementById('legend').setAttribute('hidden','false');
877 ml.firstChild.addEventListener(
880 document.getElementById('legend').setAttribute('hidden','true');
887 //obj.show_my_libs(ev.target.value);
888 //alert('lib picker, command caught - ml = ' + ml + '\nml.value = ' + ml.value + '\n');
889 if (document.getElementById('refresh_button')) document.getElementById('refresh_button').focus();
890 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
891 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
897 throw('Missing library list.\n');
900 JSAN.use('util.widgets');
902 file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
903 util.widgets.load_attributes(file);
904 ml.value = ml.getAttribute('value');
907 ml.setAttribute('value',ml.value);
910 document.getElementById('show_acns').addEventListener(
913 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
914 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
919 document.getElementById('show_acps').addEventListener(
922 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
923 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
928 obj.show_my_libs( ml.value );
930 obj.show_consortial_count();
933 this.error.standard_unexpected_error_alert('cat.copy_browser.init: ',E);
937 'show_consortial_count' : function() {
940 obj.network.simple_request('FM_ACP_COUNT',[ obj.data.tree.aou.id(), obj.docid ],function(req){
942 var robj = req.getResultObject();
943 var x = document.getElementById('consortial_total');
944 if (x) x.setAttribute('value',robj[0].count);
945 x = document.getElementById('consortial_available');
946 if (x) x.setAttribute('value',robj[0].available);
948 obj.error.standard_unexpected_error_alert('Error retrieving consortial copy count.',E);
952 this.error.standard_unexpected_error_alert('cat.copy_browser.show_consortial_count: ',E);
956 'show_my_libs' : function(org) {
960 org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
962 if (typeof org != 'object') org = obj.data.hash.aou[ org ];
964 obj.show_libs( org, false );
966 var p_org = obj.data.hash.aou[ org.parent_ou() ];
968 JSAN.use('util.exec'); var exec = new util.exec();
970 funcs.push( function() {
971 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
972 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
973 document.getElementById('lib_menu').setAttribute('disabled','true');
975 for (var i = 0; i < p_org.children().length; i++) {
979 obj.show_libs( o, false );
981 }( p_org.children()[i] )
984 funcs.push( function() {
985 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
986 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
987 document.getElementById('lib_menu').setAttribute('disabled','false');
996 'show_all_libs' : function() {
1001 obj.show_libs( obj.data.tree.aou );
1003 JSAN.use('util.exec'); var exec = new util.exec();
1005 funcs.push( function() {
1006 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1007 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
1008 document.getElementById('lib_menu').setAttribute('disabled','true');
1011 for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
1017 }( obj.data.tree.aou.children()[i] )
1020 funcs.push( function() {
1021 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1022 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
1023 document.getElementById('lib_menu').setAttribute('disabled','false');
1026 exec.chain( funcs );
1032 'show_libs_with_copies' : function() {
1035 JSAN.use('util.exec'); var exec = new util.exec();
1036 JSAN.use('util.functional');
1038 var orgs = util.functional.map_list(
1040 function(id) { return obj.data.hash.aou[id]; }
1043 if (a.shortname() < b.shortname()) return -1;
1044 if (a.shortname() > b.shortname()) return 1;
1049 funcs.push( function() {
1050 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1051 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
1052 document.getElementById('lib_menu').setAttribute('disabled','true');
1055 for (var i = 0; i < orgs.length; i++) {
1059 obj.show_libs(o,false);
1064 funcs.push( function() {
1065 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1066 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
1067 document.getElementById('lib_menu').setAttribute('disabled','false');
1070 exec.chain( funcs );
1076 'show_libs' : function(start_aou,show_open) {
1079 if (!start_aou) throw('show_libs: Need a start_aou');
1080 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1081 JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
1086 var temp_aou = start_aou;
1087 while ( temp_aou.parent_ou() ) {
1088 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
1089 parents.push( temp_aou );
1093 for (var i = 0; i < parents.length; i++) {
1098 obj.append_org(o,p,{'container':'true','open':'true'});
1100 obj.append_org(o,p,{'container':'true'});
1103 }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
1109 return function() { obj.append_org(o,p); };
1110 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
1115 if (start_aou.children()) {
1116 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
1117 x.setAttribute('container','true');
1118 if (show_open) x.setAttribute('open','true');
1119 for (var i = 0; i < start_aou.children().length; i++) {
1122 return function() { obj.append_org(o,p); };
1123 }( start_aou.children()[i], start_aou )
1130 exec.chain( funcs );
1137 'on_select' : function(list,twisty) {
1139 for (var i = 0; i < list.length; i++) {
1140 var node = obj.map_tree[ list[i] ];
1141 //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
1142 var row_type = list[i].split('_')[0];
1143 var id = list[i].split('_')[1];
1145 case 'aou' : obj.on_select_org(id,twisty); break;
1146 case 'acn' : obj.on_select_acn(id,twisty); break;
1152 'on_select_acn' : function(acn_id,twisty) {
1155 var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
1157 funcs.push( function() {
1158 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1159 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
1160 document.getElementById('lib_menu').setAttribute('disabled','true');
1162 if (acn_tree.copies()) {
1163 for (var i = 0; i < acn_tree.copies().length; i++) {
1167 obj.append_acp(c,a);
1169 }( acn_tree.copies()[i], acn_tree )
1173 funcs.push( function() {
1174 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1175 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
1176 document.getElementById('lib_menu').setAttribute('disabled','false');
1178 JSAN.use('util.exec'); var exec = new util.exec();
1179 exec.chain( funcs );
1185 'on_select_org' : function(org_id,twisty) {
1187 var org = obj.data.hash.aou[ org_id ];
1188 if (obj.data.hash.aout[ org.ou_type() ].depth() == 0) return;
1189 /* otherwise, we'd show every system in the consortia */
1191 funcs.push( function() {
1192 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1193 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
1194 document.getElementById('lib_menu').setAttribute('disabled','true');
1196 if (org.children()) {
1197 for (var i = 0; i < org.children().length; i++) {
1203 }(org.children()[i],org)
1207 if (obj.map_acn[ 'aou_' + org_id ]) {
1208 for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
1212 obj.append_acn(o,a);
1214 }( org, obj.map_acn[ 'aou_' + org_id ][i] )
1218 funcs.push( function() {
1219 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1220 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
1221 document.getElementById('lib_menu').setAttribute('disabled','false');
1223 JSAN.use('util.exec'); var exec = new util.exec();
1224 exec.chain( funcs );
1227 'append_org' : function (org,parent_org,params) {
1230 if (obj.map_tree[ 'aou_' + org.id() ]) {
1231 var x = obj.map_tree[ 'aou_' + org.id() ];
1233 for (var i in params) {
1234 x.setAttribute(i,params[i]);
1246 'skip_all_columns_except' : [0,1,2],
1247 'retrieve_id' : 'aou_' + org.id(),
1249 'no_auto_select' : true,
1253 if ( obj.org_ids.indexOf( org.id() ) == -1 ) {
1254 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) {
1255 data.row.my.volume_count = '0';
1256 data.row.my.copy_count = '<0>';
1258 data.row.my.volume_count = '';
1259 data.row.my.copy_count = '';
1262 var v_count = 0; var c_count = 0;
1263 acn_tree_list = obj.network.simple_request(
1264 'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS',
1265 [ ses(), obj.docid, [ org.id() ] ]
1267 for (var i = 0; i < acn_tree_list.length; i++) {
1269 obj.map_acn[ 'acn_' + acn_tree_list[i].id() ] = function(r){return r;}(acn_tree_list[i]);
1270 var copies = acn_tree_list[i].copies(); if (copies) c_count += copies.length;
1271 for (var j = 0; j < copies.length; j++) {
1272 obj.map_acp[ 'acp_' + copies[j].id() ] = function(r){return r;}(copies[j]);
1275 data.row.my.volume_count = v_count;
1276 data.row.my.copy_count = '<' + c_count + '>';
1279 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
1281 var nparams = obj.list.append(data);
1282 var node = nparams.my_node;
1284 for (var i in params) {
1285 node.setAttribute(i,params[i]);
1288 obj.map_tree[ 'aou_' + org.id() ] = node;
1290 if (org.children()) {
1291 node.setAttribute('container','true');
1295 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
1296 data.node.setAttribute('open','true');
1299 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
1302 if (acn_tree_list) {
1303 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
1304 node.setAttribute('container','true');
1307 if (document.getElementById('show_acns').checked) {
1308 if ( obj.data.hash.aout[ org.ou_type() ].depth() != 0 ) {
1309 node.setAttribute('open','true');
1310 setTimeout( function() { obj.on_select_org( org.id() ); }, 0 );
1320 'append_acn' : function( org, acn_tree, params ) {
1323 if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
1324 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
1326 for (var i in params) {
1327 x.setAttribute(i,params[i]);
1333 var parent_node = obj.map_tree[ 'aou_' + org.id() ];
1339 'volume_count' : '',
1340 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
1343 'skip_all_columns_except' : [0,1,2],
1344 'retrieve_id' : 'acn_' + acn_tree.id(),
1345 'node' : parent_node,
1347 'no_auto_select' : true,
1349 var nparams = obj.list.append(data);
1350 var node = nparams.my_node;
1351 obj.map_tree[ 'acn_' + acn_tree.id() ] = node;
1353 for (var i in params) {
1354 node.setAttribute(i,params[i]);
1357 if (acn_tree.copies()) {
1358 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
1359 node.setAttribute('container','true');
1361 if (document.getElementById('show_acps').checked) {
1362 node.setAttribute('open','true');
1363 setTimeout( function() { obj.on_select_acn( acn_tree.id() ); }, 0 );
1372 'append_acp' : function( acp_item, acn_tree, params ) {
1375 if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
1376 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
1378 for (var i in params) {
1379 x.setAttribute(i,params[i]);
1385 var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
1389 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
1392 'volume_count' : '',
1396 'retrieve_id' : 'acp_' + acp_item.id(),
1397 'node' : parent_node,
1399 'no_auto_select' : true,
1401 var nparams = obj.list.append(data);
1402 var node = nparams.my_node;
1403 obj.map_tree[ 'acp_' + acp_item.id() ] = node;
1405 for (var i in params) {
1406 node.setAttribute(i,params[i]);
1416 'list_init' : function( params ) {
1419 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1422 JSAN.use('circ.util');
1425 'id' : 'tree_location', 'label' : 'Location/Barcode', 'flex' : 1,
1426 'primary' : true, 'hidden' : false,
1427 'render' : function(my) { return my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"; },
1430 'id' : 'volume_count', 'label' : 'Volumes', 'flex' : 0,
1431 'primary' : false, 'hidden' : false,
1432 'render' : function(my) { return my.volume_count; },
1435 'id' : 'copy_count', 'label' : 'Copies', 'flex' : 0,
1436 'primary' : false, 'hidden' : false,
1437 'render' : function(my) { return my.copy_count; },
1442 'location' : { 'hidden' : false },
1443 'circ_lib' : { 'hidden' : false },
1444 'owning_lib' : { 'hidden' : false },
1445 'call_number' : { 'hidden' : false },
1446 'due_date' : { 'hidden' : false },
1447 'status' : { 'hidden' : false },
1476 JSAN.use('util.list'); obj.list = new util.list('copy_tree');
1479 'no_auto_select' : true,
1480 'columns' : columns,
1481 'map_row_to_columns' : circ.util.std_map_row_to_columns(' '),
1482 'retrieve_row' : function(params) {
1484 var row = params.row;
1488 if (!row.my.mvr) funcs.push(
1491 row.my.mvr = obj.network.request(
1492 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
1493 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
1494 [ row.my.circ.target_copy() ]
1503 row.my.acp = obj.network.request(
1504 api.FM_ACP_RETRIEVE.app,
1505 api.FM_ACP_RETRIEVE.method,
1506 [ row.my.circ.target_copy() ]
1509 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1514 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1520 if (typeof params.on_retrieve == 'function') {
1521 params.on_retrieve(row);
1527 JSAN.use('util.exec'); var exec = new util.exec();
1528 exec.on_error = function(E) {
1529 var err = 'items chain: ' + js2JSON(E);
1530 obj.error.sdump('D_ERROR',err);
1531 return true; /* keep going */
1533 exec.chain( funcs );
1537 'on_click' : function(ev) {
1538 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
1539 var row = {}; var col = {}; var nobj = {};
1540 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
1541 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
1542 var node = obj.list.node.contentView.getItemAtIndex(row.value);
1543 var list = [ node.getAttribute('retrieve_id') ];
1544 if (typeof obj.on_select == 'function') {
1545 obj.on_select(list,true);
1547 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1548 window.xulG.on_select(list);
1551 'on_select' : function(ev) {
1552 JSAN.use('util.functional');
1553 var sel = obj.list.retrieve_selection();
1554 obj.controller.view.sel_clip.disabled = sel.length < 1;
1555 obj.sel_list = util.functional.map_list(
1557 function(o) { return o.getAttribute('retrieve_id'); }
1559 obj.toggle_actions();
1560 if (typeof obj.on_select == 'function') {
1561 obj.on_select(obj.sel_list);
1563 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1564 window.xulG.on_select(obj.sel_list);
1570 obj.controller.render();
1573 this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
1578 'toggle_actions' : function() {
1581 var found_aou = false; var found_acn = false; var found_acp = false;
1582 var found_aou_with_can_have_vols = false;
1583 for (var i = 0; i < obj.sel_list.length; i++) {
1584 var type = obj.sel_list[i].split(/_/)[0];
1588 var org = obj.data.hash.aou[ obj.sel_list[i].split(/_/)[1] ];
1589 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) found_aou_with_can_have_vols = true;
1591 case 'acn' : found_acn = true; break;
1592 case 'acp' : found_acp = true; break;
1595 obj.controller.view.cmd_add_items.setAttribute('disabled','true');
1596 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','true');
1597 obj.controller.view.cmd_edit_items.setAttribute('disabled','true');
1598 obj.controller.view.cmd_replace_barcode.setAttribute('disabled','true');
1599 obj.controller.view.cmd_delete_items.setAttribute('disabled','true');
1600 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','true');
1601 obj.controller.view.cmd_add_volumes.setAttribute('disabled','true');
1602 obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
1603 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','true');
1604 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','true');
1605 obj.controller.view.cmd_mark_volume.setAttribute('disabled','true');
1606 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','true');
1607 obj.controller.view.cmd_transfer_items.setAttribute('disabled','true');
1608 obj.controller.view.sel_copy_details.setAttribute('disabled','true');
1609 obj.controller.view.sel_patron.setAttribute('disabled','true');
1610 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
1611 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
1612 if (found_aou && found_aou_with_can_have_vols) {
1613 obj.controller.view.cmd_add_volumes.setAttribute('disabled','false');
1614 obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
1617 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','false');
1618 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','false');
1619 obj.controller.view.cmd_mark_volume.setAttribute('disabled','false');
1620 obj.controller.view.cmd_add_items.setAttribute('disabled','false');
1621 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','false');
1624 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
1625 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
1626 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','false');
1627 obj.controller.view.cmd_edit_items.setAttribute('disabled','false');
1628 obj.controller.view.cmd_replace_barcode.setAttribute('disabled','false');
1629 obj.controller.view.cmd_delete_items.setAttribute('disabled','false');
1630 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','false');
1631 obj.controller.view.cmd_transfer_items.setAttribute('disabled','false');
1632 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
1633 obj.controller.view.sel_patron.setAttribute('disabled','false');
1636 obj.error.standard_unexpected_error_alert('Copy Browser Actions',E);
1640 'refresh_list' : function() {
1647 obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
1649 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1650 obj.show_libs( org );
1652 obj.show_my_libs( document.getElementById('lib_menu').value );
1653 // FIXME - we get a null from the copy_count call if we call it too quickly here
1654 setTimeout( function() { obj.show_consortial_count(); }, 2000 );
1656 this.error.standard_unexpected_error_alert('Problem refreshing the volume/copy tree.',E);
1661 dump('exiting cat.copy_browser.js\n');