Bug 30604: Add value builders for UNIMARC 146 ($a, $h and $i)
authorJulian Maurice <julian.maurice@biblibre.com>
Tue, 18 Jan 2022 13:36:34 +0000 (14:36 +0100)
committerFridolin Somers <fridolin.somers@biblibre.com>
Fri, 6 May 2022 20:33:10 +0000 (10:33 -1000)
Test plan:
1. Configure the default MARC framework to use those value builders:
   - unimarc_field_146a for 146$a
   - unimarc_field_146h for 146$h
   - unimarc_field_146i for 146$i
2. Verify that they all work correctly according to
https://www.ifla.org/files/assets/uca/unimarc_updates/BIBLIOGRAPHIC/u-b_146.pdf

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
cataloguing/value_builder/unimarc_field_146a.pl [new file with mode: 0755]
cataloguing/value_builder/unimarc_field_146h.pl [new file with mode: 0755]
cataloguing/value_builder/unimarc_field_146i.pl [new file with mode: 0755]
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_146a.tt [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_146h.tt [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_146i.tt [new file with mode: 0644]

diff --git a/cataloguing/value_builder/unimarc_field_146a.pl b/cataloguing/value_builder/unimarc_field_146a.pl
new file mode 100755 (executable)
index 0000000..51f0861
--- /dev/null
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+
+# 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>.
+
+use Modern::Perl;
+
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
+
+use Koha::I18N;
+
+my $builder = sub {
+    my $params = shift;
+    my $id = $params->{id};
+
+    return qq|
+<script>
+function Click$id(event) {
+    event.preventDefault();
+    const value = document.getElementById(event.data.id).value;
+    const url = new URL('/cgi-bin/koha/cataloguing/plugin_launcher.pl', location);
+    url.searchParams.set('plugin_name', 'unimarc_field_146a.pl');
+    url.searchParams.set('id', event.data.id);
+    url.searchParams.set('value', value);
+    window.open(url.toString(), 'tag_editor', 'width=700,height=700,toolbar=false,scrollbars=yes');
+}
+</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_146a.tt",
+        query => $cgi,
+        type => 'intranet',
+        flagsrequired => { editcatalogue => '*' },
+    });
+
+    my @options = (
+        { value => 'a', label => __('vocal a cappella music') },
+        { value => 'b', label => __('instrumental music') },
+        { value => 'c', label => __('vocal and instrumental music') },
+        { value => 'd', label => __('electroacoustic music') },
+        { value => 'e', label => __('mixed media music (electroacoustic and other media)') },
+        { value => 'u', label => __('undefined, variable (e.g. Renaissance vocal or instrumental music)') },
+        { value => 'z', label => __('other (e.g. ordinary objects or natural sounds)') },
+    );
+
+    $template->param(
+        id => scalar $cgi->param('id'),
+        value => scalar $cgi->param('value'),
+        options => \@options,
+    );
+    output_html_with_http_headers $cgi, $cookie, $template->output;
+};
+
+return { builder => $builder, launcher => $launcher };
diff --git a/cataloguing/value_builder/unimarc_field_146h.pl b/cataloguing/value_builder/unimarc_field_146h.pl
new file mode 100755 (executable)
index 0000000..84ad417
--- /dev/null
@@ -0,0 +1,89 @@
+#!/usr/bin/perl
+
+# 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>.
+
+use Modern::Perl;
+
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
+
+use Koha::I18N;
+
+my $builder = sub {
+    my $params = shift;
+    my $id = $params->{id};
+
+    return qq|
+<script>
+function Click$id(event) {
+    event.preventDefault();
+    const value = document.getElementById(event.data.id).value;
+    const url = new URL('/cgi-bin/koha/cataloguing/plugin_launcher.pl', location);
+    url.searchParams.set('plugin_name', 'unimarc_field_146h.pl');
+    url.searchParams.set('id', event.data.id);
+    url.searchParams.set('value', value);
+    window.open(url.toString(), 'tag_editor', 'width=700,height=700,toolbar=false,scrollbars=yes');
+}
+</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_146h.tt",
+        query => $cgi,
+        type => 'intranet',
+        flagsrequired => { editcatalogue => '*' },
+    });
+
+    my @options = (
+        { value => 'a', label => __('performers total') },
+        { value => 'b', label => __('brass instruments') },
+        { value => 'c', label => __('choirs') },
+        { value => 'd', label => __('wind instruments') },
+        { value => 'e', label => __('electro-acoustic instruments') },
+        { value => 'i', label => __('instruments total') },
+        { value => 'j', label => __('solo instruments') },
+        { value => 'k', label => __('keyboard instruments') },
+        { value => 'l', label => __('solo voices') },
+        { value => 'm', label => __('miscellaneous, other instruments') },
+        { value => 'o', label => __('orchestras') },
+        { value => 'p', label => __('percussion instruments') },
+        { value => 'q', label => __('conductors') },
+        { value => 's', label => __('bowed string instruments') },
+        { value => 't', label => __('plucked string instruments') },
+        { value => 'v', label => __('voices total') },
+        { value => 'w', label => __('woodwind instruments') },
+        { value => 'x', label => __('choral voices') },
+        { value => 'y', label => __('ensemble instruments') },
+        { value => 'z', label => __('devices, other performers') },
+    );
+
+    my $value = $cgi->param('value');
+    my $number = substr($value, 0, 3);
+    my $category = substr($value, 3, 1);
+
+    $template->param(
+        id => scalar $cgi->param('id'),
+        number => $number,
+        category => $category,
+        options => \@options,
+    );
+    output_html_with_http_headers $cgi, $cookie, $template->output;
+};
+
+return { builder => $builder, launcher => $launcher };
diff --git a/cataloguing/value_builder/unimarc_field_146i.pl b/cataloguing/value_builder/unimarc_field_146i.pl
new file mode 100755 (executable)
index 0000000..609218d
--- /dev/null
@@ -0,0 +1,89 @@
+#!/usr/bin/perl
+
+# 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>.
+
+use Modern::Perl;
+
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
+
+use Koha::I18N;
+
+my $builder = sub {
+    my $params = shift;
+    my $id = $params->{id};
+
+    return qq|
+<script>
+function Click$id(event) {
+    event.preventDefault();
+    const value = document.getElementById(event.data.id).value;
+    const url = new URL('/cgi-bin/koha/cataloguing/plugin_launcher.pl', location);
+    url.searchParams.set('plugin_name', 'unimarc_field_146i.pl');
+    url.searchParams.set('id', event.data.id);
+    url.searchParams.set('value', value);
+    window.open(url.toString(), 'tag_editor', 'width=700,height=700,toolbar=false,scrollbars=yes');
+}
+</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_146i.tt",
+        query => $cgi,
+        type => 'intranet',
+        flagsrequired => { editcatalogue => '*' },
+    });
+
+    my @options = (
+        { value => 'a', label => __('performers total') },
+        { value => 'b', label => __('brass instruments') },
+        { value => 'c', label => __('choirs') },
+        { value => 'd', label => __('wind instruments') },
+        { value => 'e', label => __('electro-acoustic instruments') },
+        { value => 'i', label => __('instruments total') },
+        { value => 'j', label => __('solo instruments') },
+        { value => 'k', label => __('keyboard instruments') },
+        { value => 'l', label => __('solo voices') },
+        { value => 'm', label => __('miscellaneous, other instruments') },
+        { value => 'o', label => __('orchestras') },
+        { value => 'p', label => __('percussion instruments') },
+        { value => 'q', label => __('conductors') },
+        { value => 's', label => __('bowed string instruments') },
+        { value => 't', label => __('plucked string instruments') },
+        { value => 'v', label => __('voices total') },
+        { value => 'w', label => __('woodwind instruments') },
+        { value => 'x', label => __('choral voices') },
+        { value => 'y', label => __('ensemble instruments') },
+        { value => 'z', label => __('devices, other performers') },
+    );
+
+    my $value = $cgi->param('value');
+    my $number = substr($value, 0, 3);
+    my $category = substr($value, 3, 1);
+
+    $template->param(
+        id => scalar $cgi->param('id'),
+        number => $number,
+        category => $category,
+        options => \@options,
+    );
+    output_html_with_http_headers $cgi, $cookie, $template->output;
+};
+
+return { builder => $builder, launcher => $launcher };
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_146a.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_146a.tt
new file mode 100644 (file)
index 0000000..4e0b5d0
--- /dev/null
@@ -0,0 +1,47 @@
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Framework plugin unimarc_field_146a &rsaquo; Cataloguing &rsaquo; Koha</title>
+[% INCLUDE 'doc-head-close.inc' %]
+</head>
+
+<body id="unimarc_field_146a" class="cat">
+    <div class="container-fluid">
+        <h1>Framework plugin for UNIMARC 146$a</h1>
+
+        <form class="form-horizontal" id="form">
+            <input type="hidden" id="id" name="id" value="[% id | html %]">
+
+            <div class="form-group">
+                <label for="type" class="col-sm-2 control-label">Type of Performance Medium</label>
+                <div class="col-sm-10">
+                    <select class="form-control" id="type">
+                        [% FOREACH option IN options %]
+                            [% IF option.value == value %]
+                                <option value="[% option.value | html %]" selected>[% option.label | html %]</option>
+                            [% ELSE %]
+                                <option value="[% option.value | html %]">[% option.label | html %]</option>
+                            [% END %]
+                        [% END %]
+                    </select>
+                </div>
+            </div>
+
+            <div class="form-group">
+                <div class="col-sm-offset-2 col-sm-10">
+                    <button type="submit">OK</button>
+                    <a href="#" class="cancel close">Cancel</a>
+                </div>
+            </div>
+        </form>
+    </div>
+
+    <script>
+        document.getElementById('form').addEventListener('submit', function (ev) {
+            ev.preventDefault();
+            const id = document.getElementById('id').value;
+            const type = document.getElementById('type').value;
+            opener.document.getElementById(id).value = type;
+            window.close();
+        });
+    </script>
+
+[% INCLUDE 'popup-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_146h.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_146h.tt
new file mode 100644 (file)
index 0000000..a8c736d
--- /dev/null
@@ -0,0 +1,58 @@
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Framework plugin unimarc_field_146h &rsaquo; Cataloguing &rsaquo; Koha</title>
+[% INCLUDE 'doc-head-close.inc' %]
+</head>
+
+<body id="unimarc_field_146h" class="cat">
+    <div class="container-fluid">
+        <h1>Framework plugin for UNIMARC 146$h</h1>
+
+        <form class="form-horizontal" id="form">
+            <input type="hidden" id="id" name="id" value="[% id | html %]">
+
+            <div class="form-group">
+                <label for="number" class="col-sm-2 control-label">Number of parts</label>
+                <div class="col-sm-10">
+                    <input type="text" inputmode="numeric" pattern="[0-9]{1,3}" id="number" name="number" title="a number between 0 and 999 (inclusive)" value="[% number | html %]">
+                    <p class="help-block">
+                        A number between 0 and 999 (inclusive)
+                    </p>
+                </div>
+            </div>
+            <div class="form-group">
+                <label for="category" class="col-sm-2 control-label">Category</label>
+                <div class="col-sm-10">
+                    <select class="form-control" id="category">
+                        [% FOREACH option IN options %]
+                            [% IF option.value == category %]
+                                <option value="[% option.value | html %]" selected>[% option.label | html %]</option>
+                            [% ELSE %]
+                                <option value="[% option.value | html %]">[% option.label | html %]</option>
+                            [% END %]
+                        [% END %]
+                    </select>
+                </div>
+            </div>
+
+            <div class="form-group">
+                <div class="col-sm-offset-2 col-sm-10">
+                    <button type="submit">OK</button>
+                    <a href="#" class="cancel close">Cancel</a>
+                </div>
+            </div>
+        </form>
+    </div>
+
+    <script>
+        document.getElementById('form').addEventListener('submit', function (ev) {
+            ev.preventDefault();
+            const id = document.getElementById('id').value;
+            const number = document.getElementById('number').value;
+            const category = document.getElementById('category').value;
+            const value = number.toString().padStart(3, '0') + category;
+            opener.document.getElementById(id).value = value;
+            window.close();
+        });
+    </script>
+
+[% INCLUDE 'popup-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_146i.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_146i.tt
new file mode 100644 (file)
index 0000000..189219b
--- /dev/null
@@ -0,0 +1,58 @@
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Framework plugin unimarc_field_146i &rsaquo; Cataloguing &rsaquo; Koha</title>
+[% INCLUDE 'doc-head-close.inc' %]
+</head>
+
+<body id="unimarc_field_146i" class="cat">
+    <div class="container-fluid">
+        <h1>Framework plugin for UNIMARC 146$i</h1>
+
+        <form class="form-horizontal" id="form">
+            <input type="hidden" id="id" name="id" value="[% id | html %]">
+
+            <div class="form-group">
+                <label for="number" class="col-sm-2 control-label">Number of players</label>
+                <div class="col-sm-10">
+                    <input type="text" inputmode="numeric" pattern="[0-9]{1,3}" id="number" name="number" title="a number between 0 and 999 (inclusive)" value="[% number | html %]">
+                    <p class="help-block">
+                        A number between 0 and 999 (inclusive)
+                    </p>
+                </div>
+            </div>
+            <div class="form-group">
+                <label for="category" class="col-sm-2 control-label">Category</label>
+                <div class="col-sm-10">
+                    <select class="form-control" id="category">
+                        [% FOREACH option IN options %]
+                            [% IF option.value == category %]
+                                <option value="[% option.value | html %]" selected>[% option.label | html %]</option>
+                            [% ELSE %]
+                                <option value="[% option.value | html %]">[% option.label | html %]</option>
+                            [% END %]
+                        [% END %]
+                    </select>
+                </div>
+            </div>
+
+            <div class="form-group">
+                <div class="col-sm-offset-2 col-sm-10">
+                    <button type="submit">OK</button>
+                    <a href="#" class="cancel close">Cancel</a>
+                </div>
+            </div>
+        </form>
+    </div>
+
+    <script>
+        document.getElementById('form').addEventListener('submit', function (ev) {
+            ev.preventDefault();
+            const id = document.getElementById('id').value;
+            const number = document.getElementById('number').value;
+            const category = document.getElementById('category').value;
+            const value = number.toString().padStart(3, '0') + category;
+            opener.document.getElementById(id).value = value;
+            window.close();
+        });
+    </script>
+
+[% INCLUDE 'popup-bottom.inc' %]