Bug 6874: Force user to select a directory
authorJulian Maurice <julian.maurice@biblibre.com>
Mon, 30 Sep 2013 07:34:01 +0000 (09:34 +0200)
committerTomas Cohen Arazi <tomascohen@unc.edu.ar>
Fri, 7 Aug 2015 18:22:44 +0000 (15:22 -0300)
This patch adds a javascript and a server-side checks

Test plan:
1/ Choose a file, leave the radios not selected and submit
2/ You have a javascript alert which prevents form to be submitted
3/ Disable javascript and repeat step 1
4/ Form is submitted but form is redisplayed with an error message
telling you to choose a directory.

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
cataloguing/value_builder/upload.pl
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/upload.tt

index 4e6683a..966f0b3 100755 (executable)
@@ -80,9 +80,9 @@ sub plugin {
     );
 
     # Dealing with the uploaded file
-    if ($uploaded_file) {
+    my $dir = $input->param('dir');
+    if ($uploaded_file and $dir) {
         my $fh = $input->upload('uploaded_file');
-        my $dir = $input->param('dir');
 
         $id = C4::UploadedFiles::UploadFile($uploaded_file, $dir, $fh->handle);
         if($id) {
@@ -128,6 +128,10 @@ sub plugin {
         } else {
             $template->param( error_upload_path_not_configured => 1 );
         }
+
+        if ($uploaded_file and not $dir) {
+            $template->param(error_no_dir_selected => 1);
+        }
     }
 
     $template->param(
index cd983ad..63849f8 100644 (file)
@@ -6,6 +6,20 @@
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <script type="text/javascript" src="[% interface %]/lib/jquery/jquery.js"></script>
     <link rel="stylesheet" type="text/css" href="[% themelang %]/css/staff-global.css" />
+    <script type="text/javascript">
+      function _(s) { return s; }
+      $(document).ready(function() {
+        $('form').each(function() {
+          $(this).submit(function() {
+            var value = $(this).find('input[type="radio"][name="dir"]:checked').val();
+            if (!value) {
+              alert(_("Please select the destination of file"));
+              return false;
+            }
+          });
+        })
+      });
+    </script>
 
 </head>
 <body>
@@ -59,6 +73,9 @@
           <p>Configuration variable 'upload_path' is not configured.</p>
           <p>Please configure it in your koha-conf.xml</p>
         [% ELSE %]
+          [% IF (error_no_dir_selected) %]
+              <p class="error">Error: You have to select the destination of uploaded file.<p>
+          [% END %]
           <h2>Please select the file to upload : </h2>
           <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/cataloguing/plugin_launcher.pl">
               [% filefield %]