Bug 31372: Value builder for field 325
authorjeremy breuillard <jeremy.breuillard@biblibre.com>
Wed, 20 Jul 2022 13:45:16 +0000 (15:45 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 4 Oct 2022 11:01:17 +0000 (08:01 -0300)
On page cataloging some plugins were added for subfields $h and $h from field $325

Test plan:
    1)Go to Home > Cataloging > New record
    2)Section 3 - field 325 : it contains lots of subfields (g, h, i, j...)
    3)Inputs are writable but notice that no plugins are suggested
    4)Apply patch and repeat 1) to 3)
    5)Values builders plugins are available for $h and $j

Signed-off-by: Thibault Keromnès <thibault.keromnes@univ-paris8.fr>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
cataloguing/value_builder/unimarc_field_325h.pl [new file with mode: 0755]
cataloguing/value_builder/unimarc_field_325j.pl [new file with mode: 0755]
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_325h.tt [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_325j.tt [new file with mode: 0644]

diff --git a/cataloguing/value_builder/unimarc_field_325h.pl b/cataloguing/value_builder/unimarc_field_325h.pl
new file mode 100755 (executable)
index 0000000..e2d4a33
--- /dev/null
@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+
+# Copyright 2014 Rijksmuseum
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+
+
+######### ATTENTION c'est le contenu du fichier unimarc_field_181-2.tt %] #############
+
+use Modern::Perl;
+
+use Date::Calc;
+
+use Koha::Util::FrameworkPlugin qw(wrapper);
+use C4::Auth qw( get_template_and_user );
+use CGI qw ( -utf8 );
+use C4::Context;
+use C4::Output qw( output_html_with_http_headers );
+
+my $builder= sub {
+    my $params = shift;
+    my $id = $params->{id};
+
+    return qq|
+<script>
+
+function Click$id(event) {
+    var fieldvalue=\$('#'+event.data.id).val();
+    window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_325h.pl&index=\"+event.data.id+\"&result=\"+fieldvalue,\"tag_editor\",'width=700,height=700,toolbar=false,scrollbars=yes');
+    return false; /* prevents scrolling */
+}
+</script>|;
+};
+
+my $launcher= sub {
+    my $params = shift;
+    my $cgi = $params->{cgi};
+    my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
+        template_name => "cataloguing/value_builder/unimarc_field_325h.tt",
+        query => $cgi,
+        type => "intranet",
+        flagsrequired => {editcatalogue => '*'},
+    });
+    my $results = scalar $cgi->param('result');
+    my $input_a = substr $results, 0, 1;
+
+    $template->param(
+        index => scalar $cgi->param('index'),
+        result => $results,
+        f0 => $input_a,
+    );
+    output_html_with_http_headers $cgi, $cookie, $template->output;
+};
+
+# Return the hashref with the builder and launcher to FrameworkPlugin object.
+# NOTE: If you do not need a popup but only use e.g. Focus, Blur etc. for a
+# particular plugin, you only need to define and return the builder.
+return { builder => $builder, launcher => $launcher };
\ No newline at end of file
diff --git a/cataloguing/value_builder/unimarc_field_325j.pl b/cataloguing/value_builder/unimarc_field_325j.pl
new file mode 100755 (executable)
index 0000000..9a97833
--- /dev/null
@@ -0,0 +1,78 @@
+#!/usr/bin/perl
+
+# Copyright 2014 Rijksmuseum
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+
+
+######### ATTENTION c'est le contenu du fichier unimarc_field_181-2.tt %] #############
+
+use Modern::Perl;
+
+use Date::Calc;
+
+use Koha::Util::FrameworkPlugin qw(wrapper);
+use C4::Auth qw( get_template_and_user );
+use CGI qw ( -utf8 );
+use C4::Context;
+use C4::Output qw( output_html_with_http_headers );
+
+my $builder= sub {
+    my $params = shift;
+    my $id = $params->{id};
+
+    return qq|
+<script>
+
+function Click$id(event) {
+    var fieldvalue=\$('#'+event.data.id).val();
+    window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_325j.pl&index=\"+event.data.id+\"&result=\"+fieldvalue,\"tag_editor\",'width=700,height=700,toolbar=false,scrollbars=yes');
+    return false; /* prevents scrolling */
+}
+</script>|;
+};
+
+my $launcher= sub {
+    my $params = shift;
+    my $cgi = $params->{cgi};
+    my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
+        template_name => "cataloguing/value_builder/unimarc_field_325j.tt",
+        query => $cgi,
+        type => "intranet",
+        flagsrequired => {editcatalogue => '*'},
+    });
+    my $results = scalar $cgi->param('result');
+
+    $template->param(
+        index => scalar $cgi->param('index'),
+        result => $results,
+    );
+
+   # Return the result of the position in the string, ex: abcde = 1=a, 2=b, 3=c...
+    my @x = split(//, $results);
+    my $i = 0;
+    for my $fresult (@x) {
+        $template->param("f$i" => $fresult);
+        ++$i;
+    }
+    output_html_with_http_headers $cgi, $cookie, $template->output;
+};
+
+# Return the hashref with the builder and launcher to FrameworkPlugin object.
+# NOTE: If you do not need a popup but only use e.g. Focus, Blur etc. for a
+# particular plugin, you only need to define and return the builder.
+return { builder => $builder, launcher => $launcher };
\ No newline at end of file
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_325h.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_325h.tt
new file mode 100644 (file)
index 0000000..4d8d4ab
--- /dev/null
@@ -0,0 +1,53 @@
+[%# ATTENTION c'est le contenu du fichier unimarc_field_181-2.tt %]
+
+
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Framework plugin example &rsaquo; Cataloguing &rsaquo; Koha</title>
+[% INCLUDE 'doc-head-close.inc' %]
+</head>
+
+<body id="cat_unimarc_field_325h" class="cat" style="padding:1em;">
+
+<h3>UNIMARC field 325h builder</h3>
+
+<form name="f_pop" action="">
+<table>
+    <tr>
+        <td><label for="f0">Completeness of the reproduction code :</label></td>
+        <td>
+            <select name="f0" id="f0">
+                [% IF ( f0 == "" ) %]
+                    <option value=" " selected="selected"># - undetermined</option>
+                [% ELSE %]
+                    <option value=" "># - undetermined</option>
+                [% END %]
+
+                [% IF ( f0 == "0" ) %]
+                    <option value="0" selected="selected">0 - reproduction is not complete</option>
+                [% ELSE %]
+                    <option value="0">0 - reproduction is not complete</option>
+                [% END %]
+
+                [% IF ( f0 == "1" ) %]
+                    <option value="1" selected="selected">1 - reproduction is complete</option>
+                [% ELSE %]
+                    <option value="1">1 - reproduction is complete</option>
+                [% END %]
+            </select>
+        </td>
+    </tr>
+</table>
+<p><input type="button" value="OK"  onclick="submitMyForm();" /> <a href="#" class="cancel close">Cancel</a> </p>
+</form>
+
+<script>
+
+    function submitMyForm() {
+        var doc   = opener.document;
+        var field = doc.getElementById("[% index | html %]");
+
+        field.value = document.f_pop.f0.value;
+        window.close();
+        return false;
+    }
+</script>
\ No newline at end of file
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_325j.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_325j.tt
new file mode 100644 (file)
index 0000000..41461a5
--- /dev/null
@@ -0,0 +1,164 @@
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Framework plugin example &rsaquo; Cataloguing &rsaquo; Koha</title>
+[% INCLUDE 'doc-head-close.inc' %]
+</head>
+
+<body id="cat_unimarc_field_325j" class="cat" style="padding:1em;">
+
+<h3>UNIMARC field 325j builder</h3>
+
+<form name="f_pop" action="" id="form">
+<table>
+    <tr>
+        <td><label for="f0">Terms of access to the reproduction :</label></td>
+        <td>
+            <select name="f0" id="f0">
+                [% IF ( f0 == "1" ) %]
+                    <option value="1" selected="selected">1 - free-to-read</option>
+                [% ELSE %]
+                    <option value="1">1 - free-to-read</option>
+                [% END %]
+
+                [% IF ( f0 == "2" ) %]
+                    <option value="2" selected="selected">2 - free-to-read, partly</option>
+                [% ELSE %]
+                    <option value="2">2 - free-to-read, partly</option>
+                [% END %]
+
+                [% IF ( f0 == "3" ) %]
+                    <option value="3" selected="selected">3 - free-to-read, after embargo</option>
+                [% ELSE %]
+                    <option value="3">3 - free-to-read, after embargo</option>
+                [% END %]
+
+                [% IF ( f0 == "4" ) %]
+                    <option value="4" selected="selected">4 - fully</option>
+                [% ELSE %]
+                    <option value="4">4 - fully</option>
+                [% END %]
+
+                [% IF ( f0 == "5" ) %]
+                    <option value="5" selected="selected">5 - free-to-read upon subscription (requires signing up)</option>
+                [% ELSE %]
+                    <option value="5">5 - free-to-read upon subscription (requires signing up)</option>
+                [% END %]
+            </select>
+        </td>
+    </tr>
+    <tr>
+        <td><label for="f1">Qualifier type :</label></td>
+        <td>
+            <select name="f1" id="f1">
+                [% IF ( f1 == "l" ) %]
+                    <option value="l" selected="selected">l - latest</option>
+                [% ELSE %]
+                    <option value="l" >l - latest</option>
+                [% END %]
+
+                [% IF ( f1 == "p" ) %]
+                    <option value="p" selected="selected">p - previous</option>
+                [% ELSE %]
+                    <option value="p">p - previous</option>
+                [% END %]
+
+                [% IF ( f1 == "x" ) %]
+                    <option value="" selected="selected">x - not applicable</option>
+                [% ELSE %]
+                    <option value="">x - not applicable</option>
+                [% END %]
+
+                [% IF ( f1 == "#" ) %]
+                    <option value="#" selected="selected"># - no attempt to code</option>
+                [% ELSE %]
+                    <option value="#"># - no attempt to code</option>
+                [% END %]
+            </select>
+        </td>
+    </tr>
+    <tr>
+        <td><label for="f2">Unit under embargo :</label></td>
+        <td>
+            <select name="f2" id="f2">
+                [% IF ( f2 == "m" ) %]
+                    <option value="m" selected="selected">m - month(s) time</option>
+                [% ELSE %]
+                    <option value="m">m - month(s) time</option>
+                [% END %]
+
+                [% IF ( f2 == "w" ) %]
+                    <option value="w" selected="selected">w - week(s) time</option>
+                [% ELSE %]
+                    <option value="w">w - week(s) time</option>
+                [% END %]
+
+                [% IF ( f2 == "y" ) %]
+                    <option value="y" selected="selected">y - year(s) time</option>
+                [% ELSE %]
+                    <option value="y">y - year(s) time</option>
+                [% END %]
+
+                [% IF ( f2 == "i" ) %]
+                    <option value="i" selected="selected">i - issue(s) part</option>
+                [% ELSE %]
+                    <option value="i">i - issue(s) part</option>
+                [% END %]
+
+                [% IF ( f2 == "x" ) %]
+                    <option value="" selected="selected">x - not applicable</option>
+                [% ELSE %]
+                    <option value="">x - not applicable</option>
+                [% END %]
+
+                [% IF ( f2 == "#" ) %]
+                    <option value="#" selected="selected"># - no attempt to code</option>
+                [% ELSE %]
+                    <option value="#"># - no attempt to code</option>
+                [% END %]
+            </select>
+        </td>
+    </tr>
+    <tr>
+        <td><label for="f3">Number of units under embargo :</label></td>
+        <td>
+            <input name="f3" id="f3" inputmode="numeric" pattern="\d{1,2}" value="[% f3 | html %]"></input>
+        </td>
+    </tr>
+</table>
+<p><input type="submit" value="OK" /> <a href="#" class="cancel close">Cancel</a> </p>
+</form>
+
+<script>
+    $("#form").on('submit', submitMyForm);
+    $("#f0").on('change', function() {
+        document.f_pop.f1.disabled = false;
+        document.f_pop.f2.disabled = false;
+        document.f_pop.f3.disabled = false;
+
+        if ( document.f_pop.f0.value != "3" ) {
+            document.f_pop.f1.value = "x";
+            document.f_pop.f2.value = "x";
+            document.f_pop.f1.disabled = true;
+            document.f_pop.f2.disabled = true;
+            document.f_pop.f3.disabled = true;
+        }
+    });
+    $("#f0").trigger('change');
+
+    function submitMyForm(event) {
+        event.preventDefault();
+        var doc   = opener.document;
+        var field = doc.getElementById("[% index | html %]");
+        if ( document.f_pop.f0.value == "3" ) {
+            var f3v = document.f_pop.f3.value.padStart(2, '0');
+            document.f_pop.f3.value = f3v;
+        }
+
+        field.value = document.f_pop.f0.value+
+                      document.f_pop.f1.value+
+                      document.f_pop.f2.value+
+                      document.f_pop.f3.value;
+        window.close();
+    }
+</script>
+
+[% INCLUDE 'popup-bottom.inc' %]
\ No newline at end of file