View | Details | Raw Unified | Return to bug 35067
Collapse All | Expand All

(-)a/cataloguing/value_builder/multipleAV.pl (+95 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2024 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use CGI qw ( -utf8 );
22
23
use C4::Auth qw( get_template_and_user );
24
use C4::Output qw( output_html_with_http_headers );
25
use Koha::AuthorisedValues;
26
27
=head1 DESCRIPTION
28
29
This plugin allows the cataloguer to choose one or more authorised value categories that should be available for selection in the dropdown for this subfield.
30
31
=cut
32
33
my $builder = sub {
34
    my ( $params ) = @_;
35
    my $res = qq{
36
    <script>
37
        function Click$params->{id}(ev) {
38
                ev.preventDefault();
39
                var code = document.getElementById(ev.data.id);
40
                \$.ajax({
41
                    url: '/cgi-bin/koha/cataloguing/plugin_launcher.pl',
42
                    type: 'POST',
43
                    data: {
44
                        'plugin_name': 'multipleAV.pl',
45
                        'code'    : code.value,
46
                    },
47
                    success: function(data){
48
                        var field = document.getElementById(ev.data.id);
49
                        field.value = data;
50
                        return 1;
51
                    }
52
                });
53
        }
54
    </script>
55
    };
56
57
    return $res;
58
};
59
60
my $launcher = sub {
61
    my ( $params ) = @_;
62
    my $input = $params->{cgi};
63
    my $code = $input->param('code');
64
65
    my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
66
        {   template_name   => "cataloguing/value_builder/ajax.tt",
67
            query           => $input,
68
            type            => "intranet",
69
            flagsrequired   => { editcatalogue => '*' },
70
        }
71
    );
72
73
    # If a prefix is submited, we look for the highest stocknumber with this prefix, and return it incremented
74
    $code =~ s/ *$//g;
75
    if ( $code =~ m/^[a-zA-Z]+$/ ) {
76
        my $av = Koha::AuthorisedValues->find({
77
            'category' => 'INVENTORY',
78
            'authorised_value' => $code
79
        });
80
        if ( $av ) {
81
            $av->lib($av->lib + 1);
82
            $av->store;
83
            $template->param( return => $code . ' ' . sprintf( '%010s', ( $av->lib ) ), );
84
        } else {
85
            $template->param( return => "There is no defined value for $code");
86
        }
87
        # The user entered a custom value, we don't touch it, this could be handled in js
88
    } else {
89
        $template->param( return => $code, );
90
    }
91
92
    output_html_with_http_headers $input, $cookie, $template->output;
93
};
94
95
return { builder => $builder, launcher => $launcher };
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/multipleAV.tt (-1 / +46 lines)
Line 0 Link Here
0
- 
1
[% USE raw %]
2
[% USE Koha %]
3
[% PROCESS 'i18n.inc' %]
4
[% SET footerjs = 1 %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
<title>[% FILTER collapse %]
7
    [% t("Multiple authorised values dropdown builder") | html %] &rsaquo;
8
    [% t("Cataloging") | html %] &rsaquo;
9
    [% t("Koha") | html %]
10
[% END %]</title>
11
[% INCLUDE 'doc-head-close.inc' %]
12
</head>
13
14
<body id="cat_marc21_leader" class="cat value_builder">
15
    <form name="f_pop" onsubmit="report()" action="">
16
        <input type="hidden" name="plugin_name" value="multipleAV.pl" />
17
        <h1>Multiple authorised values dropdown builder</h1>
18
19
        <div class="page-section">
20
        </div> <!-- /.page-section -->
21
    </form>
22
23
[% MACRO jsinclude BLOCK %]
24
    <script>
25
        function report() {
26
            var doc   = opener.document;
27
            var field = doc.getElementById("[% index | html %]");
28
            field.value =
29
            '     '+
30
            document.f_pop.f5.value +
31
            document.f_pop.f6.value +
32
            document.f_pop.f7.value +
33
            document.f_pop.f8.value +
34
            'a'+ // MARC21 UNICODE flag - must be 'a' for Koha
35
            '22     '+
36
            document.f_pop.f17.value +
37
            document.f_pop.f18.value +
38
            document.f_pop.f19.value +
39
            '4500';
40
            self.close();
41
            return false;
42
        }
43
    </script>
44
[% END %]
45
46
[% INCLUDE 'intranet-bottom.inc' popup_window=1 %]

Return to bug 35067