1 dump('entering cat.copy_browser.js\n');
4 if (typeof cat == 'undefined') cat = {};
5 cat.copy_browser = function (params) {
7 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
8 JSAN.use('util.error'); this.error = new util.error();
10 dump('cat.copy_browser: ' + E + '\n');
14 cat.copy_browser.prototype = {
22 'init' : function( params ) {
25 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
28 obj.docid = params.docid;
30 JSAN.use('util.network'); obj.network = new util.network();
31 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
33 obj.controller_init(params);
35 obj.list_init(params);
37 obj.controller.render();
39 obj.default_depth = obj.depth_menu_init();
40 obj.default_lib = obj.data.hash.aou[ obj.library_menu_init() ];
42 document.getElementById('show_acns').addEventListener(
45 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
46 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
51 document.getElementById('show_acps').addEventListener(
54 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
55 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_acns' : [ 'checked' ], 'show_acps' : [ 'checked' ] });
60 obj.show_my_libs( obj.default_lib.id() );
62 JSAN.use('util.exec'); var exec = new util.exec(20); exec.timer(obj.funcs,100);
64 obj.show_consortial_count();
67 this.error.standard_unexpected_error_alert('cat.copy_browser.init: ',E);
71 'controller_init' : function(params) {
74 JSAN.use('util.controller'); obj.controller = new util.controller();
78 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
81 function() { obj.list.clipboard(); }
86 alert(document.getElementById('commonStrings').getString('common.unimplemented'));
89 'cmd_show_my_libs' : [
95 'cmd_show_all_libs' : [
101 'cmd_show_libs_with_copies' : [
104 obj.show_libs_with_copies();
114 'sel_mark_items_damaged' : [
117 JSAN.use('cat.util'); JSAN.use('util.functional');
119 var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; });
121 list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; });
123 cat.util.mark_item_damaged( list );
128 'sel_mark_items_missing' : [
131 JSAN.use('cat.util'); JSAN.use('util.functional');
133 var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; });
135 list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; });
137 cat.util.mark_item_missing( list );
145 JSAN.use('util.functional');
147 var list = util.functional.filter_list(
150 return o.split(/_/)[0] == 'acp';
154 list = util.functional.map_list(
157 return { 'copy_id' : o.split(/_/)[1] };
161 JSAN.use('circ.util');
162 circ.util.show_last_few_circs(list);
165 'sel_copy_details' : [
168 JSAN.use('util.functional');
170 var list = util.functional.filter_list(
173 return o.split(/_/)[0] == 'acp';
177 JSAN.use('circ.util');
178 circ.util.item_details_new(
179 util.functional.map_list(
181 return obj.map_acp[o].barcode();
190 JSAN.use("cat.util");
191 JSAN.use("util.functional");
193 /* Filter selected rows that aren"t copies. */
194 var list = util.functional.filter_list(
197 return o.split(/_/)[0] == "acp";
200 var results = cat.util.make_bookable(
201 util.functional.map_list(
203 return obj.map_acp[o].id();
207 if (results && results["brsrc"]) {
208 cat.util.edit_new_brsrc(results["brsrc"]);
212 'cmd_book_item_now' : [
215 JSAN.use("cat.util");
216 JSAN.use("util.functional");
218 /* Filter selected rows that aren"t copies. */
219 var list = util.functional.filter_list(
222 return o.split(/_/)[0] == "acp";
225 var results = cat.util.make_bookable(
226 util.functional.map_list(
228 return obj.map_acp[o].id();
233 cat.util.edit_new_bresv(results);
241 JSAN.use('util.functional');
242 var list = util.functional.map_list(
243 util.functional.filter_list(
246 return o.split(/_/)[0] == 'acn';
250 return o.split(/_/)[1];
253 if (list.length == 0) return;
255 var copy_shortcut = {};
256 list = util.functional.map_list(
259 var call_number = obj.map_acn['acn_'+o];
260 var ou_id = call_number.owning_lib();
262 var label = call_number.label();
263 var acnc_id = typeof call_number.label_class() == 'object'
264 ? call_number.label_class().id()
265 : call_number.label_class();
266 var acnp_id = typeof call_number.prefix() == 'object'
267 ? call_number.prefix().id()
268 : call_number.prefix();
269 var acns_id = typeof call_number.suffix() == 'object'
270 ? call_number.suffix().id()
271 : call_number.suffix();
272 if (!copy_shortcut[ou_id]) copy_shortcut[ou_id] = {};
273 var callnumber_composite_key = acnc_id + ':' + acnp_id + ':' + label + ':' + acns_id;
274 copy_shortcut[ou_id][ callnumber_composite_key ] = volume_id;
279 /* quick fix */ /* what was this fixing? */
280 list = []; for (var i in copy_shortcut) { list.push( i ); }
284 edit = obj.network.request(
285 api.PERM_MULTI_ORG_CHECK.app,
286 api.PERM_MULTI_ORG_CHECK.method,
289 obj.data.list.au[0].id(),
293 ).length == 0 ? 1 : 0;
295 obj.error.sdump('D_ERROR','batch permission check: ' + E);
298 if (edit==0) return; // no read-only view for this interface
300 var title = document.getElementById('catStrings').getString('staff.cat.copy_browser.add_item.title');
302 var horizontal_interface = String( obj.data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true';
303 var url = window.xulG.url_prefix( horizontal_interface ? urls.XUL_VOLUME_COPY_CREATOR_HORIZONTAL : urls.XUL_VOLUME_COPY_CREATOR );
304 var w = xulG.new_tab(
306 { 'tab_name' : title },
308 'doc_id' : obj.docid,
310 'copy_shortcut' : copy_shortcut,
311 'onrefresh' : function() { obj.refresh_list(); }
315 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_item.error'),E);
319 'cmd_add_items_to_buckets' : [
323 JSAN.use('util.functional');
325 var list = util.functional.filter_list(
328 return o.split(/_/)[0] == 'acp';
332 list = util.functional.map_list(
335 return o.split(/_/)[1];
339 JSAN.use('cat.util');
340 cat.util.add_copies_to_bucket( list );
343 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_items_bucket.error'),E);
351 JSAN.use('util.functional');
353 var list = util.functional.filter_list(
356 return o.split(/_/)[0] == 'acp';
360 list = util.functional.map_list(
363 var cloned_copy_obj = JSON2js( js2JSON( obj.map_acp[ o ] ) );
364 cloned_copy_obj.call_number( obj.map_acn[ 'acn_' + cloned_copy_obj.call_number() ] );
365 return cloned_copy_obj;
369 xulG.volume_item_creator( {'existing_copies':list, 'onrefresh' : function() { obj.refresh_list(); } } );
372 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E);
377 'old_cmd_edit_items' : [
381 JSAN.use('util.functional');
383 var list = util.functional.filter_list(
386 return o.split(/_/)[0] == 'acp';
390 list = util.functional.map_list(
393 return o.split(/_/)[1];
397 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
401 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E);
405 'cmd_delete_items' : [
409 JSAN.use('util.functional');
411 var list = util.functional.filter_list(
414 return o.split(/_/)[0] == 'acp';
418 list = util.functional.map_list(
421 return JSON2js( js2JSON( obj.map_acp[ 'acp_' + o.split(/_/)[1] ] ) );
426 if (list.length != 1) {
427 delete_msg = document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.delete_items.confirm.plural', [list.length]);
429 delete_msg = document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.confirm');
431 var r = obj.error.yns_alert(
433 document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.title'),
434 document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.delete'),
435 document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.cancel'),
437 document.getElementById('commonStrings').getString('common.confirm')
441 var acn_hash = {}; var acn_list = [];
442 for (var i = 0; i < list.length; i++) {
443 list[i].isdeleted('1');
444 var acn_id = list[i].call_number();
445 if ( ! acn_hash[ acn_id ] ) {
446 acn_hash[ acn_id ] = obj.map_acn[ 'acn_' + acn_id ];
447 acn_hash[ acn_id ].copies( [] );
449 var temp = acn_hash[ acn_id ].copies();
450 temp.push( list[i] );
451 acn_hash[ acn_id ].copies( temp );
453 for (var i in acn_hash) acn_list.push( acn_hash[i] );
454 var robj = obj.network.simple_request(
455 'FM_ACN_TREE_UPDATE',
456 [ ses(), acn_list, true ],
459 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.override'),
460 'overridable_events' : [
461 1208 /* TITLE_LAST_COPY */,
462 1227 /* COPY_DELETE_WARNING */,
466 if (robj == null) throw(robj);
467 if (typeof robj.ilsevent != 'undefined') {
468 if ( (robj.ilsevent != 0) && (robj.ilsevent != 1227 /* COPY_DELETE_WARNING */) && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */) ) throw(robj);
475 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.error'),E);
480 'cmd_print_spine_labels' : [
484 JSAN.use('util.functional');
486 var list = util.functional.filter_list(
489 return o.split(/_/)[0] == 'acp';
493 list = util.functional.map_list(
496 return obj.map_acp[ o ];
501 xulG.url_prefix( urls.XUL_SPINE_LABEL ),
502 { 'tab_name' : document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.tab') },
504 'barcodes' : util.functional.map_list( list, function(o){return o.barcode();})
508 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.error'),E);
512 'cmd_add_volumes' : [
516 JSAN.use('util.functional');
517 var list = util.functional.filter_list(
520 return o.split(/_/)[0] == 'aou';
523 list = util.functional.map_list(
526 return o.split(/_/)[1];
531 edit = obj.network.request(
532 api.PERM_MULTI_ORG_CHECK.app,
533 api.PERM_MULTI_ORG_CHECK.method,
536 obj.data.list.au[0].id(),
538 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
540 ).length == 0 ? 1 : 0;
542 obj.error.sdump('D_ERROR','batch permission check: ' + E);
546 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.permission_error'));
547 return; // no read-only view for this interface
550 var title = document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.title');
552 var horizontal_interface = String( obj.data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true';
553 var url = window.xulG.url_prefix( horizontal_interface ? urls.XUL_VOLUME_COPY_CREATOR_HORIZONTAL : urls.XUL_VOLUME_COPY_CREATOR );
554 var w = xulG.new_tab(
556 { 'tab_name' : title },
557 { 'doc_id' : obj.docid, 'ou_ids' : list, 'onrefresh' : function() { obj.refresh_list(); } }
561 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.error'),E);
565 'cmd_edit_volumes' : [
569 JSAN.use('util.functional');
570 var volumes = util.functional.map_list(
571 util.functional.filter_list(
574 return o.split(/_/)[0] == 'acn';
578 return o.split(/_/)[1];
581 volumes = util.functional.map_list(
584 var my_acn = obj.map_acn['acn_' + o];
585 return function(r){return r;}(my_acn);
589 JSAN.use('cat.util');
590 if ( cat.util.batch_edit_volumes( volumes ) ) {
595 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.exception'),E);
599 'cmd_delete_volumes' : [
603 JSAN.use('util.functional');
605 var list = util.functional.filter_list(
608 return o.split(/_/)[0] == 'acn';
612 list = util.functional.map_list(
615 return JSON2js( js2JSON( obj.map_acn[ 'acn_' + o.split(/_/)[1] ] ) );
620 if (list.length == 1) {
621 del_prompt = document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.prompt');
623 del_prompt = document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.delete_volume.prompt.plural', [list.length]);
626 var r = obj.error.yns_alert(
628 document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.title'),
629 document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.delete'),
630 document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.cancel'),
632 document.getElementById('commonStrings').getString('common.confirm')
636 for (var i = 0; i < list.length; i++) {
637 list[i].isdeleted('1');
639 var robj = obj.network.simple_request(
640 'FM_ACN_TREE_UPDATE',
641 [ ses(), list, true ],
644 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.override'),
645 'overridable_events' : [
649 if (robj == null) throw(robj);
650 if (typeof robj.ilsevent != 'undefined') {
651 if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
652 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain'));
655 if (robj.ilsevent != 0) throw(robj);
660 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.exception'),E);
666 'cmd_mark_library' : [
670 var list = util.functional.filter_list(
673 return o.split(/_/)[0] == 'aou';
677 list = util.functional.map_list(
680 return o.split(/_/)[1];
684 if (list.length == 1) {
685 obj.data.marked_library = { 'lib' : list[0], 'docid' : obj.docid };
686 obj.data.stash('marked_library');
687 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.alert'));
690 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.prompt'),
691 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.title'),
692 document.getElementById('commonStrings').getString('common.ok'),
695 document.getElementById('commonStrings').getString('common.confirm')
699 obj.error.standard_unexpected_error_alert('copy browser -> mark library',E);
704 'cmd_mark_volume' : [
708 var list = util.functional.filter_list(
711 return o.split(/_/)[0] == 'acn';
715 list = util.functional.map_list(
718 return o.split(/_/)[1];
722 if (list.length == 1) {
723 obj.data.marked_volume = list[0];
724 obj.data.stash('marked_volume');
725 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.alert'));
728 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.prompt'),
729 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.title'),
730 document.getElementById('commonStrings').getString('common.ok'),
733 document.getElementById('commonStrings').getString('common.confirm')
737 obj.error.standard_unexpected_error_alert('copy browser -> mark volume',E);
741 'cmd_refresh_list' : [
747 'cmd_transfer_volume' : [
751 obj.data.stash_retrieve();
752 if (!obj.data.marked_library) {
753 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_volume.alert'));
757 JSAN.use('util.functional');
759 var list = util.functional.filter_list(
762 return o.split(/_/)[0] == 'acn';
766 list = util.functional.map_list(
769 return o.split(/_/)[1];
773 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
775 var acn_list = util.functional.map_list(
778 return obj.map_acn[ 'acn_' + o ].label();
780 ).join(document.getElementById('commonStrings').getString('common.grouping_string'));
782 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
783 xml += '<description>';
784 xml += document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.transfer.prompt', [acn_list, obj.data.hash.aou[ obj.data.marked_library.lib ].shortname()]);
785 xml += '</description>';
786 xml += '<hbox><button label="' + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.submit.label') + '" name="fancy_submit"/>';
787 xml += '<button label="'
788 + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.cancel.label')
790 + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.cancel.accesskey')
791 + '" name="fancy_cancel"/></hbox>';
792 xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + obj.data.marked_library.docid + '"/>';
794 JSAN.use('OpenILS.data');
795 var data = new OpenILS.data(); data.init({'via':'stash'});
796 //data.temp_transfer = xml; data.stash('temp_transfer');
797 JSAN.use('util.window'); var win = new util.window();
798 var fancy_prompt_data = win.open(
799 urls.XUL_FANCY_PROMPT,
800 //+ '?xml_in_stash=temp_transfer'
801 //+ '&title=' + window.escape('Volume Transfer'),
802 'fancy_prompt', 'chrome,resizable,modal,width=500,height=300',
805 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.title')
809 if (fancy_prompt_data.fancy_status == 'incomplete') {
810 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.incomplete'));
814 var robj = obj.network.simple_request(
816 [ ses(), { 'docid' : obj.data.marked_library.docid, 'lib' : obj.data.marked_library.lib, 'volumes' : list } ],
819 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.override.failure'),
820 'overridable_events' : [
821 1208 /* TITLE_LAST_COPY */,
822 1219 /* COPY_REMOTE_CIRC_LIB */,
827 if (typeof robj.ilsevent != 'undefined') {
828 if (robj.ilsevent == 1221 /* ORG_CANNOT_HAVE_VOLS */) {
829 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.ineligible_destination'));
834 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.success'));
838 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.unexpected_error'),E);
844 'cmd_transfer_items' : [
848 obj.data.stash_retrieve();
849 if (!obj.data.marked_volume) {
850 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_items.missing_volume'));
854 JSAN.use('util.functional');
856 var list = util.functional.filter_list(
859 return o.split(/_/)[0] == 'acp';
863 list = util.functional.map_list(
866 return o.split(/_/)[1];
870 var volume = obj.network.simple_request('FM_ACN_RETRIEVE.authoritative',[ obj.data.marked_volume ]);
872 JSAN.use('cat.util'); cat.util.transfer_copies( {
874 'docid' : volume.record(),
875 'volume_label' : volume.label(),
876 'owning_lib' : volume.owning_lib(),
880 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_items.unexpected_error'),E);
886 'cmd_link_as_multi_bib' : [
890 obj.data.stash_retrieve();
891 if (!obj.data.marked_multi_home_record) {
892 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.link_as_multi_bib.missing_bib'));
896 JSAN.use('util.functional');
898 var list = util.functional.filter_list(
901 return o.split(/_/)[0] == 'acp';
905 list = util.functional.map_list(
908 return obj.map_acp[ o ].barcode();
913 window.xulG.url_prefix(urls.MANAGE_MULTI_HOME_ITEMS),
915 { 'docid' : obj.data.marked_multi_home_record, 'barcodes' : list }
919 alert('Error in copy_browser.js, cmd_link_as_multi_bib: ' + E);
929 this.error.standard_unexpected_error_alert('cat.copy_browser.controller_init(): ',E);
933 'depth_menu_init' : function(params) {
938 for (var i = 0; i < obj.data.list.aout.length; i++) {
939 var type = obj.data.list.aout[i];
940 var depth = type.depth();
941 if ( depth > max_depth) { max_depth = depth; }
942 if (typeof list[depth] == 'undefined') {
950 list[depth][0] += ' / ' + type.opac_label();
953 ml = util.widgets.make_menulist( list, max_depth );
954 ml.setAttribute('id','depth_menu'); document.getElementById('x_depth_menu').appendChild(ml);
958 obj.default_depth = ev.target.value;
959 if (document.getElementById('refresh_button')) document.getElementById('refresh_button').focus();
960 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
961 util.widgets.save_attributes(file, {
962 'lib_menu' : [ 'value' ],
963 'depth_menu' : [ 'value' ],
964 'show_acns' : [ 'checked' ],
965 'show_acps' : [ 'checked' ]
971 file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
972 util.widgets.load_attributes(file);
973 ml.value = ml.getAttribute('value');
975 ml.value = max_depth;
976 ml.setAttribute('value',ml.value);
981 alert('Error in copy_browser.js, depth_menu_init(): ' + E);
985 'library_menu_init' : function(params) {
989 obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
990 if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
991 JSAN.use('util.functional');
992 obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
994 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
996 JSAN.use('util.file'); JSAN.use('util.widgets');
998 var file; var list_data; var ml;
1000 file = new util.file('offline_ou_list');
1001 if (file._file.exists()) {
1002 list_data = file.get_object(); file.close();
1003 for (var i = 0; i < list_data[0].length; i++) { // make sure all entries are enabled
1004 list_data[0][i][2] = false;
1006 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
1007 ml.setAttribute('id','lib_menu'); document.getElementById('x_lib_menu').appendChild(ml);
1008 for (var i = 0; i < obj.org_ids.length; i++) {
1009 ml.getElementsByAttribute('value',obj.org_ids[i])[0].setAttribute('class','has_copies');
1011 ml.firstChild.addEventListener(
1014 document.getElementById('legend').setAttribute('hidden','false');
1018 ml.firstChild.addEventListener(
1021 document.getElementById('legend').setAttribute('hidden','true');
1025 ml.addEventListener(
1028 obj.default_lib = obj.data.hash.aou[ ev.target.value ];
1029 if (document.getElementById('refresh_button')) document.getElementById('refresh_button').focus();
1030 JSAN.use('util.file'); var file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
1031 util.widgets.save_attributes(file, {
1032 'lib_menu' : [ 'value' ],
1033 'depth_menu' : [ 'value' ],
1034 'show_acns' : [ 'checked' ],
1035 'show_acps' : [ 'checked' ]
1042 throw(document.getElementById('catStrings').getString('staff.cat.copy_browser.missing_library') + '\n');
1045 file = new util.file('copy_browser_prefs.'+obj.data.server_unadorned);
1046 util.widgets.load_attributes(file);
1047 ml.value = ml.getAttribute('value');
1049 ml.value = org.id();
1050 ml.setAttribute('value',ml.value);
1056 this.error.standard_unexpected_error_alert('cat.copy_browser.library_menu_init(): ',E);
1060 'show_consortial_count' : function() {
1063 obj.network.simple_request('FM_ACP_COUNT.authoritative',[ obj.data.tree.aou.id(), obj.docid ],function(req){
1065 var robj = req.getResultObject();
1066 var x = document.getElementById('consortial_total');
1067 if (x) x.setAttribute('value',robj[0].count);
1068 x = document.getElementById('consortial_available');
1069 if (x) x.setAttribute('value',robj[0].available);
1071 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.consortial_copy_count.error'),E);
1075 this.error.standard_unexpected_error_alert('cat.copy_browser.show_consortial_count: ',E);
1079 'show_my_libs' : function(org) {
1083 org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1085 if (typeof org != 'object') org = obj.data.hash.aou[ org ];
1087 obj.show_libs( org, false );
1089 var p_org = obj.data.hash.aou[ org.parent_ou() ];
1091 obj.funcs.push( function() {
1092 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1093 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
1094 document.getElementById('lib_menu').setAttribute('disabled','true');
1096 for (var i = 0; i < p_org.children().length; i++) {
1100 obj.show_libs( o, false );
1102 }( p_org.children()[i] )
1105 obj.funcs.push( function() {
1106 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1107 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
1108 document.getElementById('lib_menu').setAttribute('disabled','false');
1117 'show_all_libs' : function() {
1122 obj.show_libs( obj.data.tree.aou );
1124 obj.funcs.push( function() {
1125 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1126 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
1127 document.getElementById('lib_menu').setAttribute('disabled','true');
1130 for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
1131 var child = obj.data.tree.aou.children()[i];
1132 if (obj.data.hash.aout[child.ou_type()].depth() <= obj.default_depth
1133 && orgIsMine(obj.default_lib,child,obj.default_depth)) {
1143 obj.funcs.push( function() {
1144 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1145 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
1146 document.getElementById('lib_menu').setAttribute('disabled','false');
1154 'show_libs_with_copies' : function() {
1157 JSAN.use('util.functional');
1159 var orgs = util.functional.map_list(
1161 function(id) { return obj.data.hash.aou[id]; }
1164 if (a.shortname() < b.shortname()) return -1;
1165 if (a.shortname() > b.shortname()) return 1;
1169 obj.funcs.push( function() {
1170 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1171 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
1172 document.getElementById('lib_menu').setAttribute('disabled','true');
1175 for (var i = 0; i < orgs.length; i++) {
1179 obj.show_libs(o,false);
1184 obj.funcs.push( function() {
1185 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1186 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
1187 document.getElementById('lib_menu').setAttribute('disabled','false');
1195 'show_libs' : function(start_aou,show_open) {
1198 if (!start_aou) throw('show_libs: Need a start_aou');
1199 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1200 JSAN.use('util.functional');
1203 var temp_aou = start_aou;
1204 while ( temp_aou.parent_ou() ) {
1205 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
1206 parents.push( temp_aou );
1210 for (var i = 0; i < parents.length; i++) {
1214 obj.append_org(o,p,{'container':'true','open':'true'});
1216 }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
1222 return function() { obj.append_org(o,p); };
1223 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
1228 if (start_aou.children()) {
1229 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
1230 x.setAttribute('container','true');
1231 if (show_open) x.setAttribute('open','true');
1232 for (var i = 0; i < start_aou.children().length; i++) {
1233 var child = start_aou.children()[i];
1234 if (obj.data.hash.aout[child.ou_type()].depth() <= obj.default_depth
1235 && orgIsMine(obj.default_lib,child,obj.default_depth)) {
1238 return function() { obj.append_org(o,p); };
1239 }( child, start_aou )
1252 'on_select' : function(list,twisty) {
1254 for (var i = 0; i < list.length; i++) {
1255 var node = obj.map_tree[ list[i] ];
1256 //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
1257 var row_type = list[i].split('_')[0];
1258 var id = list[i].split('_')[1];
1260 case 'aou' : obj.on_select_org(id,twisty); break;
1261 case 'acn' : obj.on_select_acn(id,twisty); break;
1267 'on_select_acn' : function(acn_id,twisty) {
1270 var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
1271 obj.funcs.push( function() {
1272 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1273 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
1274 document.getElementById('lib_menu').setAttribute('disabled','true');
1276 if (acn_tree.copies()) {
1277 for (var i = 0; i < acn_tree.copies().length; i++) {
1281 obj.append_acp(c,a);
1283 }( acn_tree.copies()[i], acn_tree )
1287 obj.funcs.push( function() {
1288 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1289 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
1290 document.getElementById('lib_menu').setAttribute('disabled','false');
1297 'on_select_org' : function(org_id,twisty) {
1300 var org = obj.data.hash.aou[ org_id ];
1301 obj.funcs.push( function() {
1302 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1303 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','true');
1304 document.getElementById('lib_menu').setAttribute('disabled','true');
1306 if (org.children()) {
1307 for (var i = 0; i < org.children().length; i++) {
1308 var child = org.children()[i];
1309 if (obj.data.hash.aout[child.ou_type()].depth() <= obj.default_depth
1310 && orgIsMine(obj.default_lib,child,obj.default_depth)) {
1321 if (obj.map_acn[ 'aou_' + org_id ]) {
1322 for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
1326 obj.append_acn(o,a);
1328 }( org, obj.map_acn[ 'aou_' + org_id ][i] )
1332 obj.funcs.push( function() {
1333 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1334 document.getElementById('cmd_show_libs_with_copies').setAttribute('disabled','false');
1335 document.getElementById('lib_menu').setAttribute('disabled','false');
1338 alert('Error in copy_browser.js, on_select_org(): ' + E);
1342 'append_org' : function (org,parent_org,params) {
1344 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1345 obj.error.consoleService.logStringMessage('append_org: org = ' + org.shortname() + ' parent_org = ' + (parent_org ? parent_org.shortname() : '') + ' params = ' + js2JSON(params) + '\n');
1347 if (obj.map_tree[ 'aou_' + org.id() ]) {
1348 var x = obj.map_tree[ 'aou_' + org.id() ];
1350 for (var i in params) {
1351 x.setAttribute(i,params[i]);
1363 'skip_all_columns_except' : [0,1,2],
1364 'retrieve_id' : 'aou_' + org.id(),
1366 'no_auto_select' : true,
1370 if ( obj.org_ids.indexOf( Number( org.id() ) ) == -1 ) {
1371 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) {
1372 data.row.my.volume_count = '0';
1373 data.row.my.copy_count = '<0>';
1375 data.row.my.volume_count = '';
1376 data.row.my.copy_count = '';
1379 var v_count = 0; var c_count = 0;
1380 acn_tree_list = obj.network.simple_request(
1381 'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS.authoritative',
1382 [ ses(), obj.docid, [ org.id() ] ]
1384 for (var i = 0; i < acn_tree_list.length; i++) {
1386 obj.map_acn[ 'acn_' + acn_tree_list[i].id() ] = function(r){return r;}(acn_tree_list[i]);
1387 var copies = acn_tree_list[i].copies(); if (copies) c_count += copies.length;
1388 for (var j = 0; j < copies.length; j++) {
1389 obj.map_acp[ 'acp_' + copies[j].id() ] = function(r){return r;}(copies[j]);
1392 data.row.my.volume_count = v_count;
1393 data.row.my.copy_count = '<' + c_count + '>';
1396 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
1398 var nparams = obj.list.append(data);
1399 var node = nparams.my_node;
1401 for (var i in params) {
1402 node.setAttribute(i,params[i]);
1405 obj.map_tree[ 'aou_' + org.id() ] = node;
1407 if (org.children()) {
1408 node.setAttribute('container','true');
1412 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
1413 data.node.setAttribute('open','true');
1416 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
1419 if (acn_tree_list) {
1420 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
1421 node.setAttribute('container','true');
1424 if (document.getElementById('show_acns').checked) {
1425 node.setAttribute('open','true');
1426 obj.funcs.push( function() { obj.on_select_org( org.id() ); } );
1435 'append_acn' : function( org, acn_tree, params ) {
1438 if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
1439 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
1441 for (var i in params) {
1442 x.setAttribute(i,params[i]);
1448 var parent_node = obj.map_tree[ 'aou_' + org.id() ];
1454 'volume_count' : '',
1455 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
1458 'skip_all_columns_except' : [0,1,2],
1459 'retrieve_id' : 'acn_' + acn_tree.id(),
1460 'node' : parent_node,
1462 'no_auto_select' : true,
1464 var nparams = obj.list.append(data);
1465 var node = nparams.my_node;
1466 obj.map_tree[ 'acn_' + acn_tree.id() ] = node;
1468 for (var i in params) {
1469 node.setAttribute(i,params[i]);
1472 if (acn_tree.copies()) {
1473 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
1474 node.setAttribute('container','true');
1476 if (document.getElementById('show_acps').checked) {
1477 node.setAttribute('open','true');
1478 obj.funcs.push( function() { obj.on_select_acn( acn_tree.id() ); } );
1487 'append_acp' : function( acp_item, acn_tree, params ) {
1490 if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
1491 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
1493 for (var i in params) {
1494 x.setAttribute(i,params[i]);
1500 var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
1504 'doc_id' : obj.docid,
1505 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
1509 acp_item.circulations()
1511 acp_item.circulations().length > 0
1512 ? acp_item.circulations()[0]
1516 'volume_count' : '',
1520 'retrieve_id' : 'acp_' + acp_item.id(),
1521 'node' : parent_node,
1523 'no_auto_select' : true,
1525 var nparams = obj.list.append(data);
1526 var node = nparams.my_node;
1527 obj.map_tree[ 'acp_' + acp_item.id() ] = node;
1529 for (var i in params) {
1530 node.setAttribute(i,params[i]);
1540 'list_init' : function( params ) {
1543 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1546 JSAN.use('circ.util');
1549 'id' : 'tree_location',
1550 'label' : document.getElementById('catStrings').getString('staff.cat.copy_browser.list_init.tree_location'),
1551 'flex' : 1, 'primary' : true, 'hidden' : false,
1552 'render' : function(my) { return my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"; },
1555 'id' : 'volume_count',
1556 'label' : document.getElementById('catStrings').getString('staff.cat.copy_browser.list_init.volume_count'),
1557 'flex' : 0, 'primary' : false, 'hidden' : false,
1558 'render' : function(my) { return my.volume_count; },
1561 'id' : 'copy_count',
1562 'label' : document.getElementById('catStrings').getString('staff.cat.copy_browser.list_init.copy_count'),
1564 'primary' : false, 'hidden' : false,
1565 'render' : function(my) { return my.copy_count; },
1570 'location' : { 'hidden' : false },
1571 'circ_lib' : { 'hidden' : false },
1572 'owning_lib' : { 'hidden' : false },
1573 'call_number' : { 'hidden' : false },
1574 'parts' : { 'hidden' : false },
1575 'due_date' : { 'hidden' : false },
1576 'acp_status' : { 'hidden' : false },
1604 'acp_mint_condition',
1610 JSAN.use('util.list'); obj.list = new util.list('copy_tree');
1613 'no_auto_select' : true,
1614 'columns' : columns,
1615 'map_row_to_columns' : circ.util.std_map_row_to_columns(' '),
1616 'retrieve_row' : function(params) {
1618 var row = params.row;
1621 if (!row.my.mvr) obj.funcs.push(
1624 row.my.mvr = obj.network.request(
1625 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
1626 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
1627 [ row.my.circ.target_copy() ]
1636 row.my.acp = obj.network.request(
1637 api.FM_ACP_RETRIEVE.app,
1638 api.FM_ACP_RETRIEVE.method,
1639 [ row.my.circ.target_copy() ]
1642 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1647 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
1653 if (typeof params.on_retrieve == 'function') {
1654 params.on_retrieve(row);
1662 'on_click' : function(ev) {
1663 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
1664 var row = {}; var col = {}; var nobj = {};
1665 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
1666 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
1667 var node = obj.list.node.contentView.getItemAtIndex(row.value);
1668 var list = [ node.getAttribute('retrieve_id') ];
1669 if (typeof obj.on_select == 'function') {
1670 obj.on_select(list,true);
1672 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1673 window.xulG.on_select(list);
1676 'on_select' : function(ev) {
1677 JSAN.use('util.functional');
1678 var sel = obj.list.retrieve_selection();
1679 obj.controller.view.sel_clip.disabled = sel.length < 1;
1680 obj.sel_list = util.functional.map_list(
1682 function(o) { return o.getAttribute('retrieve_id'); }
1684 obj.toggle_actions();
1685 if (typeof obj.on_select == 'function') {
1686 obj.on_select(obj.sel_list);
1688 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1689 window.xulG.on_select(obj.sel_list);
1696 this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
1701 'toggle_actions' : function() {
1704 var found_aou = false; var found_acn = false; var found_acp = false;
1705 var found_aou_with_can_have_vols = false;
1706 var sel_copy_libs = {};
1707 for (var i = 0; i < obj.sel_list.length; i++) {
1708 var type = obj.sel_list[i].split(/_/)[0];
1712 var org = obj.data.hash.aou[ obj.sel_list[i].split(/_/)[1] ];
1713 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) found_aou_with_can_have_vols = true;
1715 case 'acn' : found_acn = true; break;
1721 obj.map_acp[obj.sel_list[i]].call_number()
1727 obj.controller.view.cmd_add_items.setAttribute('disabled','true');
1728 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','true');
1729 obj.controller.view.cmd_edit_items.setAttribute('disabled','true');
1730 obj.controller.view.cmd_delete_items.setAttribute('disabled','true');
1731 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','true');
1732 obj.controller.view.cmd_add_volumes.setAttribute('disabled','true');
1733 obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
1734 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','true');
1735 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','true');
1736 obj.controller.view.cmd_mark_volume.setAttribute('disabled','true');
1737 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','true');
1738 obj.controller.view.cmd_transfer_items.setAttribute('disabled','true');
1739 obj.controller.view.sel_copy_details.setAttribute('disabled','true');
1740 obj.controller.view.cmd_create_brt.setAttribute('disabled','true');
1741 obj.controller.view.cmd_book_item_now.setAttribute('disabled','true');
1742 obj.controller.view.sel_patron.setAttribute('disabled','true');
1743 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
1744 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
1745 if (found_aou && found_aou_with_can_have_vols) {
1746 obj.controller.view.cmd_add_volumes.setAttribute('disabled','false');
1747 obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
1750 obj.controller.view.cmd_edit_volumes.setAttribute('disabled','false');
1751 obj.controller.view.cmd_delete_volumes.setAttribute('disabled','false');
1752 obj.controller.view.cmd_mark_volume.setAttribute('disabled','false');
1753 obj.controller.view.cmd_add_items.setAttribute('disabled','false');
1754 obj.controller.view.cmd_transfer_volume.setAttribute('disabled','false');
1757 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
1758 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
1759 obj.controller.view.cmd_add_items_to_buckets.setAttribute('disabled','false');
1760 obj.controller.view.cmd_edit_items.setAttribute('disabled','false');
1761 obj.controller.view.cmd_delete_items.setAttribute('disabled','false');
1762 obj.controller.view.cmd_print_spine_labels.setAttribute('disabled','false');
1763 obj.controller.view.cmd_transfer_items.setAttribute('disabled','false');
1764 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
1765 obj.controller.view.cmd_create_brt.setAttribute('disabled','false');
1766 obj.controller.view.sel_patron.setAttribute('disabled','false');
1768 var L = 0; for (var k in sel_copy_libs) L++;
1770 obj.controller.view.cmd_book_item_now.setAttribute('disabled','false');
1774 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.actions.error'),E);
1778 'refresh_list' : function() {
1785 obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
1786 if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
1787 JSAN.use('util.functional');
1788 obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
1789 obj.show_my_libs( obj.default_lib.id() );
1790 // FIXME - we get a null from the copy_count call if we call it too quickly here
1791 setTimeout( function() { obj.show_consortial_count(); }, 2000 );
1793 this.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.refresh_list.error'),E);
1798 dump('exiting cat.copy_browser.js\n');