1 dump('entering serial/manage_subs.js\n');
4 if (typeof serial == 'undefined') serial = {};
5 serial.manage_subs = function (params) {
7 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
8 JSAN.use('util.error'); this.error = new util.error();
10 dump('serial/manage_subs: ' + E + '\n');
14 serial.manage_subs.prototype = {
23 'editor_indexes' : { 'ssub' : 1, 'sdist' : 2, 'siss' : 3, 'scap' : 4 },
25 'ids_from_sel_list' : function(type) {
27 JSAN.use('util.functional');
29 var list = util.functional.map_list(
30 util.functional.filter_list(
33 return o.split(/_/)[0] == type;
37 return o.split(/_/)[1];
44 'editor_init' : function(type, mode, params) {
47 $('serial_manage_subs_editor_deck').selectedIndex = obj.editor_indexes[type];
48 var editor_type = type + '_editor';
49 if (typeof obj[editor_type] == 'undefined') {
50 JSAN.use('serial.' + editor_type);
51 obj[editor_type] = new serial[editor_type]();
54 params.do_edit = true;
55 params.handle_update = true;
57 params.trigger_refresh = true;
58 params.refresh_command = function () {obj.refresh_list();};
60 obj[editor_type].init(params);
62 obj.error.standard_unexpected_error_alert('editor_init() error',E);
66 'do_delete' : function(type, method, overridable_events) {
69 JSAN.use('util.functional');
71 var list = util.functional.filter_list(
74 return o.split(/_/)[0] == type;
78 list = util.functional.map_list(
81 return JSON2js( js2JSON( obj['map_' + type][ type + '_' + o.split(/_/)[1] ] ) );
85 //TODO: proper messages
87 if (list.length != 1) {
88 delete_msg = document.getElementById('serialStrings').getFormattedString('staff.serial.manage_subs.delete_' + type + '.confirm.plural', [list.length]);
90 delete_msg = document.getElementById('serialStrings').getString('staff.serial.manage_subs.delete_' + type + '.confirm');
92 var r = obj.error.yns_alert(
94 document.getElementById('serialStrings').getString('staff.serial.manage_subs.delete_' + type + '.title'),
95 document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.delete'),
96 document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.cancel'),
98 document.getElementById('commonStrings').getString('common.confirm')
102 for (var i = 0; i < list.length; i++) {
103 list[i].isdeleted('1');
105 var robj = obj.network.request(
108 [ ses(), list, true ],
111 'title' : document.getElementById('serialStrings').getString('staff.serial.manage_subs.delete_' + type + '.override'),
112 'overridable_events' : overridable_events
115 if (robj == null) throw(robj);
116 if (typeof robj.ilsevent != 'undefined') {
117 if (robj.ilsevent != 0) {
118 var overridable = false;
119 for (i = 0; i < overridable_events.length; i++) {
120 if (overridable_events[i] == robj.ilsevent) {
125 if (!overridable) throw(robj);
131 obj.error.standard_unexpected_error_alert(document.getElementById('serialStrings').getString('staff.serial.manage_subs.delete.error'),E);
136 'init' : function( params ) {
139 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
142 obj.docid = params.docid;
144 JSAN.use('util.network'); obj.network = new util.network();
145 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
146 JSAN.use('util.controller'); obj.controller = new util.controller();
150 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
153 function() { obj.list.clipboard(); }
158 alert(document.getElementById('commonStrings').getString('common.unimplemented'));
161 'cmd_show_my_libs' : [
167 'cmd_show_all_libs' : [
173 'cmd_show_libs_with_distributions' : [
176 obj.show_libs_with_distributions();
190 var list = obj.ids_from_sel_list('ssub');
191 if (list.length == 0) list = obj.ids_from_sel_list('scap-group');
192 if (list.length == 0) return;
194 /*TODO: permission check?
195 //populate 'list' with owning_libs of subs, TODO
198 edit = obj.network.request(
199 api.PERM_MULTI_ORG_CHECK.app,
200 api.PERM_MULTI_ORG_CHECK.method,
203 obj.data.list.au[0].id(),
207 ).length == 0 ? 1 : 0;
209 obj.error.sdump('D_ERROR','batch permission check: ' + E);
212 if (edit==0) return; // no read-only view for this interface */
213 var new_scap = new scap();
214 new_scap.subscription(list[0]);//TODO: add multiple at once support?
217 params.scaps = [new_scap];
218 obj.editor_init('scap', 'add', params);
220 obj.error.standard_unexpected_error_alert(document.getElementById('serialStrings').getString('staff.serial.manage_subs.add.error'),E);
228 var list = obj.ids_from_sel_list('ssub');
229 if (list.length == 0) list = obj.ids_from_sel_list('siss-group');
230 if (list.length == 0) return;
232 /*TODO: permission check?
233 //populate 'list' with owning_libs of subs, TODO
236 edit = obj.network.request(
237 api.PERM_MULTI_ORG_CHECK.app,
238 api.PERM_MULTI_ORG_CHECK.method,
241 obj.data.list.au[0].id(),
245 ).length == 0 ? 1 : 0;
247 obj.error.sdump('D_ERROR','batch permission check: ' + E);
250 if (edit==0) return; // no read-only view for this interface */
251 var new_siss = new siss();
252 new_siss.subscription(list[0]);//TODO: add multiple at once support?
255 params.sisses = [new_siss];
256 obj.editor_init('siss', 'add', params);
258 obj.error.standard_unexpected_error_alert(document.getElementById('serialStrings').getString('staff.serial.manage_subs.add.error'),E);
266 var list = obj.ids_from_sel_list('ssub');
267 if (list.length == 0) list = obj.ids_from_sel_list('sdist-group');
268 if (list.length == 0) return;
270 /*TODO: permission check?
271 //populate 'list' with owning_libs of subs, TODO
274 edit = obj.network.request(
275 api.PERM_MULTI_ORG_CHECK.app,
276 api.PERM_MULTI_ORG_CHECK.method,
279 obj.data.list.au[0].id(),
283 ).length == 0 ? 1 : 0;
285 obj.error.sdump('D_ERROR','batch permission check: ' + E);
288 if (edit==0) return; // no read-only view for this interface */
289 var new_sdist = new sdist();
290 new_sdist.subscription(list[0]);//TODO: add multiple at once support?
291 new_sdist.holding_lib(obj.map_ssub['ssub_' + list[0]].owning_lib());//default to sub owning lib
292 new_sdist.label('Default');
295 params.sdists = [new_sdist];
296 obj.editor_init('sdist', 'add', params);
298 obj.error.standard_unexpected_error_alert(document.getElementById('serialStrings').getString('staff.serial.manage_subs.add.error'),E);
302 'cmd_delete_scap' : [
305 var overridable_events = [
306 11001 // SERIAL_CAPTION_AND_PATTERN_HAS_ISSUANCES
308 obj.do_delete('scap', 'open-ils.serial.caption_and_pattern.batch.update', overridable_events);
311 'cmd_delete_sdist' : [
314 var overridable_events = [ //TODO: proper overrides
316 obj.do_delete('sdist', 'open-ils.serial.distribution.fleshed.batch.update', overridable_events);
319 'cmd_delete_siss' : [
322 var overridable_events = [ //TODO: proper overrides
324 obj.do_delete('siss', 'open-ils.serial.issuance.fleshed.batch.update', overridable_events);
327 'cmd_delete_ssub' : [
330 var overridable_events = [
331 11000 // SERIAL_SUBSCRIPTION_NOT_EMPTY
333 obj.do_delete('ssub', 'open-ils.serial.subscription.fleshed.batch.update', overridable_events);
336 /*dbw2 'cmd_delete_ssub' : [
340 JSAN.use('util.functional');
342 var list = util.functional.filter_list(
345 return o.split(/_/)[0] == 'ssub';
349 list = util.functional.map_list(
352 return JSON2js( js2JSON( obj.map_ssub[ 'ssub_' + o.split(/_/)[1] ] ) );
357 if (list.length == 1) {
358 //TODO: correct prompts
359 del_prompt = document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.prompt');
361 del_prompt = document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.delete_volume.prompt.plural', [list.length]);
364 var r = obj.error.yns_alert(
366 document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.title'),
367 document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.delete'),
368 document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.cancel'),
370 document.getElementById('commonStrings').getString('common.confirm')
374 for (var i = 0; i < list.length; i++) {
375 list[i].isdeleted('1');
377 var robj = obj.network.simple_request(
378 'FM_ACN_TREE_UPDATE',
379 [ ses(), list, true ],
382 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.override'),
383 'overridable_events' : [
387 if (robj == null) throw(robj);
388 if (typeof robj.ilsevent != 'undefined') {
389 if (robj.ilsevent == 1206 ) { // VOLUME_NOT_EMPTY
390 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain'));
393 if (robj.ilsevent != 0) throw(robj);
395 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.success'));
399 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.exception'),E);
405 'cmd_mark_library' : [
409 var list = obj.ids_from_sel_list('aou');
410 if (list.length == 1) {
411 obj.data.marked_library = { 'lib' : list[0], 'docid' : obj.docid };
412 obj.data.stash('marked_library');
413 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.alert'));
416 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.prompt'),
417 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.title'),
418 document.getElementById('commonStrings').getString('common.ok'),
421 document.getElementById('commonStrings').getString('common.confirm')
425 obj.error.standard_unexpected_error_alert('manage_subs.js -> mark library',E);
430 'cmd_mark_subscription' : [
434 var list = obj.ids_from_sel_list('ssub');
435 if (list.length == 1) {
436 obj.data.marked_subscription = list[0];
437 obj.data.stash('marked_subscription');
438 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.alert'));
441 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.prompt'),
442 document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.title'),
443 document.getElementById('commonStrings').getString('common.ok'),
446 document.getElementById('commonStrings').getString('common.confirm')
450 obj.error.standard_unexpected_error_alert('manage_subs.js -> mark subscription',E);
454 'cmd_add_subscriptions' : [
458 var list = obj.ids_from_sel_list('aou');
459 if (list.length == 0) return;
460 //TODO: permission check?
463 edit = obj.network.request(
464 api.PERM_MULTI_ORG_CHECK.app,
465 api.PERM_MULTI_ORG_CHECK.method,
468 obj.data.list.au[0].id(),
470 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
472 ).length == 0 ? 1 : 0;
474 obj.error.sdump('D_ERROR','batch permission check: ' + E);
478 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.permission_error'));
479 return; // no read-only view for this interface
481 var new_ssub = new ssub();
482 new_ssub.owning_lib(list[0]);//TODO: add multiple at once support?
484 new_ssub.record_entry(obj.docid);
486 params.ssubs = [new_ssub];
487 obj.editor_init('ssub', 'add', params);
489 obj.error.standard_unexpected_error_alert(document.getElementById('serialStrings').getString('staff.serial.manage_subs.add.error'),E);
493 'cmd_transfer_subscription' : [
497 obj.data.stash_retrieve();
498 if (!obj.data.marked_library) {
499 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_volume.alert'));
503 var list = obj.ids_from_sel_list('ssub');
505 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
507 JSAN.use('util.functional');
509 var ssub_list = util.functional.map_list(
512 return obj.map_ssub[ 'ssub_' + o ].start_date();
514 ).join(document.getElementById('commonStrings').getString('common.grouping_string'));
516 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
517 xml += '<description>';
518 xml += document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.transfer.prompt', [ssub_list, obj.data.hash.aou[ obj.data.marked_library.lib ].shortname()]);
519 xml += '</description>';
520 xml += '<hbox><button label="' + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.submit.label') + '" name="fancy_submit"/>';
521 xml += '<button label="'
522 + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.cancel.label')
524 + document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.cancel.accesskey')
525 + '" name="fancy_cancel"/></hbox>';
526 xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + obj.data.marked_library.docid + '"/>';
528 JSAN.use('OpenILS.data');
529 var data = new OpenILS.data(); data.init({'via':'stash'});
530 //data.temp_transfer = xml; data.stash('temp_transfer');
531 JSAN.use('util.window'); var win = new util.window();
532 var fancy_prompt_data = win.open(
533 urls.XUL_FANCY_PROMPT,
534 //+ '?xml_in_stash=temp_transfer'
535 //+ '&title=' + window.escape('Volume Transfer'),
536 'fancy_prompt', 'chrome,resizable,modal,width=500,height=300',
539 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.title')
543 if (fancy_prompt_data.fancy_status == 'incomplete') {
544 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.incomplete'));
548 var robj = obj.network.simple_request(
550 [ ses(), { 'docid' : obj.data.marked_library.docid, 'lib' : obj.data.marked_library.lib, 'subscriptions' : list } ],
553 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.override.failure'),
554 'overridable_events' : [
555 1208, // TITLE_LAST_COPY
556 1219, // COPY_REMOTE_CIRC_LIB
561 if (typeof robj.ilsevent != 'undefined') {
562 if (robj.ilsevent == 1221) { // ORG_CANNOT_HAVE_VOLS
563 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.ineligible_destination'));
568 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.success'));
572 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer.unexpected_error'),E);
578 'cmd_transfer_sdists' : [
582 obj.data.stash_retrieve();
583 if (!obj.data.marked_subscription) {
584 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_items.missing_volume'));
588 JSAN.use('util.functional');
590 var list = obj.ids_from_sel_list('sdist');
591 var subscription = obj.network.simple_request('FM_ACN_RETRIEVE.authoritative',[ obj.data.marked_subscription ]);
593 JSAN.use('cat.util'); cat.util.transfer_copies( {
594 'distribution_ids' : list,
595 'docid' : subscription.record(),
596 'subscription_label' : subscription.start_date(),
597 'owning_lib' : subscription.owning_lib(),
601 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_items.unexpected_error'),E);
606 'cmd_refresh_list' : [
612 'cmd_make_predictions' : [
616 var list = obj.ids_from_sel_list('ssub');
617 if (list.length == 0) {
618 alert('You must select a subscription before predicting issuances.'); //TODO: better error
622 var num_to_predict = prompt('How many items would you like to predict?',
624 'Number of Predicted Items');
625 num_to_predict = String( num_to_predict ).replace(/\D/g,'');
626 if (num_to_predict == '') {
627 alert('Invalid number entered!'); //TODO: better error
631 for (i = 0; i < list.length; i++) {
632 var robj = obj.network.request(
634 'open-ils.serial.make_predictions',
635 [ ses(), {"ssub_id":list[i], "num_to_predict":num_to_predict}]
637 util.functional.map_list(
640 alert('debug: ' + o.date_expected());
646 /*JSAN.use('util.functional');
647 var list = util.functional.map_list(
650 o.distribution(obj.sdist_id);
655 var robj = obj.network.request(
657 'open-ils.serial.item.fleshed.batch.update',
661 //obj.refresh_list('main');
664 obj.error.standard_unexpected_error_alert('cmd_make_predictions failed!',E);
668 /*dbw2 'sel_distribution_details' : [
671 JSAN.use('util.functional');
673 var list = util.functional.filter_list(
676 return o.split(/_/)[0] == 'sdist';
680 list = util.functional.map_list(
683 return o.split(/_/)[1];
687 JSAN.use('circ.util');
688 for (var i = 0; i < list.length; i++) {
689 circ.util.show_copy_details( list[i] );
693 'cmd_edit_sdists' : [
697 JSAN.use('util.functional');
699 var list = util.functional.filter_list(
702 return o.split(/_/)[0] == 'sdist';
706 list = util.functional.map_list(
709 return o.split(/_/)[1];
713 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
717 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E);
722 /*dbw2 'cmd_print_spine_labels' : [
726 JSAN.use('util.functional');
728 var list = util.functional.filter_list(
731 return o.split(/_/)[0] == 'sdist';
735 list = util.functional.map_list(
738 return obj.map_sdist[ o ];
742 obj.data.temp_barcodes_for_labels = util.functional.map_list( list, function(o){return o.barcode();}) ;
743 obj.data.stash('temp_barcodes_for_labels');
745 xulG.url_prefix( urls.XUL_SPINE_LABEL ),
746 { 'tab_name' : document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.tab') },
750 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.error'),E);
754 'cmd_edit_subscriptions' : [
758 JSAN.use('util.functional');
759 var list = util.functional.map_list(
760 util.functional.filter_list(
763 return o.split(/_/)[0] == 'ssub';
767 return o.split(/_/)[1];
770 if (list.length == 0) return;
774 edit = obj.network.request(
775 api.PERM_MULTI_ORG_CHECK.app,
776 api.PERM_MULTI_ORG_CHECK.method,
779 obj.data.list.au[0].id(),
780 util.functional.map_list(
783 return obj.map_ssub[ 'ssub_' + o ].owning_lib();
788 ).length == 0 ? 1 : 0;
790 obj.error.sdump('D_ERROR','batch permission check: ' + E);
794 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.permission_error'));
795 return; // no read-only view for this interface
798 list = util.functional.map_list(
801 var my_ssub = obj.map_ssub['ssub_' + o];
802 return function(r){return r;}(my_ssub);
807 if (list.length == 1) {
808 title = document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.title');
810 title = document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.title.plural');
813 JSAN.use('util.window'); var win = new util.window();
814 //obj.data.volumes_temp = js2JSON( list );
815 //obj.data.stash('volumes_temp');
816 var my_xulG = win.open(
817 window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR),
819 'chrome,modal,resizable',
820 { 'subscriptions' : JSON2js(js2JSON(list)) }
823 // FIXME -- need to unique the temp space, and not rely on modalness of window
824 //obj.data.stash_retrieve();
825 if (typeof my_xulG.update_these_subscriptions == 'undefined') { return; }
826 var subscriptions = my_xulG.subscriptions;
827 if (!subscriptions) return;
829 subscriptions = util.functional.filter_list(
832 return o.ischanged() == '1';
836 subscriptions = util.functional.map_list(
839 o.record( obj.docid ); // staff client 2 did not do this. Does it matter?
844 if (subscriptions.length == 0) return;
847 var r = obj.network.request(
848 api.FM_ACN_TREE_UPDATE.app,
849 api.FM_ACN_TREE_UPDATE.method,
850 [ ses(), subscriptions, true ]
852 if (typeof r.ilsevent != 'undefined') {
853 switch(Number(r.ilsevent)) {
854 case 1705 : // VOLUME_LABEL_EXISTS
855 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.failed'));
860 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.success'));
863 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.error'),E);
868 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.exception'),E);
876 obj.list_init(params);
878 obj.org_ids = obj.network.simple_request('FM_SSUB_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
879 if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
880 JSAN.use('util.functional');
881 obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
883 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
884 //obj.show_libs( org );
886 //obj.show_my_libs();
888 JSAN.use('util.file'); JSAN.use('util.widgets');
890 var file; var list_data; var ml;
892 file = new util.file('offline_ou_list');
893 if (file._file.exists()) {
894 list_data = file.get_object(); file.close();
895 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
896 ml.setAttribute('id','lib_menu'); document.getElementById('serial_sub_lib_menu').appendChild(ml);
897 //TODO: class this menu properly
898 for (var i = 0; i < obj.org_ids.length; i++) {
899 ml.getElementsByAttribute('value',obj.org_ids[i])[0].setAttribute('class','has_distributions');
901 ml.firstChild.addEventListener(
904 document.getElementById('legend').setAttribute('hidden','false');
908 ml.firstChild.addEventListener(
911 document.getElementById('legend').setAttribute('hidden','true');
918 if (document.getElementById('refresh_button')) document.getElementById('refresh_button').focus();
919 JSAN.use('util.file'); var file = new util.file('manage_subs_prefs.'+obj.data.server_unadorned);
920 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_ssubs' : [ 'checked' ], 'show_groups' : [ 'checked' ] });
926 throw(document.getElementById('catStrings').getString('staff.cat.copy_browser.missing_library') + '\n');
929 file = new util.file('manage_subs_prefs.'+obj.data.server_unadorned);
930 util.widgets.load_attributes(file);
931 ml.value = ml.getAttribute('value');
934 ml.setAttribute('value',ml.value);
937 document.getElementById('show_ssubs').addEventListener(
940 JSAN.use('util.file'); var file = new util.file('manage_subs_prefs.'+obj.data.server_unadorned);
941 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_ssubs' : [ 'checked' ], 'show_groups' : [ 'checked' ] });
946 document.getElementById('show_groups').addEventListener(
949 JSAN.use('util.file'); var file = new util.file('manage_subs_prefs.'+obj.data.server_unadorned);
950 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_ssubs' : [ 'checked' ], 'show_groups' : [ 'checked' ] });
955 obj.show_my_libs( ml.value );
957 JSAN.use('util.exec'); var exec = new util.exec(20); exec.timer(obj.funcs,100);
959 obj.toggle_actions(); // disable menus initially
962 this.error.standard_unexpected_error_alert('serial/manage_subs.init: ',E);
966 'show_my_libs' : function(org) {
970 org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
972 if (typeof org != 'object') org = obj.data.hash.aou[ org ];
974 obj.show_libs( org, false );
976 var p_org = obj.data.hash.aou[ org.parent_ou() ];
978 obj.funcs.push( function() {
979 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
980 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','true');
981 document.getElementById('lib_menu').setAttribute('disabled','true');
983 for (var i = 0; i < p_org.children().length; i++) {
987 obj.show_libs( o, false );
989 }( p_org.children()[i] )
992 obj.funcs.push( function() {
993 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
994 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','false');
995 document.getElementById('lib_menu').setAttribute('disabled','false');
1003 'show_all_libs' : function() {
1008 obj.show_libs( obj.data.tree.aou );
1010 obj.funcs.push( function() {
1011 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1012 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','true');
1013 document.getElementById('lib_menu').setAttribute('disabled','true');
1016 for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
1022 }( obj.data.tree.aou.children()[i] )
1025 obj.funcs.push( function() {
1026 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1027 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','false');
1028 document.getElementById('lib_menu').setAttribute('disabled','false');
1036 'show_libs_with_distributions' : function() {
1039 JSAN.use('util.functional');
1041 var orgs = util.functional.map_list(
1043 function(id) { return obj.data.hash.aou[id]; }
1046 if (a.shortname() < b.shortname()) return -1;
1047 if (a.shortname() > b.shortname()) return 1;
1051 obj.funcs.push( function() {
1052 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1053 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','true');
1054 document.getElementById('lib_menu').setAttribute('disabled','true');
1057 for (var i = 0; i < orgs.length; i++) {
1061 obj.show_libs(o,false);
1066 obj.funcs.push( function() {
1067 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1068 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','false');
1069 document.getElementById('lib_menu').setAttribute('disabled','false');
1077 'show_libs' : function(start_aou,show_open) {
1080 if (!start_aou) throw('show_libs: Need a start_aou');
1081 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1082 JSAN.use('util.functional');
1085 var temp_aou = start_aou;
1086 while ( temp_aou.parent_ou() ) {
1087 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
1088 parents.push( temp_aou );
1092 for (var i = 0; i < parents.length; i++) {
1096 obj.append_org(o,p,{'container':'true','open':'true'});
1098 }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
1104 return function() { obj.append_org(o,p); };
1105 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
1110 if (start_aou.children()) {
1111 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
1112 x.setAttribute('container','true');
1113 if (show_open) x.setAttribute('open','true');
1114 for (var i = 0; i < start_aou.children().length; i++) {
1117 return function() { obj.append_org(o,p); };
1118 }( start_aou.children()[i], start_aou )
1130 'on_select' : function(list,twisty) {
1134 for (var i = 0; i < list.length; i++) {
1135 var row_type = list[i].split('_')[0];
1136 var id = list[i].split('_')[1];
1138 if (!sel_lists[row_type]) sel_lists[row_type] = [];
1139 sel_lists[row_type].push(id);
1143 case 'aou' : obj.on_click_aou(id,twisty); break;
1144 case 'ssub' : obj.on_select_ssub(id,twisty); break;
1150 if (!obj.focused_node_retrieve_id) return;
1152 var row_type = obj.focused_node_retrieve_id.split('_')[0];
1153 var id = obj.focused_node_retrieve_id.split('_')[1];
1155 if (sel_lists[row_type]) { // the type focused is in the selection (usually the case)
1157 case 'aou' : obj.on_click_aou(id,twisty); break;
1158 default: if (obj['on_click_' + row_type]) obj['on_click_' + row_type](sel_lists[row_type],twisty);
1163 'on_select_ssub' : function(ssub_id,twisty) {
1166 //typo? var ssub_tree = obj.map_sdist[ 'ssub_' + ssub_id ];
1167 var ssub_tree = obj.map_ssub[ 'ssub_' + ssub_id ];
1168 obj.funcs.push( function() {
1169 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1170 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','true');
1171 document.getElementById('lib_menu').setAttribute('disabled','true');
1173 if (ssub_tree.distributions()) {
1174 for (var i = 0; i < ssub_tree.distributions().length; i++) {
1178 obj.append_member(c,a,[],'sdist');
1180 }( ssub_tree.distributions()[i], ssub_tree )
1184 if (ssub_tree.issuances()) {
1185 for (var i = 0; i < ssub_tree.issuances().length; i++) {
1189 obj.append_member(c,a,[],'siss');
1191 }( ssub_tree.issuances()[i], ssub_tree )
1195 if (ssub_tree.scaps()) {
1196 for (var i = 0; i < ssub_tree.scaps().length; i++) {
1200 obj.append_member(c,a,[],'scap');
1202 }( ssub_tree.scaps()[i], ssub_tree )
1206 obj.funcs.push( function() {
1207 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1208 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','false');
1209 document.getElementById('lib_menu').setAttribute('disabled','false');
1216 'on_click_ssub' : function(ssub_ids,twisty) {
1219 // draw sdist editor
1220 if (typeof twisty == 'undefined') {
1222 params.ssub_ids = ssub_ids;
1223 obj.editor_init('ssub', 'edit', params);
1230 'on_click_sdist' : function(sdist_ids,twisty) {
1233 // draw sdist editor
1234 if (typeof twisty == 'undefined') {
1236 params.sdist_ids = sdist_ids;
1237 obj.editor_init('sdist', 'edit', params);
1244 'on_click_siss' : function(siss_ids,twisty) {
1248 if (typeof twisty == 'undefined') {
1250 params.siss_ids = siss_ids;
1251 obj.editor_init('siss', 'edit', params);
1258 'on_click_scap' : function(scap_ids,twisty) {
1262 if (typeof twisty == 'undefined') {
1264 params.scap_ids = scap_ids;
1265 obj.editor_init('scap', 'edit', params);
1272 'on_click_aou' : function(org_id,twisty) {
1274 var org = obj.data.hash.aou[ org_id ];
1275 obj.funcs.push( function() {
1276 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1277 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','true');
1278 document.getElementById('lib_menu').setAttribute('disabled','true');
1280 if (org.children()) {
1281 for (var i = 0; i < org.children().length; i++) {
1287 }(org.children()[i],org)
1291 if (obj.map_ssub[ 'aou_' + org_id ]) {
1292 for (var i = 0; i < obj.map_ssub[ 'aou_' + org_id ].length; i++) {
1296 obj.append_ssub(o,a);
1298 }( org, obj.map_ssub[ 'aou_' + org_id ][i] )
1302 obj.funcs.push( function() {
1303 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1304 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','false');
1305 document.getElementById('lib_menu').setAttribute('disabled','false');
1308 // remove current editor
1309 if (typeof twisty == 'undefined') {
1310 document.getElementById('serial_manage_subs_editor_deck').selectedIndex = 0;
1314 'append_org' : function (org,parent_org,params) {
1317 if (obj.map_tree[ 'aou_' + org.id() ]) {
1318 var x = obj.map_tree[ 'aou_' + org.id() ];
1320 for (var i in params) {
1321 x.setAttribute(i,params[i]);
1333 'skip_all_columns_except' : [0,1,2],
1334 'retrieve_id' : 'aou_' + org.id(),
1336 'no_auto_select' : true,
1340 if ( obj.org_ids.indexOf( Number( org.id() ) ) == -1 ) {
1341 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) {
1342 data.row.my.subscription_count = '0';
1343 //data.row.my.distribution_count = '<0>';
1345 data.row.my.subscription_count = '';
1346 //data.row.my.distribution_count = '';
1349 var v_count = 0; var d_count = 0;
1350 ssub_tree_list = obj.network.simple_request(
1351 'FM_SSUB_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS.authoritative',
1352 [ ses(), obj.docid, [ org.id() ] ]
1354 for (var i = 0; i < ssub_tree_list.length; i++) {
1356 obj.map_ssub[ 'ssub_' + ssub_tree_list[i].id() ] = function(r){return r;}(ssub_tree_list[i]);
1357 var distributions = ssub_tree_list[i].distributions();
1358 //if (distributions) d_count += distributions.length;
1359 for (var j = 0; j < distributions.length; j++) {
1360 obj.map_sdist[ 'sdist_' + distributions[j].id() ] = function(r){return r;}(distributions[j]);
1362 var issuances = ssub_tree_list[i].issuances();
1363 for (var j = 0; j < issuances.length; j++) {
1364 obj.map_siss[ 'siss_' + issuances[j].id() ] = function(r){return r;}(issuances[j]);
1366 var scaps = ssub_tree_list[i].scaps();
1367 for (var j = 0; j < scaps.length; j++) {
1368 obj.map_scap[ 'scap_' + scaps[j].id() ] = function(r){return r;}(scaps[j]);
1371 data.row.my.subscription_count = v_count;
1372 //data.row.my.distribution_count = '<' + d_count + '>';
1375 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
1377 var nparams = obj.list.append(data);
1378 var node = nparams.my_node;
1380 for (var i in params) {
1381 node.setAttribute(i,params[i]);
1384 obj.map_tree[ 'aou_' + org.id() ] = node;
1386 if (org.children()) {
1387 node.setAttribute('container','true');
1391 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
1392 data.node.setAttribute('open','true');
1395 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
1398 if (ssub_tree_list) {
1399 obj.map_ssub[ 'aou_' + org.id() ] = ssub_tree_list;
1400 node.setAttribute('container','true');
1403 if (document.getElementById('show_ssubs').checked) {
1404 obj.funcs.push( function() { obj.on_click_aou( org.id() ); } );
1405 node.setAttribute('open','true');
1414 'append_ssub' : function( org, ssub_tree, params ) {
1417 if (obj.map_tree[ 'ssub_' + ssub_tree.id() ]) {
1418 var x = obj.map_tree[ 'ssub_' + ssub_tree.id() ];
1420 for (var i in params) {
1421 x.setAttribute(i,params[i]);
1427 var parent_node = obj.map_tree[ 'aou_' + org.id() ];
1433 'subscription_count' : '',
1434 //'distribution_count' : ssub_tree.distributions() ? ssub_tree.distributions().length : '0',
1437 'skip_all_columns_except' : [0,1,2],
1438 'retrieve_id' : 'ssub_' + ssub_tree.id(),
1439 'node' : parent_node,
1441 'no_auto_select' : true,
1443 var nparams = obj.list.append(data);
1444 var node = nparams.my_node;
1445 obj.map_tree[ 'ssub_' + ssub_tree.id() ] = node;
1447 for (var i in params) {
1448 node.setAttribute(i,params[i]);
1451 if (ssub_tree.distributions() || ssub_tree.scaps() || ssub_tree.issuances()) {
1452 //did this support a later typo? obj.map_sdist[ 'ssub_' + ssub_tree.id() ] = ssub_tree;
1453 node.setAttribute('container','true');
1455 if (document.getElementById('show_groups').checked) {
1456 node.setAttribute('open','true');
1457 obj.funcs.push( function() { obj.on_select_ssub( ssub_tree.id(), true ); } );
1459 var sdist_group_node_data = {
1462 'label' : 'Distributions',
1465 'retrieve_id' : 'sdist-group_' + ssub_tree.id(),
1468 'no_auto_select' : true,
1470 nparams = obj.list.append(sdist_group_node_data);
1471 obj.map_tree[ 'ssub_sdist_group_' + ssub_tree.id() ] = nparams.my_node;
1473 var siss_group_node_data = {
1476 'label' : 'Issuances',
1479 'retrieve_id' : 'siss-group_' + ssub_tree.id(),
1482 'no_auto_select' : true,
1484 nparams = obj.list.append(siss_group_node_data);
1485 obj.map_tree[ 'ssub_siss_group_' + ssub_tree.id() ] = nparams.my_node;
1487 var scap_group_node_data = {
1490 'label' : 'Captions/Patterns',
1493 'retrieve_id' : 'scap-group_' + ssub_tree.id(),
1496 'no_auto_select' : true,
1498 nparams = obj.list.append(scap_group_node_data);
1499 obj.map_tree[ 'ssub_scap_group_' + ssub_tree.id() ] = nparams.my_node;
1506 'append_member' : function( item, ssub_tree, attributes, type ) {
1509 if (obj.map_tree[ type + '_' + item.id() ]) {
1510 var x = obj.map_tree[ type + '_' + item.id() ];
1512 for (var i in attributes) {
1513 x.setAttribute(i,attributes[i]);
1519 var parent_node = obj.map_tree[ 'ssub_' + type + '_group_' + ssub_tree.id() ];
1523 'aou' : obj.data.hash.aou[ ssub_tree.owning_lib() ],
1525 'subscription_count' : '',
1526 //'distribution_count' : '',
1529 'retrieve_id' : type + '_' + item.id(),
1530 'node' : parent_node,
1532 'no_auto_select' : true,
1534 data['row']['my'][type] = item; // TODO: future optimization: get only the IDs of these leaves, then fetch the full row in 'retrieve_row'
1535 var nparams = obj.list.append(data);
1536 var node = nparams.my_node;
1537 obj.map_tree[ type + '_' + item.id() ] = node;
1539 for (var i in attributes) {
1540 node.setAttribute(i,attributes[i]);
1550 'list_init' : function( params ) {
1553 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1556 JSAN.use('circ.util');
1559 'id' : 'tree_location',
1560 'label' : 'Location',
1561 'flex' : 1, 'primary' : true, 'hidden' : false,
1562 'render' : function(my) { return my.sdist ? my.sdist.label() : my.siss ? my.siss.label() : my.scap ? 'C/P : #' + my.scap.id() : my.ssub ? 'Subscription : #' + my.ssub.id() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : my.label ? my.label : "???"; },
1565 'id' : 'subscription_count',
1566 'label' : 'Subscriptions',
1567 'flex' : 0, 'primary' : false, 'hidden' : false,
1568 'render' : function(my) { return my.subscription_count; },
1571 'id' : 'distribution_count',
1572 'label' : 'Members',
1574 'primary' : false, 'hidden' : false,
1575 'render' : function(my) { return my.distribution_count; },
1578 JSAN.use('util.list'); obj.list = new util.list('subs_tree');
1581 'no_auto_select' : true,
1582 'columns' : columns,
1583 'map_row_to_columns' : circ.util.std_map_row_to_columns(' '),
1584 'retrieve_row' : function(params) {
1586 var row = params.row;
1590 if (typeof params.on_retrieve == 'function') {
1591 params.on_retrieve(row);
1599 'on_click' : function(ev) {
1600 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
1601 var row = {}; var col = {}; var nobj = {};
1602 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
1603 if ((row.value == -1)||(nobj.value != 'twisty')) { return; } // on_click runs for twistys only
1605 var node = obj.list.node.contentView.getItemAtIndex(row.value);
1606 var list = [ node.getAttribute('retrieve_id') ];
1607 if (typeof obj.on_select == 'function') {
1608 obj.on_select(list,true);
1610 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1611 window.xulG.on_select(list);
1614 'on_select' : function(ev) {
1615 JSAN.use('util.functional');
1617 // get the actual node clicked to determine which editor to use
1618 if (obj.list.node.view.selection.currentIndex > -1) {
1619 var node = obj.list.node.contentView.getItemAtIndex(obj.list.node.view.selection.currentIndex);
1620 obj.focused_node_retrieve_id = node.getAttribute('retrieve_id');
1623 var sel = obj.list.retrieve_selection();
1624 obj.controller.view.sel_clip.disabled = sel.length < 1;
1625 obj.sel_list = util.functional.map_list(
1627 function(o) { return o.getAttribute('retrieve_id'); }
1629 obj.toggle_actions();
1630 if (typeof obj.on_select == 'function') {
1631 obj.on_select(obj.sel_list);
1633 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1634 window.xulG.on_select(obj.sel_list);
1640 obj.controller.render();
1643 this.error.sdump('D_ERROR','serial/manage_subs.list_init: ' + E + '\n');
1648 'toggle_actions' : function() {
1651 var found_aou = false; var found_ssub = false; var found_sdist = false; var found_siss = false; var found_scap = false; var found_sdist_group = false; var found_siss_group = false; var found_scap_group = false;
1652 for (var i = 0; i < obj.sel_list.length; i++) {
1653 var type = obj.sel_list[i].split(/_/)[0];
1658 case 'ssub' : found_ssub = true; break;
1659 case 'sdist' : found_sdist = true; break;
1660 case 'siss' : found_siss = true; break;
1661 case 'scap' : found_scap = true; break;
1662 case 'sdist-group' : found_sdist_group = true; break;
1663 case 'siss-group' : found_siss_group = true; break;
1664 case 'scap-group' : found_scap_group = true; break;
1667 obj.controller.view.cmd_add_sdist.setAttribute('disabled','true');
1668 obj.controller.view.cmd_add_siss.setAttribute('disabled','true');
1669 obj.controller.view.cmd_add_scap.setAttribute('disabled','true');
1670 obj.controller.view.cmd_make_predictions.setAttribute('disabled','true');
1671 obj.controller.view.cmd_delete_sdist.setAttribute('disabled','true');
1672 obj.controller.view.cmd_delete_siss.setAttribute('disabled','true');
1673 obj.controller.view.cmd_delete_scap.setAttribute('disabled','true');
1674 obj.controller.view.cmd_add_subscriptions.setAttribute('disabled','true');
1675 obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
1676 obj.controller.view.cmd_delete_ssub.setAttribute('disabled','true');
1677 obj.controller.view.cmd_mark_subscription.setAttribute('disabled','true');
1678 obj.controller.view.cmd_transfer_subscription.setAttribute('disabled','true');
1679 obj.controller.view.cmd_transfer_sdists.setAttribute('disabled','true');
1681 obj.controller.view.cmd_add_subscriptions.setAttribute('disabled','false');
1682 obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
1685 obj.controller.view.cmd_delete_ssub.setAttribute('disabled','false');
1686 obj.controller.view.cmd_mark_subscription.setAttribute('disabled','false');
1687 obj.controller.view.cmd_add_sdist.setAttribute('disabled','false');
1688 obj.controller.view.cmd_add_siss.setAttribute('disabled','false');
1689 obj.controller.view.cmd_add_scap.setAttribute('disabled','false');
1690 obj.controller.view.cmd_transfer_subscription.setAttribute('disabled','false');
1691 obj.controller.view.cmd_make_predictions.setAttribute('disabled','false');
1693 if (found_sdist_group) {
1694 obj.controller.view.cmd_add_sdist.setAttribute('disabled','false');
1696 if (found_siss_group) {
1697 obj.controller.view.cmd_add_siss.setAttribute('disabled','false');
1699 if (found_scap_group) {
1700 obj.controller.view.cmd_add_scap.setAttribute('disabled','false');
1703 obj.controller.view.cmd_delete_sdist.setAttribute('disabled','false');
1704 obj.controller.view.cmd_transfer_sdists.setAttribute('disabled','false');
1707 obj.controller.view.cmd_delete_siss.setAttribute('disabled','false');
1710 obj.controller.view.cmd_delete_scap.setAttribute('disabled','false');
1713 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.actions.error'),E);
1717 'refresh_list' : function() {
1726 obj.org_ids = obj.network.simple_request('FM_SSUB_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
1727 if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
1728 JSAN.use('util.functional');
1729 obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
1731 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1732 obj.show_libs( org );
1734 obj.show_my_libs( document.getElementById('lib_menu').value );
1736 this.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.refresh_list.error'),E);
1741 dump('exiting serial/manage_subs.js\n');