Bugzilla – Attachment 105852 Details for
Bug 25728
Add the ability to create a new authorised value within the cataloguing module
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25728: Use a svc script instead of the REST API endpoint
Bug-25728-Use-a-svc-script-instead-of-the-REST-API.patch (text/plain), 4.95 KB, created by
Jonathan Druart
on 2020-06-13 10:38:45 UTC
(
hide
)
Description:
Bug 25728: Use a svc script instead of the REST API endpoint
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-06-13 10:38:45 UTC
Size:
4.95 KB
patch
obsolete
>From 20e83a01717b0876b684c9b5f5cf5236e64fc58d Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Sat, 13 Jun 2020 12:36:01 +0200 >Subject: [PATCH] Bug 25728: Use a svc script instead of the REST API endpoint > >The try to implement correctly the REST API endpoint for authorised >values failed. >This patch uses an easy to implement svc script for the POST route. >--- > koha-tmpl/intranet-tmpl/prog/js/cataloging.js | 22 +++--- > svc/authorised_values | 72 +++++++++++++++++++ > 2 files changed, 85 insertions(+), 9 deletions(-) > create mode 100755 svc/authorised_values > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js >index fd462b67ed..9f077d765a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js >@@ -555,20 +555,24 @@ $(document).ready(function() { > } > > $("#add_new_av").on("submit", function(){ >- var data = { >- category: $(this).find('input[name="category"]').val(), >- value: $(this).find('input[name="value"]').val(), >- description: $(this).find('input[name="description"]').val(), >- opac_description: $(this).find('input[name="opac_description"]').val(), >- }; >+ var category = $(this).find('input[name="category"]').val(); >+ var value = $(this).find('input[name="value"]').val(); >+ var description = $(this).find('input[name="description"]').val(); >+ var opac_description = $(this).find('input[name="opac_description"]').val(); >+ >+ var data = "category="+encodeURIComponent(category) >+ +"&value="+encodeURIComponent(value) >+ +"&description="+encodeURIComponent(description) >+ +"&opac_description="+encodeURIComponent(opac_description); >+ > $.ajax({ > type: "POST", >- url: "/api/v1/authorised_values", >- data:JSON.stringify(data), >+ url: "/cgi-bin/koha/svc/authorised_values", >+ data: data, > success: function(response) { > $('#avCreate').modal('hide'); > >- $(current_select2).append('<option selected value="'+data['value']+'">'+data['description']+'</option>'); >+ $(current_select2).append('<option selected value="'+response.value+'">'+response.description+'</option>'); > }, > error: function(err) { > $("#avCreate .error").html(_("Something went wrong, maybe the value already exists?")) >diff --git a/svc/authorised_values b/svc/authorised_values >new file mode 100755 >index 0000000000..692b82d6d7 >--- /dev/null >+++ b/svc/authorised_values >@@ -0,0 +1,72 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Copyright 2020 Koha Development Team >+# >+# 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 JSON qw( to_json ); >+use CGI; >+use C4::Service; >+use C4::Auth qw( check_cookie_auth ); >+use C4::Output qw(:DEFAULT :ajax); >+use Koha::AuthorisedValues; >+ >+=head1 NAME >+ >+svc/authorised_values - Web service for adding authorised values >+ >+=head1 DESCRIPTION >+ >+=cut >+ >+our ( $query, $response ) = C4::Service->init( parameters => 'manage_auth_values' ); >+ >+sub add_authorised_value { >+ my $category = $query->param('category'); >+ my $value = $query->param('value'); >+ my $description = $query->param('description'); >+ my $opac_description = $query->param('opac_description'); >+ my $image_url = $query->param('image_url'); >+ >+ eval { >+ my $av = Koha::AuthorisedValue->new( >+ { >+ category => $category, >+ authorised_value => $value, >+ lib => $description, >+ lib_opac => $opac_description, >+ imageurl => $image_url, >+ } >+ ); >+ $av->store; >+ $response->param( >+ category => $av->category, >+ value => $av->authorised_value, >+ description => $av->lib, >+ opac_description => $av->lib_opac, >+ image_url => $av->imageurl, >+ ); >+ }; >+ C4::Service->return_error ( $@ ) if $@; >+ >+ C4::Service->return_success( $response ); >+} >+ >+C4::Service->dispatch( >+ [ 'POST /', [ 'category', 'value', 'description', 'opac_description' ], \&add_authorised_value ], >+); >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 25728
:
105837
|
105838
|
105839
|
105840
|
105841
|
105842
|
105852
|
106696
|
106697
|
106698
|
106699
|
106700
|
106701
|
106702
|
108356
|
108357
|
108358
|
108359
|
108360
|
108361
|
108362
|
108883
|
108884
|
108885
|
108886
|
108887
|
108888
|
108889
|
108890
|
108922
|
108923
|
108924
|
108925
|
108926
|
108927
|
108928
|
108929
|
108930
|
108931