Koha/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt
Tomas Cohen Arazi 557857cf2c Bug 9894 - (3.12) de-serialize the 'hidden' value for subfields in frameworks
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 <liz@catalyst.net.nz>
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 <jonathan.druart@biblibre.com>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
2013-04-18 07:55:18 -04:00

355 lines
17 KiB
Text

[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Administration &rsaquo;[% IF ( add_form ) %][% IF ( use_heading_flags_p ) %][% IF ( heading_edit_subfields_p ) %] MARC subfield structure &rsaquo; Edit MARC subfields constraints[% END %][% ELSE %] MARC subfield structure &rsaquo; [% action %][% END %][% END %]
[% IF ( delete_confirm ) %] MARC subfield structure &rsaquo; Confirm deletion of subfield [% tagsubfield %][% END %][% IF ( delete_confirmed ) %] MARC subfield structure &rsaquo; Subfield deleted[% END %][% IF ( else ) %]MARC subfield structure[% END %]</title>
[% INCLUDE 'doc-head-close.inc' %]
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
$('#subfieldtabs').tabs();
$("a.displaymore").click(function(){
var link = $(this);
var constraints = $("#"+$(this).attr("href").replace("#",""));
constraints.toggle();
if($(constraints).is(':visible')){
link.html(_("Hide constraints"));
} else {
link.html(_("Display more constraints"));
}
});
$("input[id^='hidden_']").click(setHiddenValue);
$("input[id^='hidden-']").each(function() {
populateHiddenCheckboxes($(this).attr('id').split('-')[1]);
});
});
/*function displayMoreConstraint(numlayer){
var thisdiv = document.getElementById(numlayer);
if(thisdiv.getAttribute("class") == "content_hidden"){
thisdiv.removeAttribute('class');
thisdiv.setAttribute("class","content_visible");
} else {
thisdiv.removeAttribute('class');
thisdiv.setAttribute("class","content_hidden");
}
}*/
/* 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);
}
//]]>
</script>
</head>
<body id="admin_marc_subfields_structure" class="admin">
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<div id="breadcrumbs">
<a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <a href="/cgi-bin/koha/admin/biblio_framework.pl">MARC frameworks</a> &rsaquo; <a href="/cgi-bin/koha/admin/marctagstructure.pl?frameworkcode=[% frameworkcode %]&amp;searchfield=[% tagfield %]">[% frameworkcode %] framework structure</a> &rsaquo;
[% IF ( add_form ) %]
[% IF ( use_heading_flags_p ) %]
[% IF ( heading_edit_subfields_p ) %] <a href="/cgi-bin/koha/admin/marc_subfields_structure.pl?tagfield=[% tagfield %]&amp;frameworkcode=[% frameworkcode %]">Tag [% tagfield %] subfield structure</a> &rsaquo; Edit subfields constraints
[% END %]
[% ELSE %] <a href="/cgi-bin/koha/admin/marc_subfields_structure.pl?tagfield=[% tagfield %]&amp;frameworkcode=[% frameworkcode %]">Tag [% tagfield %] Subfield structure</a> &rsaquo; [% action %]
[% END %]
[% END %]
[% IF ( delete_confirm ) %] <a href="/cgi-bin/koha/admin/marc_subfields_structure.pl?tagfield=[% tagfield %]&amp;frameworkcode=[% frameworkcode %]">Tag [% tagfield %] Subfield structure</a> &rsaquo; Confirm deletion of subfield [% tagsubfield %]
[% END %]
[% IF ( delete_confirmed ) %] <a href="/cgi-bin/koha/admin/marc_subfields_structure.pl?tagfield=[% tagfield %]&amp;frameworkcode=[% frameworkcode %]">Tag [% tagfield %] subfield structure</a> &rsaquo; Subfield deleted
[% END %]
[% IF ( else ) %]Tag [% tagfield %] Subfield structure[% END %]
</div>
<div id="doc" class="yui-t7">
<div id="bd">
<div id="yui-main">
<div class="yui-g">
[% IF ( add_form ) %]
<h1>
[% IF ( use_heading_flags_p ) %]
[% IF ( heading_edit_subfields_p ) %]Tag [% tagfield %] Subfield constraints[% END %]
[% ELSE %]
[% action %]
[% END %]
</h1>
<form action="[% script_name %]" name="Aform" method="post">
<input type="hidden" name="op" value="add_validate" />
<input type="hidden" name="tagfield" value="[% tagfield %]" />
<input type="hidden" name="frameworkcode" value="[% frameworkcode %]" />
<input type="submit" value="Save changes" />
<div id="subfieldtabs" class="toptabs numbered">
<ul>
[% FOREACH loo IN loop %]
[% IF ( loo.new_subfield ) %]
<li><a href="#sub[% loo.urisubfieldcode %]field" title="[% loo.liblibrarian %]">New</a></li>
[% ELSE %]
<li><a href="#sub[% loo.urisubfieldcode %]field" title="[% loo.liblibrarian %]">
[% loo.subfieldcode %]
</a></li>
[% END %]
[% END %]
</ul>
[% FOREACH loo IN loop %]
<div id="sub[% loo.urisubfieldcode %]field">
<fieldset class="rows" style="float:none;"><legend>[% IF ( loo.new_subfield ) %]Add new subfield[% ELSE %]Basic constraints[% END %]</legend>
<ol>
[% IF ( subfieldcode == 0 || subfieldcode ) %]
<li><span class="label">Subfield code:</span> [% loo.subfieldcode %] <input type="hidden" name="tagsubfield" value="[% loo.subfieldcode %]" /></li>
[% ELSE %]
<li><label for="tagsubfield[% loo.row %]">Subfield code:</label> <input type="text" id="tagsubfield[% loo.row %]" name="tagsubfield" value="[% loo.subfieldcode %]" /></li>
[% END %]
<li><label for="liblibrarian[% loo.row %]">Text for librarian: </label><input id="liblibrarian[% loo.row %]" type="text" name="liblibrarian" value="[% loo.liblibrarian %]" size="40" maxlength="80" /></li>
<li><label for="libopac[% loo.row %]">Text for OPAC: </label><input type="text" id="libopac[% loo.row %]" name="libopac" value="[% loo.libopac %]" size="40" maxlength="80" /></li>
<li><label for="repeatable[% loo.row %]">Repeatable: </label>[% loo.repeatable %]</li>
<li><label for="mandatory[% loo.row %]">Mandatory: </label>[% loo.mandatory %]</li>
<li><label for="tab[% loo.row %]">Managed in tab: </label>[% loo.tab %] (ignore means that the subfield does not display in the record editor)</li>
</ol>
</fieldset>
<a class="displaymore" href="#more[% loo.urisubfieldcode %]">Display more constraints</a>
<div id="more[% loo.urisubfieldcode %]" style="display:none; clear: both">
<fieldset class="rows" style="float:none;">
<legend>Advanced constraints:</legend>
<ol><li><label for="defaultvalue[% loo.row %]">Default value:</label>
<input type="text" name="defaultvalue" id="defaultvalue[% loo.row %]" value="[% loo.defaultvalue %]" /></li>
<li><label for="maxlength[% loo.row %]">Max length:</label><input type="text" id="maxlength[% loo.row %]" name="maxlength" value="[% loo.maxlength %]" size="4" /> (see online help)</li>
<li><input type="hidden" id="hidden-[% loo.row %]" name="hidden" value="[% loo.hidden %]" />
<label for="hidden[% loo.row %]">Visibility: </label>
<input class="radio" type="checkbox" id="hidden_opac_[% loo.row %]" name="hidden_opac_[% loo.row %]"/> OPAC
<input type="checkbox" id="hidden_intranet_[% loo.row %]" name="hidden_intranet_[% loo.row %]"/> Intranet
<input type="checkbox" id="hidden_editor_[% loo.row %]" name="hidden_editor_[% loo.row %]"/> Editor
<input type="checkbox" id="hidden_collapsed_[% loo.row %]" name="hidden_collapsed_[% loo.row %]"/> Collapsed
</li>
<li><label for="isurl[% loo.row %]">Is a URL:</label>[% loo.isurl %] (if checked, it means that the subfield is a URL and can be clicked)</li>
<li><label for="link[% loo.row %]">Link:</label><input type="text" id="link[% loo.row %]" name="link" value="[% loo.link %]" size="10" maxlength="80" /> (e.g., Title or Local-Number) <span class="error"><em>NOTE: If you change this value you must ask your administrator to run misc/batchRebuildBiblioTables.pl.</em></span></li>
<li><label for="kohafield[% loo.row %]">Koha link:</label>[% loo.kohafield %]</li>
</ol>
</fieldset>
<fieldset class="rows" style="float:none;">
<legend>Other Options: (choose one)</legend>
<ol>
<li><label for="authorised_value[% loo.row %]">Authorized value:</label>[% loo.authorised_value %]</li>
<li><label for="authtypecode[% loo.row %]">Thesaurus:</label>[% loo.authtypes %]</li>
<li><label for="value_builder[% loo.row %]">Plugin:</label>[% loo.value_builder %]</li>
</ol>
</fieldset>
</div><br class="clear" /><!-- /more -->
</div><!-- /content_sub -->
[% END %]
</div><!-- /content -->
</form>
[% END %]
[% IF ( delete_confirm ) %]
<h3>Confirm deletion of subfield [% tagsubfield %]?</h3>
<p>Subfield: [% tagsubfield %]</p>
<p>Description: [% liblibrarian %]</p>
<form action="[% delete_link %]" method="post"><input type="hidden" name="op" value="delete_confirmed" />
<input type="hidden" name="searchfield" value="[% searchfield %]" />
<input type="hidden" name="tagfield" value="[% tagfield %]" />
<input type="hidden" name="tagsubfield" value="[% tagsubfield %]" />
<input type="hidden" name="frameworkcode" value="[% frameworkcode %]" />
<input type="submit" value="Yes, Delete this Subfield" />
</form>
<form action="[% script_name %]" method="post">
<input type="hidden" name="searchfield" value="[% searchfield %]" />
<input type="hidden" name="tagfield" value="[% tagfield %]" />
<input type="hidden" name="tagsubfield" value="[% tagsubfield %]" />
<input type="hidden" name="frameworkcode" value="[% frameworkcode %]" />
<input type="submit" value="No, Do Not Delete" />
</form>
[% END %]
[% IF ( delete_confirmed ) %]
<h3>Data deleted</h3>
<form action="[% script_name %]" method="post">
<input type="hidden" name="tagfield" value="[% tagfield %]" />
<input type="submit" value="OK" />
</form>
[% END %]
[% IF ( else ) %]
<h1>MARC subfield structure admin for [% tagfield %] [% IF ( frameworkcode ) %](framework [% frameworkcode %])[% ELSE %](default framework)[% END %]</h1>
<p>This screen shows the subfields associated with the selected tag. You can edit subfields or add a new one by clicking on edit. </p>
<p>The column Koha field shows that the subfield is linked with a Koha field. Koha can manage a MARC interface, or a Koha interface. This link ensures that both DB are synchronized, thus you can change from a MARC to a Koha interface easily.</p>
<table>
<tr>
<th>Subfield</th>
<th>Text</th>
<th>Constraints</th>
<th>Edit</th>
<th>Delete</th>
</tr>
[% FOREACH loo IN loop %]
[% UNLESS ( loop.odd ) %]
<tr class="highlight">
[% ELSE %]
<tr>
[% END %]
<td><a href="/cgi-bin/koha/admin/marc_subfields_structure.pl?op=add_form&amp;tagfield=[% loo.tagfield %]&amp;frameworkcode=[% frameworkcode %]#sub[% loo.tagsubfield %]field">[% loo.tagsubfield %]</a></td>
<td>
[% IF ( loo.subfield_ignored ) %]
<i>[% loo.liblibrarian %]</i>
[% ELSE %]
[% loo.liblibrarian %]
[% END %]
</td>
<td>
[% IF ( loo.subfield_ignored ) %]
<i>subfield ignored</i>
[% ELSE %]
Tab:[% loo.tab %],
[% IF ( loo.kohafield ) %] | Koha field: [% loo.kohafield %], [% END %]
[% IF ( loo.repeatable ) %]Repeatable, [% ELSE %]Not repeatable,[% END %]
[% IF ( loo.mandatory ) %]Mandatory, [% ELSE %]Not mandatory,[% END %]
[% IF ( loo.seealso ) %] | See Also: [% loo.seealso %],[% END %]
[% IF ( loo.hidden ) %]hidden,[% END %]
[% IF ( loo.isurl ) %]is a URL,[% END %]
[% IF ( loo.authorised_value ) %] | Auth value:[% loo.authorised_value %],[% END %]
[% IF ( loo.authtypecode ) %] | Authority:[% loo.authtypecode %],[% END %]
[% IF ( loo.value_builder ) %] | Plugin:[% loo.value_builder %],[% END %]
[% IF ( loo.link ) %] | Link:[% loo.link %],[% END %]
[% END %]
</td>
<td><a href="/cgi-bin/koha/admin/marc_subfields_structure.pl?op=add_form&amp;tagfield=[% loo.tagfield %]&amp;frameworkcode=[% frameworkcode %]#sub[% loo.tagsubfield %]field">Edit</a></td>
<td><a href="/cgi-bin/koha/admin/marc_subfields_structure.pl?op=delete_confirm&amp;tagfield=[% loo.tagfield %]&amp;tagsubfield=[% loo.tagsubfield %]&amp;frameworkcode=[% frameworkcode %]">Delete</a></td>
</tr>
[% END %]
</table>
<form action="[% script_name %]" method="get">
<fieldset class="action"><input type="hidden" name="op" value="add_form" />
<input type="hidden" name="tagfield" value="[% edit_tagfield %]" />
<input type="hidden" name="frameworkcode" value="[% edit_frameworkcode %]" />
<input type="submit" value="Edit Subfields" />
<a class="cancel" href="marctagstructure.pl?searchfield=[% tagfield %]&amp;frameworkcode=[% frameworkcode %]">Cancel</a>
</fieldset>
</form>
[% END %]
</div>
</div>
</div>
[% INCLUDE 'intranet-bottom.inc' %]