From 92c6d3511ee42d9040fd8c4cda1fc1661024b075 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 13 Dec 2019 12:41:20 +0100 Subject: [PATCH] Bug 21232: Add a client-side check on biblionumber when creating a subscription This patch adds an AJAX call to the REST API (/api/v1/biblios/) to retrieve and display the biblio's title. On clicking the "next" button a check is done to make sure the title exists, which means the biblionumber we manually entered is valid (can we assume a title is mandatory?) Test plan: - Create or edit a new subscription - Enter an invalid biblionumber in the input => A friendly note is telling you that the biblio does not exist - Try to switch to the next screen => You get an alert - Enter a valid biblionumber in the input => The title is displayed => Try to switch to the next screen => It works! Signed-off-by: hc Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- .../en/modules/serials/subscription-add.tt | 1 + .../intranet-tmpl/prog/js/subscription-add.js | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt index e59c3258a7..c5dd38639c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt @@ -61,6 +61,7 @@ fieldset.rows table { clear: none; margin: 0; } () Required +
Subscriptions must be associated with a bibliographic record
Search for record [% IF ( CAN_user_editcatalogue ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js index 63104717bd..8f14fba505 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js +++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js @@ -52,12 +52,17 @@ function Check_page1() { return false; } } - if ($("#biblionumber").val().length == 0) { + + var biblionumber = $("#biblionumber").val() + if ( biblionumber.length == 0 ) { alert( MSG_LINK_BIBLIO ); return false; } - return true; + var bib_exists = $("input[name='title']").val().length; + + if (!bib_exists) alert(_("Bibliographic record does not exist!")); + return bib_exists; } function Check_page2(){ @@ -694,4 +699,25 @@ $(document).ready(function() { e.preventDefault(); hidePredcitionPatternTest(); }); + + $("#biblionumber").on("change", function(){ + var biblionumber = $(this).val(); + $.ajax({ + url: "/api/v1/biblios/" + biblionumber, + type: "GET", + headers: { + Accept: "application/json", + }, + contentType: "application/json", + success: function (biblio) { + $("input[name='title']").val(biblio['title']); + $("#error_bib_not_exist").html(""); + }, + error: function (x) { + $("input[name='title']").val(''); + $("#error_bib_not_exist").html("This bibliographic record does not exist"); + } + }); + }); + }); -- 2.39.5