From 5e050165e216f4f673e01caecbf641991d680415 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Wed, 17 Feb 2016 09:33:28 -0500 Subject: [PATCH] Bug 15843 - Move MARC subfields structure JavaScript into separate file Content-Type: text/plain; charset="utf-8" The JavaScript embedded in the MARC subfields structure template is not dependent on template processing and can safely be moved to a separate file. This patch does so. Removed in the process is some lines which were commented out. To test, apply the patch and go to Administration -> MARC framworks. - Click 'MARC structure' for a framework you can edit. - Click 'subfields' for a tag you can edit. - Click 'Edit' for a subfield you can edit. - Confirm that tabs and accordian sections work correctly. - Make changes under Advanced constraints -> Visibility and confirm that they are saved correctly. --- .../prog/en/js/marc_subfields_structure.js | 143 ++++++++++++++++++ .../en/modules/admin/marc_subfields_structure.tt | 160 +-------------------- 2 files changed, 144 insertions(+), 159 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/js/marc_subfields_structure.js diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/marc_subfields_structure.js b/koha-tmpl/intranet-tmpl/prog/en/js/marc_subfields_structure.js new file mode 100644 index 0000000..ce50e67 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/js/marc_subfields_structure.js @@ -0,0 +1,143 @@ +$(document).ready(function() { + $( ".constraints" ).accordion(); + $('#subfieldtabs').tabs(); + $("input[id^='hidden_']").click(setHiddenValue); + $("input[id^='hidden-']").each(function() { + populateHiddenCheckboxes($(this).attr('id').split('-')[1]); + }); + +}); + +/* Function to enable/disable hidden values checkboxes when Flag is (de)selected */ +function enable_cb(tab) { + if ($("#hidden_flagged_" + tab).is(':checked')) { + $('.inclusive_' + tab).attr('disabled',true).removeAttr('checked'); + } + else { + $('.inclusive_' + tab).removeAttr('disabled'); + } +} + +/* Function to serialize and set the 'hidden' field */ +function setHiddenValue() { + + var tab = $(this).attr('id').split('_')[2]; + var flagged_checked = $("#hidden_flagged_" + tab).is(':checked'); + var opac_checked = $("#hidden_opac_" + tab).is(':checked'); + var intranet_checked = $("#hidden_intranet_" + tab).is(':checked'); + var editor_checked = $("#hidden_editor_" + tab).is(':checked'); + var collapsed_checked = $("#hidden_collapsed_" + tab).is(':checked'); + var hidden_value = ""; + + if ( flagged_checked ) { + hidden_value='-8'; + } else if ( opac_checked && ! intranet_checked && ! editor_checked && collapsed_checked ) { + hidden_value='-7'; + } else if ( opac_checked && intranet_checked && ! editor_checked && ! collapsed_checked) { + hidden_value='-6'; + } else if ( opac_checked && intranet_checked && ! editor_checked && collapsed_checked) { + hidden_value='-5'; + } else if ( opac_checked && ! intranet_checked && ! editor_checked && ! collapsed_checked) { + hidden_value='-4'; + } else if ( opac_checked && ! intranet_checked && editor_checked && collapsed_checked) { + hidden_value='-3'; + } else if ( opac_checked && ! intranet_checked && editor_checked && ! collapsed_checked) { + hidden_value='-2'; + } else if ( opac_checked && intranet_checked && editor_checked && collapsed_checked) { + hidden_value='-1'; + } else if ( opac_checked && intranet_checked && editor_checked && ! collapsed_checked) { + hidden_value='0'; + } else if ( ! opac_checked && intranet_checked && editor_checked && collapsed_checked) { + hidden_value='1'; + } else if ( ! opac_checked && ! intranet_checked && editor_checked && ! collapsed_checked) { + hidden_value='2'; + } else if ( ! opac_checked && ! intranet_checked && editor_checked && collapsed_checked) { + hidden_value='3'; + } else if ( ! opac_checked && intranet_checked && editor_checked && ! collapsed_checked) { + hidden_value='4'; + } else if ( ! opac_checked && ! intranet_checked && ! editor_checked && collapsed_checked) { + hidden_value='5'; + } else if ( ! opac_checked && intranet_checked && ! editor_checked && ! collapsed_checked) { + hidden_value='6'; + } else if ( ! opac_checked && intranet_checked && ! editor_checked && collapsed_checked) { + hidden_value='7'; + } else if ( ! opac_checked && ! intranet_checked && ! editor_checked && ! collapsed_checked) { + hidden_value='8'; + } + + enable_cb(tab); + + $('#hidden-' + tab).val(hidden_value); + +} + +function populateHiddenCheckboxes(tab) { + // read the serialized value + var hidden_value = $('#hidden-' + tab).val(); + // deafult to false + var opac_checked = false; + var intranet_checked = false; + var editor_checked = false; + var collapsed_checked = false; + var flagged_checked = false; + + if ( hidden_value == '-8' ) { + flagged_checked = true; + } else if ( hidden_value == '-7') { + opac_checked = true; + collapsed_checked = true; + } else if ( hidden_value == '-6' ) { + opac_checked = true; + intranet_checked = true; + } else if ( hidden_value == '-5') { + opac_checked = true; + intranet_checked = true; + collapsed_checked = true; + } else if ( hidden_value == '-4' ) { + opac_checked = true; + } else if ( hidden_value == '-3') { + opac_checked = true; + editor_checked = true; + collapsed_checked = true; + } else if ( hidden_value == '-2' ) { + opac_checked = true; + editor_checked = true; + } else if ( hidden_value == '-1' ) { + opac_checked = true; + intranet_checked = true; + editor_checked = true; + collapsed_checked = true; + } else if ( hidden_value == '0' ) { + opac_checked = true; + intranet_checked = true; + editor_checked = true; + } else if ( hidden_value == '1' ) { + intranet_checked = true; + editor_checked = true; + collapsed_checked = true; + } else if ( hidden_value == '2' ) { + editor_checked = true; + } else if ( hidden_value == '3' ) { + editor_checked = true; + collapsed_checked = true; + } else if ( hidden_value == '4' ) { + intranet_checked = true; + editor_checked = true; + } else if ( hidden_value == '5' ) { + collapsed_checked = true; + } else if ( hidden_value == '6' ) { + intranet_checked = true; + } else if ( hidden_value == '7' ) { + intranet_checked = true; + collapsed_checked = true; + } // else if ( hidden_value == '8') { skip } + + $("#hidden_opac_" + tab).attr('checked',opac_checked); + $("#hidden_intranet_" + tab).attr('checked',intranet_checked); + $("#hidden_editor_" + tab).attr('checked',editor_checked); + $("#hidden_collapsed_" + tab).attr('checked',collapsed_checked); + $("#hidden_flagged_" + tab).attr('checked',flagged_checked); + + enable_cb(tab); + +} \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt index bd76f43..0268800 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt @@ -2,165 +2,7 @@ Koha › Administration ›[% IF ( add_form ) %][% IF ( use_heading_flags_p ) %][% IF ( heading_edit_subfields_p ) %] MARC subfield structure › Edit MARC subfields constraints[% END %][% ELSE %] MARC subfield structure › [% action %][% END %][% END %] [% IF ( delete_confirm ) %] MARC subfield structure › Confirm deletion of subfield [% tagsubfield %][% END %][% IF ( delete_confirmed ) %] MARC subfield structure › Subfield deleted[% END %][% IF ( else ) %]MARC subfield structure[% END %] [% INCLUDE 'doc-head-close.inc' %] - + [% INCLUDE 'header.inc' %] -- 2.1.4