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 (per active pattern) 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 alert('Successfully predicted ' + robj.length + ' issuance(s) for subscription #' + list[i] + '.');
643 obj.error.standard_unexpected_error_alert('cmd_make_predictions failed!',E);
647 /*dbw2 'sel_distribution_details' : [
650 JSAN.use('util.functional');
652 var list = util.functional.filter_list(
655 return o.split(/_/)[0] == 'sdist';
659 list = util.functional.map_list(
662 return o.split(/_/)[1];
666 JSAN.use('circ.util');
667 for (var i = 0; i < list.length; i++) {
668 circ.util.show_copy_details( list[i] );
672 'cmd_edit_sdists' : [
676 JSAN.use('util.functional');
678 var list = util.functional.filter_list(
681 return o.split(/_/)[0] == 'sdist';
685 list = util.functional.map_list(
688 return o.split(/_/)[1];
692 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
696 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E);
701 /*dbw2 'cmd_print_spine_labels' : [
705 JSAN.use('util.functional');
707 var list = util.functional.filter_list(
710 return o.split(/_/)[0] == 'sdist';
714 list = util.functional.map_list(
717 return obj.map_sdist[ o ];
721 obj.data.temp_barcodes_for_labels = util.functional.map_list( list, function(o){return o.barcode();}) ;
722 obj.data.stash('temp_barcodes_for_labels');
724 xulG.url_prefix( urls.XUL_SPINE_LABEL ),
725 { 'tab_name' : document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.tab') },
729 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.error'),E);
733 'cmd_edit_subscriptions' : [
737 JSAN.use('util.functional');
738 var list = util.functional.map_list(
739 util.functional.filter_list(
742 return o.split(/_/)[0] == 'ssub';
746 return o.split(/_/)[1];
749 if (list.length == 0) return;
753 edit = obj.network.request(
754 api.PERM_MULTI_ORG_CHECK.app,
755 api.PERM_MULTI_ORG_CHECK.method,
758 obj.data.list.au[0].id(),
759 util.functional.map_list(
762 return obj.map_ssub[ 'ssub_' + o ].owning_lib();
767 ).length == 0 ? 1 : 0;
769 obj.error.sdump('D_ERROR','batch permission check: ' + E);
773 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.permission_error'));
774 return; // no read-only view for this interface
777 list = util.functional.map_list(
780 var my_ssub = obj.map_ssub['ssub_' + o];
781 return function(r){return r;}(my_ssub);
786 if (list.length == 1) {
787 title = document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.title');
789 title = document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.title.plural');
792 JSAN.use('util.window'); var win = new util.window();
793 //obj.data.volumes_temp = js2JSON( list );
794 //obj.data.stash('volumes_temp');
795 var my_xulG = win.open(
796 window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR),
798 'chrome,modal,resizable',
799 { 'subscriptions' : JSON2js(js2JSON(list)) }
802 // FIXME -- need to unique the temp space, and not rely on modalness of window
803 //obj.data.stash_retrieve();
804 if (typeof my_xulG.update_these_subscriptions == 'undefined') { return; }
805 var subscriptions = my_xulG.subscriptions;
806 if (!subscriptions) return;
808 subscriptions = util.functional.filter_list(
811 return o.ischanged() == '1';
815 subscriptions = util.functional.map_list(
818 o.record( obj.docid ); // staff client 2 did not do this. Does it matter?
823 if (subscriptions.length == 0) return;
826 var r = obj.network.request(
827 api.FM_ACN_TREE_UPDATE.app,
828 api.FM_ACN_TREE_UPDATE.method,
829 [ ses(), subscriptions, true ]
831 if (typeof r.ilsevent != 'undefined') {
832 switch(Number(r.ilsevent)) {
833 case 1705 : // VOLUME_LABEL_EXISTS
834 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.failed'));
839 alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.success'));
842 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.error'),E);
847 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.exception'),E);
855 obj.list_init(params);
857 obj.org_ids = obj.network.simple_request('FM_SSUB_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
858 if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
859 JSAN.use('util.functional');
860 obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
862 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
863 //obj.show_libs( org );
865 //obj.show_my_libs();
867 JSAN.use('util.file'); JSAN.use('util.widgets');
869 var file; var list_data; var ml;
871 file = new util.file('offline_ou_list');
872 if (file._file.exists()) {
873 list_data = file.get_object(); file.close();
874 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
875 ml.setAttribute('id','lib_menu'); document.getElementById('serial_sub_lib_menu').appendChild(ml);
876 //TODO: class this menu properly
877 for (var i = 0; i < obj.org_ids.length; i++) {
878 ml.getElementsByAttribute('value',obj.org_ids[i])[0].setAttribute('class','has_distributions');
880 ml.firstChild.addEventListener(
883 document.getElementById('legend').setAttribute('hidden','false');
887 ml.firstChild.addEventListener(
890 document.getElementById('legend').setAttribute('hidden','true');
897 if (document.getElementById('refresh_button')) document.getElementById('refresh_button').focus();
898 JSAN.use('util.file'); var file = new util.file('manage_subs_prefs.'+obj.data.server_unadorned);
899 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_ssubs' : [ 'checked' ], 'show_groups' : [ 'checked' ] });
905 throw(document.getElementById('catStrings').getString('staff.cat.copy_browser.missing_library') + '\n');
908 file = new util.file('manage_subs_prefs.'+obj.data.server_unadorned);
909 util.widgets.load_attributes(file);
910 ml.value = ml.getAttribute('value');
913 ml.setAttribute('value',ml.value);
916 document.getElementById('show_ssubs').addEventListener(
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' ] });
925 document.getElementById('show_groups').addEventListener(
928 JSAN.use('util.file'); var file = new util.file('manage_subs_prefs.'+obj.data.server_unadorned);
929 util.widgets.save_attributes(file, { 'lib_menu' : [ 'value' ], 'show_ssubs' : [ 'checked' ], 'show_groups' : [ 'checked' ] });
934 obj.show_my_libs( ml.value );
936 JSAN.use('util.exec'); var exec = new util.exec(20); exec.timer(obj.funcs,100);
938 obj.toggle_actions(); // disable menus initially
941 this.error.standard_unexpected_error_alert('serial/manage_subs.init: ',E);
945 'show_my_libs' : function(org) {
949 org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
951 if (typeof org != 'object') org = obj.data.hash.aou[ org ];
953 obj.show_libs( org, false );
955 var p_org = obj.data.hash.aou[ org.parent_ou() ];
957 obj.funcs.push( function() {
958 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
959 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','true');
960 document.getElementById('lib_menu').setAttribute('disabled','true');
962 for (var i = 0; i < p_org.children().length; i++) {
966 obj.show_libs( o, false );
968 }( p_org.children()[i] )
971 obj.funcs.push( function() {
972 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
973 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','false');
974 document.getElementById('lib_menu').setAttribute('disabled','false');
982 'show_all_libs' : function() {
987 obj.show_libs( obj.data.tree.aou );
989 obj.funcs.push( function() {
990 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
991 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','true');
992 document.getElementById('lib_menu').setAttribute('disabled','true');
995 for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
1001 }( obj.data.tree.aou.children()[i] )
1004 obj.funcs.push( function() {
1005 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1006 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','false');
1007 document.getElementById('lib_menu').setAttribute('disabled','false');
1015 'show_libs_with_distributions' : function() {
1018 JSAN.use('util.functional');
1020 var orgs = util.functional.map_list(
1022 function(id) { return obj.data.hash.aou[id]; }
1025 if (a.shortname() < b.shortname()) return -1;
1026 if (a.shortname() > b.shortname()) return 1;
1030 obj.funcs.push( function() {
1031 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1032 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','true');
1033 document.getElementById('lib_menu').setAttribute('disabled','true');
1036 for (var i = 0; i < orgs.length; i++) {
1040 obj.show_libs(o,false);
1045 obj.funcs.push( function() {
1046 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1047 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','false');
1048 document.getElementById('lib_menu').setAttribute('disabled','false');
1056 'show_libs' : function(start_aou,show_open) {
1059 if (!start_aou) throw('show_libs: Need a start_aou');
1060 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1061 JSAN.use('util.functional');
1064 var temp_aou = start_aou;
1065 while ( temp_aou.parent_ou() ) {
1066 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
1067 parents.push( temp_aou );
1071 for (var i = 0; i < parents.length; i++) {
1075 obj.append_org(o,p,{'container':'true','open':'true'});
1077 }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
1083 return function() { obj.append_org(o,p); };
1084 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
1089 if (start_aou.children()) {
1090 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
1091 x.setAttribute('container','true');
1092 if (show_open) x.setAttribute('open','true');
1093 for (var i = 0; i < start_aou.children().length; i++) {
1096 return function() { obj.append_org(o,p); };
1097 }( start_aou.children()[i], start_aou )
1109 'on_select' : function(list,twisty) {
1113 for (var i = 0; i < list.length; i++) {
1114 var row_type = list[i].split('_')[0];
1115 var id = list[i].split('_')[1];
1117 if (!sel_lists[row_type]) sel_lists[row_type] = [];
1118 sel_lists[row_type].push(id);
1122 case 'aou' : obj.on_click_aou(id,twisty); break;
1123 case 'ssub' : obj.on_select_ssub(id,twisty); break;
1129 if (!obj.focused_node_retrieve_id) return;
1131 var row_type = obj.focused_node_retrieve_id.split('_')[0];
1132 var id = obj.focused_node_retrieve_id.split('_')[1];
1134 if (sel_lists[row_type]) { // the type focused is in the selection (usually the case)
1136 case 'aou' : obj.on_click_aou(id,twisty); break;
1137 default: if (obj['on_click_' + row_type]) obj['on_click_' + row_type](sel_lists[row_type],twisty);
1142 'on_select_ssub' : function(ssub_id,twisty) {
1145 //typo? var ssub_tree = obj.map_sdist[ 'ssub_' + ssub_id ];
1146 var ssub_tree = obj.map_ssub[ 'ssub_' + ssub_id ];
1147 obj.funcs.push( function() {
1148 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1149 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','true');
1150 document.getElementById('lib_menu').setAttribute('disabled','true');
1152 if (ssub_tree.distributions()) {
1153 for (var i = 0; i < ssub_tree.distributions().length; i++) {
1157 obj.append_member(c,a,[],'sdist');
1159 }( ssub_tree.distributions()[i], ssub_tree )
1163 if (ssub_tree.issuances()) {
1164 for (var i = 0; i < ssub_tree.issuances().length; i++) {
1168 obj.append_member(c,a,[],'siss');
1170 }( ssub_tree.issuances()[i], ssub_tree )
1174 if (ssub_tree.scaps()) {
1175 for (var i = 0; i < ssub_tree.scaps().length; i++) {
1179 obj.append_member(c,a,[],'scap');
1181 }( ssub_tree.scaps()[i], ssub_tree )
1185 obj.funcs.push( function() {
1186 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1187 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','false');
1188 document.getElementById('lib_menu').setAttribute('disabled','false');
1195 'on_click_ssub' : function(ssub_ids,twisty) {
1198 // draw sdist editor
1199 if (typeof twisty == 'undefined') {
1201 params.ssub_ids = ssub_ids;
1202 obj.editor_init('ssub', 'edit', params);
1209 'on_click_sdist' : function(sdist_ids,twisty) {
1212 // draw sdist editor
1213 if (typeof twisty == 'undefined') {
1215 params.sdist_ids = sdist_ids;
1216 obj.editor_init('sdist', 'edit', params);
1223 'on_click_siss' : function(siss_ids,twisty) {
1227 if (typeof twisty == 'undefined') {
1229 params.siss_ids = siss_ids;
1230 obj.editor_init('siss', 'edit', params);
1237 'on_click_scap' : function(scap_ids,twisty) {
1241 if (typeof twisty == 'undefined') {
1243 params.scap_ids = scap_ids;
1244 obj.editor_init('scap', 'edit', params);
1251 'on_click_aou' : function(org_id,twisty) {
1253 var org = obj.data.hash.aou[ org_id ];
1254 obj.funcs.push( function() {
1255 document.getElementById('cmd_refresh_list').setAttribute('disabled','true');
1256 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','true');
1257 document.getElementById('lib_menu').setAttribute('disabled','true');
1259 if (org.children()) {
1260 for (var i = 0; i < org.children().length; i++) {
1266 }(org.children()[i],org)
1270 if (obj.map_ssub[ 'aou_' + org_id ]) {
1271 for (var i = 0; i < obj.map_ssub[ 'aou_' + org_id ].length; i++) {
1275 obj.append_ssub(o,a);
1277 }( org, obj.map_ssub[ 'aou_' + org_id ][i] )
1281 obj.funcs.push( function() {
1282 document.getElementById('cmd_refresh_list').setAttribute('disabled','false');
1283 document.getElementById('cmd_show_libs_with_distributions').setAttribute('disabled','false');
1284 document.getElementById('lib_menu').setAttribute('disabled','false');
1287 // remove current editor
1288 if (typeof twisty == 'undefined') {
1289 document.getElementById('serial_manage_subs_editor_deck').selectedIndex = 0;
1293 'append_org' : function (org,parent_org,params) {
1296 if (obj.map_tree[ 'aou_' + org.id() ]) {
1297 var x = obj.map_tree[ 'aou_' + org.id() ];
1299 for (var i in params) {
1300 x.setAttribute(i,params[i]);
1312 'skip_all_columns_except' : [0,1,2],
1313 'retrieve_id' : 'aou_' + org.id(),
1315 'no_auto_select' : true,
1319 if ( obj.org_ids.indexOf( Number( org.id() ) ) == -1 ) {
1320 if ( get_bool( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) ) {
1321 data.row.my.subscription_count = '0';
1322 //data.row.my.distribution_count = '<0>';
1324 data.row.my.subscription_count = '';
1325 //data.row.my.distribution_count = '';
1328 var v_count = 0; var d_count = 0;
1329 ssub_tree_list = obj.network.simple_request(
1330 'FM_SSUB_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS.authoritative',
1331 [ ses(), obj.docid, [ org.id() ] ]
1333 for (var i = 0; i < ssub_tree_list.length; i++) {
1335 obj.map_ssub[ 'ssub_' + ssub_tree_list[i].id() ] = function(r){return r;}(ssub_tree_list[i]);
1336 var distributions = ssub_tree_list[i].distributions();
1337 //if (distributions) d_count += distributions.length;
1338 for (var j = 0; j < distributions.length; j++) {
1339 obj.map_sdist[ 'sdist_' + distributions[j].id() ] = function(r){return r;}(distributions[j]);
1341 var issuances = ssub_tree_list[i].issuances();
1342 for (var j = 0; j < issuances.length; j++) {
1343 obj.map_siss[ 'siss_' + issuances[j].id() ] = function(r){return r;}(issuances[j]);
1345 var scaps = ssub_tree_list[i].scaps();
1346 for (var j = 0; j < scaps.length; j++) {
1347 obj.map_scap[ 'scap_' + scaps[j].id() ] = function(r){return r;}(scaps[j]);
1350 data.row.my.subscription_count = v_count;
1351 //data.row.my.distribution_count = '<' + d_count + '>';
1354 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
1356 var nparams = obj.list.append(data);
1357 var node = nparams.my_node;
1359 for (var i in params) {
1360 node.setAttribute(i,params[i]);
1363 obj.map_tree[ 'aou_' + org.id() ] = node;
1365 if (org.children()) {
1366 node.setAttribute('container','true');
1370 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
1371 data.node.setAttribute('open','true');
1374 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
1377 if (ssub_tree_list) {
1378 obj.map_ssub[ 'aou_' + org.id() ] = ssub_tree_list;
1379 node.setAttribute('container','true');
1382 if (document.getElementById('show_ssubs').checked) {
1383 obj.funcs.push( function() { obj.on_click_aou( org.id() ); } );
1384 node.setAttribute('open','true');
1393 'append_ssub' : function( org, ssub_tree, params ) {
1396 if (obj.map_tree[ 'ssub_' + ssub_tree.id() ]) {
1397 var x = obj.map_tree[ 'ssub_' + ssub_tree.id() ];
1399 for (var i in params) {
1400 x.setAttribute(i,params[i]);
1406 var parent_node = obj.map_tree[ 'aou_' + org.id() ];
1412 'subscription_count' : '',
1413 //'distribution_count' : ssub_tree.distributions() ? ssub_tree.distributions().length : '0',
1416 'skip_all_columns_except' : [0,1,2],
1417 'retrieve_id' : 'ssub_' + ssub_tree.id(),
1418 'node' : parent_node,
1420 'no_auto_select' : true,
1422 var nparams = obj.list.append(data);
1423 var node = nparams.my_node;
1424 obj.map_tree[ 'ssub_' + ssub_tree.id() ] = node;
1426 for (var i in params) {
1427 node.setAttribute(i,params[i]);
1430 if (ssub_tree.distributions() || ssub_tree.scaps() || ssub_tree.issuances()) {
1431 //did this support a later typo? obj.map_sdist[ 'ssub_' + ssub_tree.id() ] = ssub_tree;
1432 node.setAttribute('container','true');
1434 if (document.getElementById('show_groups').checked) {
1435 node.setAttribute('open','true');
1436 obj.funcs.push( function() { obj.on_select_ssub( ssub_tree.id(), true ); } );
1438 var sdist_group_node_data = {
1441 'label' : 'Distributions',
1444 'retrieve_id' : 'sdist-group_' + ssub_tree.id(),
1447 'no_auto_select' : true,
1449 nparams = obj.list.append(sdist_group_node_data);
1450 obj.map_tree[ 'ssub_sdist_group_' + ssub_tree.id() ] = nparams.my_node;
1452 var siss_group_node_data = {
1455 'label' : 'Issuances',
1458 'retrieve_id' : 'siss-group_' + ssub_tree.id(),
1461 'no_auto_select' : true,
1463 nparams = obj.list.append(siss_group_node_data);
1464 obj.map_tree[ 'ssub_siss_group_' + ssub_tree.id() ] = nparams.my_node;
1466 var scap_group_node_data = {
1469 'label' : 'Captions/Patterns',
1472 'retrieve_id' : 'scap-group_' + ssub_tree.id(),
1475 'no_auto_select' : true,
1477 nparams = obj.list.append(scap_group_node_data);
1478 obj.map_tree[ 'ssub_scap_group_' + ssub_tree.id() ] = nparams.my_node;
1485 'append_member' : function( item, ssub_tree, attributes, type ) {
1488 if (obj.map_tree[ type + '_' + item.id() ]) {
1489 var x = obj.map_tree[ type + '_' + item.id() ];
1491 for (var i in attributes) {
1492 x.setAttribute(i,attributes[i]);
1498 var parent_node = obj.map_tree[ 'ssub_' + type + '_group_' + ssub_tree.id() ];
1502 'aou' : obj.data.hash.aou[ ssub_tree.owning_lib() ],
1504 'subscription_count' : '',
1505 //'distribution_count' : '',
1508 'retrieve_id' : type + '_' + item.id(),
1509 'node' : parent_node,
1511 'no_auto_select' : true,
1513 data['row']['my'][type] = item; // TODO: future optimization: get only the IDs of these leaves, then fetch the full row in 'retrieve_row'
1514 var nparams = obj.list.append(data);
1515 var node = nparams.my_node;
1516 obj.map_tree[ type + '_' + item.id() ] = node;
1518 for (var i in attributes) {
1519 node.setAttribute(i,attributes[i]);
1529 'list_init' : function( params ) {
1532 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1535 JSAN.use('circ.util');
1538 'id' : 'tree_location',
1539 'label' : 'Location',
1540 'flex' : 1, 'primary' : true, 'hidden' : false,
1541 '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 : "???"; },
1544 'id' : 'subscription_count',
1545 'label' : 'Subscriptions',
1546 'flex' : 0, 'primary' : false, 'hidden' : false,
1547 'render' : function(my) { return my.subscription_count; },
1550 'id' : 'distribution_count',
1551 'label' : 'Members',
1553 'primary' : false, 'hidden' : false,
1554 'render' : function(my) { return my.distribution_count; },
1557 JSAN.use('util.list'); obj.list = new util.list('subs_tree');
1560 'no_auto_select' : true,
1561 'columns' : columns,
1562 'map_row_to_columns' : circ.util.std_map_row_to_columns(' '),
1563 'retrieve_row' : function(params) {
1565 var row = params.row;
1569 if (typeof params.on_retrieve == 'function') {
1570 params.on_retrieve(row);
1578 'on_click' : function(ev) {
1579 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
1580 var row = {}; var col = {}; var nobj = {};
1581 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
1582 if ((row.value == -1)||(nobj.value != 'twisty')) { return; } // on_click runs for twistys only
1584 var node = obj.list.node.contentView.getItemAtIndex(row.value);
1585 var list = [ node.getAttribute('retrieve_id') ];
1586 if (typeof obj.on_select == 'function') {
1587 obj.on_select(list,true);
1589 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1590 window.xulG.on_select(list);
1593 'on_select' : function(ev) {
1594 JSAN.use('util.functional');
1596 // get the actual node clicked to determine which editor to use
1597 if (obj.list.node.view.selection.currentIndex > -1) {
1598 var node = obj.list.node.contentView.getItemAtIndex(obj.list.node.view.selection.currentIndex);
1599 obj.focused_node_retrieve_id = node.getAttribute('retrieve_id');
1602 var sel = obj.list.retrieve_selection();
1603 obj.controller.view.sel_clip.disabled = sel.length < 1;
1604 obj.sel_list = util.functional.map_list(
1606 function(o) { return o.getAttribute('retrieve_id'); }
1608 obj.toggle_actions();
1609 if (typeof obj.on_select == 'function') {
1610 obj.on_select(obj.sel_list);
1612 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
1613 window.xulG.on_select(obj.sel_list);
1619 obj.controller.render();
1622 this.error.sdump('D_ERROR','serial/manage_subs.list_init: ' + E + '\n');
1627 'toggle_actions' : function() {
1630 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;
1631 for (var i = 0; i < obj.sel_list.length; i++) {
1632 var type = obj.sel_list[i].split(/_/)[0];
1637 case 'ssub' : found_ssub = true; break;
1638 case 'sdist' : found_sdist = true; break;
1639 case 'siss' : found_siss = true; break;
1640 case 'scap' : found_scap = true; break;
1641 case 'sdist-group' : found_sdist_group = true; break;
1642 case 'siss-group' : found_siss_group = true; break;
1643 case 'scap-group' : found_scap_group = true; break;
1646 obj.controller.view.cmd_add_sdist.setAttribute('disabled','true');
1647 obj.controller.view.cmd_add_siss.setAttribute('disabled','true');
1648 obj.controller.view.cmd_add_scap.setAttribute('disabled','true');
1649 obj.controller.view.cmd_make_predictions.setAttribute('disabled','true');
1650 obj.controller.view.cmd_delete_sdist.setAttribute('disabled','true');
1651 obj.controller.view.cmd_delete_siss.setAttribute('disabled','true');
1652 obj.controller.view.cmd_delete_scap.setAttribute('disabled','true');
1653 obj.controller.view.cmd_add_subscriptions.setAttribute('disabled','true');
1654 obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
1655 obj.controller.view.cmd_delete_ssub.setAttribute('disabled','true');
1656 obj.controller.view.cmd_mark_subscription.setAttribute('disabled','true');
1657 obj.controller.view.cmd_transfer_subscription.setAttribute('disabled','true');
1658 obj.controller.view.cmd_transfer_sdists.setAttribute('disabled','true');
1660 obj.controller.view.cmd_add_subscriptions.setAttribute('disabled','false');
1661 obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
1664 obj.controller.view.cmd_delete_ssub.setAttribute('disabled','false');
1665 obj.controller.view.cmd_mark_subscription.setAttribute('disabled','false');
1666 obj.controller.view.cmd_add_sdist.setAttribute('disabled','false');
1667 obj.controller.view.cmd_add_siss.setAttribute('disabled','false');
1668 obj.controller.view.cmd_add_scap.setAttribute('disabled','false');
1669 obj.controller.view.cmd_transfer_subscription.setAttribute('disabled','false');
1670 obj.controller.view.cmd_make_predictions.setAttribute('disabled','false');
1672 if (found_sdist_group) {
1673 obj.controller.view.cmd_add_sdist.setAttribute('disabled','false');
1675 if (found_siss_group) {
1676 obj.controller.view.cmd_add_siss.setAttribute('disabled','false');
1678 if (found_scap_group) {
1679 obj.controller.view.cmd_add_scap.setAttribute('disabled','false');
1682 obj.controller.view.cmd_delete_sdist.setAttribute('disabled','false');
1683 obj.controller.view.cmd_transfer_sdists.setAttribute('disabled','false');
1686 obj.controller.view.cmd_delete_siss.setAttribute('disabled','false');
1689 obj.controller.view.cmd_delete_scap.setAttribute('disabled','false');
1692 obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.actions.error'),E);
1696 'refresh_list' : function() {
1705 obj.org_ids = obj.network.simple_request('FM_SSUB_AOU_IDS_RETRIEVE_VIA_RECORD_ID.authoritative',[ obj.docid ]);
1706 if (typeof obj.org_ids.ilsevent != 'undefined') throw(obj.org_ids);
1707 JSAN.use('util.functional');
1708 obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
1710 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
1711 obj.show_libs( org );
1713 obj.show_my_libs( document.getElementById('lib_menu').value );
1715 this.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.refresh_list.error'),E);
1720 dump('exiting serial/manage_subs.js\n');