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

(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js (-9 / +13 lines)
Lines 555-574 $(document).ready(function() { Link Here
555
    }
555
    }
556
556
557
    $("#add_new_av").on("submit", function(){
557
    $("#add_new_av").on("submit", function(){
558
        var data = {
558
        var category         = $(this).find('input[name="category"]').val();
559
            category: $(this).find('input[name="category"]').val(),
559
        var value            = $(this).find('input[name="value"]').val();
560
            value: $(this).find('input[name="value"]').val(),
560
        var description      = $(this).find('input[name="description"]').val();
561
            description: $(this).find('input[name="description"]').val(),
561
        var opac_description = $(this).find('input[name="opac_description"]').val();
562
            opac_description: $(this).find('input[name="opac_description"]').val(),
562
563
        };
563
        var data = "category="+encodeURIComponent(category)
564
            +"&value="+encodeURIComponent(value)
565
            +"&description="+encodeURIComponent(description)
566
            +"&opac_description="+encodeURIComponent(opac_description);
567
564
        $.ajax({
568
        $.ajax({
565
            type: "POST",
569
            type: "POST",
566
            url: "/api/v1/authorised_values",
570
            url: "/cgi-bin/koha/svc/authorised_values",
567
            data:JSON.stringify(data),
571
            data: data,
568
            success: function(response) {
572
            success: function(response) {
569
                $('#avCreate').modal('hide');
573
                $('#avCreate').modal('hide');
570
574
571
                $(current_select2).append('<option selected value="'+data['value']+'">'+data['description']+'</option>');
575
                $(current_select2).append('<option selected value="'+response.value+'">'+response.description+'</option>');
572
            },
576
            },
573
            error: function(err) {
577
            error: function(err) {
574
                $("#avCreate .error").html(_("Something went wrong, maybe the value already exists?"))
578
                $("#avCreate .error").html(_("Something went wrong, maybe the value already exists?"))
(-)a/svc/authorised_values (-1 / +72 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2020 Koha Development Team
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
22
use JSON qw( to_json );
23
use CGI;
24
use C4::Service;
25
use C4::Auth qw( check_cookie_auth );
26
use C4::Output qw(:DEFAULT :ajax);
27
use Koha::AuthorisedValues;
28
29
=head1 NAME
30
31
svc/authorised_values - Web service for adding authorised values
32
33
=head1 DESCRIPTION
34
35
=cut
36
37
our ( $query, $response ) = C4::Service->init( parameters => 'manage_auth_values' );
38
39
sub add_authorised_value {
40
    my $category         = $query->param('category');
41
    my $value            = $query->param('value');
42
    my $description      = $query->param('description');
43
    my $opac_description = $query->param('opac_description');
44
    my $image_url        = $query->param('image_url');
45
46
    eval {
47
        my $av = Koha::AuthorisedValue->new(
48
            {
49
                category         => $category,
50
                authorised_value => $value,
51
                lib              => $description,
52
                lib_opac         => $opac_description,
53
                imageurl         => $image_url,
54
            }
55
        );
56
        $av->store;
57
        $response->param(
58
            category         => $av->category,
59
            value            => $av->authorised_value,
60
            description      => $av->lib,
61
            opac_description => $av->lib_opac,
62
            image_url        => $av->imageurl,
63
        );
64
    };
65
    C4::Service->return_error ( $@ ) if $@;
66
67
    C4::Service->return_success( $response );
68
}
69
70
C4::Service->dispatch(
71
    [ 'POST /', [ 'category', 'value', 'description', 'opac_description' ], \&add_authorised_value ],
72
);

Return to bug 25728