Bug 30604: Add value builders for UNIMARC 146 ($a, $h and $i)
[koha.git] / cataloguing / value_builder / unimarc_field_146a.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use C4::Auth qw( get_template_and_user );
21 use C4::Output qw( output_html_with_http_headers );
22
23 use Koha::I18N;
24
25 my $builder = sub {
26     my $params = shift;
27     my $id = $params->{id};
28
29     return qq|
30 <script>
31 function Click$id(event) {
32     event.preventDefault();
33     const value = document.getElementById(event.data.id).value;
34     const url = new URL('/cgi-bin/koha/cataloguing/plugin_launcher.pl', location);
35     url.searchParams.set('plugin_name', 'unimarc_field_146a.pl');
36     url.searchParams.set('id', event.data.id);
37     url.searchParams.set('value', value);
38     window.open(url.toString(), 'tag_editor', 'width=700,height=700,toolbar=false,scrollbars=yes');
39 }
40 </script>|;
41 };
42
43 my $launcher = sub {
44     my $params = shift;
45     my $cgi = $params->{cgi};
46     my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
47         template_name => "cataloguing/value_builder/unimarc_field_146a.tt",
48         query => $cgi,
49         type => 'intranet',
50         flagsrequired => { editcatalogue => '*' },
51     });
52
53     my @options = (
54         { value => 'a', label => __('vocal a cappella music') },
55         { value => 'b', label => __('instrumental music') },
56         { value => 'c', label => __('vocal and instrumental music') },
57         { value => 'd', label => __('electroacoustic music') },
58         { value => 'e', label => __('mixed media music (electroacoustic and other media)') },
59         { value => 'u', label => __('undefined, variable (e.g. Renaissance vocal or instrumental music)') },
60         { value => 'z', label => __('other (e.g. ordinary objects or natural sounds)') },
61     );
62
63     $template->param(
64         id => scalar $cgi->param('id'),
65         value => scalar $cgi->param('value'),
66         options => \@options,
67     );
68     output_html_with_http_headers $cgi, $cookie, $template->output;
69 };
70
71 return { builder => $builder, launcher => $launcher };