Bug 23888: Do not allow invalid vendor id on creating a subscription
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 11 Nov 2019 11:14:50 +0000 (12:14 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 27 Mar 2020 12:14:09 +0000 (12:14 +0000)
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

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt
koha-tmpl/intranet-tmpl/prog/js/subscription-add.js
serials/subscription-add.pl

index c2b3af0..fd603e1 100644 (file)
@@ -1,4 +1,5 @@
 [% USE raw %]
+[% USE To %]
 [% USE Asset %]
 [% USE KohaDates %]
 [% USE Branches %]
@@ -554,6 +555,8 @@ 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");
+
+        var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | $raw %];
     </script>
     [% Asset.js("js/subscription-add.js") | $raw %]
     [% Asset.js("js/showpredictionpattern.js") | $raw %]
index 06fae0f..79de60d 100644 (file)
@@ -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;
+        }
     }
 
     var biblionumber = $("#biblionumber").val()
index ebc19a0..a7b483b 100755 (executable)
@@ -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;
 }