From 557857cf2c881fb7beec2019d3c85cef893c5342 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 25 Mar 2013 22:55:11 -0300 Subject: [PATCH] Bug 9894 - (3.12) de-serialize the 'hidden' value for subfields in frameworks MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch aims to provide a non-intrusive way (with respect to Koha's code, so it could have got into 3.12) for the users to easily choose the visibility settings for each subfield. This patch is also known to have arrived late for 3.12. I've been struggling with other stuff at work, but I just wanted to put this somewhere just in case it can be reused or something else. The patch adds two JavaScript functions that deal with (de)serialization of the 'hidden' value for subfields. One each way. Listeners are added to the checkboxes so the (actually, heh) 'hidden' value gets correctly updated on each checkbox change. There's a costly function to update all checkboxes on every tab to match the 'hidden' value on page load. To test: - open the docs to have at hand the list of codes/visibility options combinations and try changing several subfields from a single tagfield. Save, and reopen the "Edit subfields" page. - I had a MySQL shell opened to repeatedly run this query (i tested against field 886 on the default framework): > SELECT tagfield,tagsubfield,hidden FROM marc_subfield_structure WHERE frameworkcode='' AND tagfield=886; - Compare what was saved on the DB with the docs for that visibility selection. Regards To+ PS: I promise I'll work on the proper patch for 3.14, which would involve DB structure changes and (more than I expected) rewriten code. Sponsored-by: Universidad Nacional de Córdoba Signed-off-by: Liz Rea I promise to hug you the next time we meet. This works, and is a reasonable work around for a very longstanding awkward interface. Signed-off-by: Jonathan Druart Signed-off-by: Jared Camins-Esakov --- .../modules/admin/marc_subfields_structure.tt | 123 +++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) 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 a0177db727..c9ba8e7965 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 @@ -17,6 +17,10 @@ $(document).ready(function() { link.html(_("Display more constraints")); } }); + $("input[id^='hidden_']").click(setHiddenValue); + $("input[id^='hidden-']").each(function() { + populateHiddenCheckboxes($(this).attr('id').split('-')[1]); + }); }); /*function displayMoreConstraint(numlayer){ @@ -30,6 +34,117 @@ $(document).ready(function() { } }*/ +/* Function to serialize and set the 'hidden' field */ +function setHiddenValue() { + + var tab = $(this).attr('id').split('_')[2]; + 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 ( 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'; + } + + $('#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; + + 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); +} + //]]> @@ -111,7 +226,13 @@ $(document).ready(function() {
  1. (see online help)
  2. -
  3. (see online help)
  4. +
  5. + + OPAC + Intranet + Editor + Collapsed +
  6. [% loo.isurl %] (if checked, it means that the subfield is a URL and can be clicked)
  7. (e.g., Title or Local-Number) NOTE: If you change this value you must ask your administrator to run misc/batchRebuildBiblioTables.pl.
  8. [% loo.kohafield %]
  9. -- 2.39.5