From f1a5396097f588b6903a4bae6d956a3cab8d0d45 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 11 Nov 2019 12:14:50 +0100 Subject: [PATCH] Bug 23888: Do not allow invalid vendor id on creating a subscription It will avoid crash and invalid data when creating/updating a subscription. This could have been done with a AJAX query but seems more convenient this way. Test plan: - Create or update a subscription - In the "Vendor" input try an empty string, a valid vendor's id, and invalid one. => With an empty string you get the existing alert message => With a valid id you do not get any messages => With an invalid id you are not allowed to go to page 2 --- .../intranet-tmpl/prog/en/modules/serials/subscription-add.tt | 5 +++++ koha-tmpl/intranet-tmpl/prog/js/subscription-add.js | 9 ++++++++- serials/subscription-add.pl | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) 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..d21235d5b6 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 @@ -1,4 +1,5 @@ [% USE raw %] +[% USE To %] [% USE Asset %] [% USE KohaDates %] [% USE Branches %] @@ -552,6 +553,10 @@ fieldset.rows table { clear: none; margin: 0; } var MSG_MANA_SHOW_DETAILS = _("Show Mana results"); var MSG_MANA_NO_SUBSCRIPTION_FOUND = _("No subscription found on Mana Knowledge Base"); var MSG_MANA_SHARE_PATTERN = _("Please feel free to share your pattern with all others librarians once you are done"); + + [% IF bookseller_ids %] + var BOOKSELLER_IDS = [% To.json( bookseller_ids ) %] + [% END %] [% Asset.js("js/subscription-add.js") | $raw %] [% Asset.js("js/showpredictionpattern.js") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js index 63104717bd..3377eb1ca8 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js +++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js @@ -46,11 +46,18 @@ function Clear(id) { } function Check_page1() { - if ( $("#aqbooksellerid").val().length == 0) { + var bookseller_id = $("#aqbooksellerid").val(); + if ( bookseller_id.length == 0) { input_box = confirm( MSG_LINK_TO_VENDOR ); if (input_box==false) { return false; } + } else { + var bookseller_ids = BOOKSELLER_IDS; + if ( $.inArray(Number(bookseller_id), bookseller_ids) == -1 ) { + alert ("The vendor does not exist"); + return false; + } } if ($("#biblionumber").val().length == 0) { alert( MSG_LINK_BIBLIO ); diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index ebc19a05e9..a7b483be18 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -244,6 +244,9 @@ if ($op eq 'addsubscription') { $template->param( locales => $languages ); + my @bookseller_ids = Koha::Acquisition::Booksellers->search->get_column('id'); + $template->param( bookseller_ids => \@bookseller_ids ); + output_html_with_http_headers $query, $cookie, $template->output; } -- 2.11.0