Bug 10848 - Allow configuration of mandatory/required fields on the suggestion form...
authorJacek Ablewicz <abl@biblos.pk.edu.pl>
Fri, 5 Aug 2016 08:47:11 +0000 (10:47 +0200)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 2 Sep 2016 16:00:50 +0000 (16:00 +0000)
This patch adds a configuration option which allows to define which
fields should be mandatory for a patron purchase suggestion form in OPAC.

Test plan:

1/ Apply patch.
2/ Play with the new OPACSuggestionMandatoryFields system preference
(select some fields as manadatory, select all, deselect all, try to
submit some suggestions with mandatory fields filled and/or not
filled etc.) to ensure that required fields (and only required fields)
are enforced in the browser to be filled.
3/ With all options deselected, 'Title' field should still be
mandatory (by default).

Signed-off-by: barbara johnson <barbara.johnson@bedfordtx.gov>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt
opac/opac-suggestions.pl

index a6a515a..cf4dec2 100644 (file)
                             <h1>Enter a new purchase suggestion</h1>
 
                             <p>Please fill out this form to make a purchase suggestion. You will receive an email when the library processes your suggestion</p>
-                            <p>Only the title is required, but the more information you enter the easier it will be for the librarians to find the title you're requesting. The "Notes" field can be used to provide any additional information.</p>
+                            <p>Only certain fields (marked in red) are required, but the more information you enter the easier it will be for the librarians to find the title you're requesting. The "Notes" field can be used to provide any additional information.</p>
 
-                            <form action="/cgi-bin/koha/opac-suggestions.pl" method="post">
+                            <form action="/cgi-bin/koha/opac-suggestions.pl" method="post" id="add_suggestion_form">
                                 <fieldset class="rows">
                                     <ol>
-                                        <li><label class="required" for="title">Title:</label><input type="text" id="title" name="title" class="span6" maxlength="255" /></li>
+                                        <li><label for="title">Title:</label><input type="text" id="title" name="title" class="span6" maxlength="255" /></li>
                                         <li><label for="author">Author:</label><input type="text" id="author" name="author" class="span6" maxlength="80" /></li>
-                                        <li><label for="copyrightdate">Copyright date:</label><input type="text" id="copyrightdate" name="copyrightdate" size="4" maxlength="4" /></li>
+                                        <li><label for="copyrightdate">Copyright date:</label><input type="text" id="copyrightdate" name="copyrightdate" pattern="[12][0-9\-\?]{3}" size="4" maxlength="4" /></li>
                                         <li><label for="isbn">Standard number (ISBN, ISSN or other):</label><input type="text" id="isbn" name="isbn"  maxlength="80" /></li>
                                         <li><label for="publishercode">Publisher:</label><input type="text" id="publishercode" name="publishercode" class="span6" maxlength="80" /></li>
                                         <li><label for="collectiontitle">Collection title:</label><input type="text" id="collectiontitle" name="collectiontitle" class="span6" maxlength="80" /></li>
@@ -89,7 +89,7 @@
                                 <fieldset class="action">
                                     <input type="hidden" name="suggested_by_anyone" value="[% suggested_by_anyone %]" />
                                     <input type="hidden" name="op" value="add_confirm" />
-                                    <input type="submit" onclick="Check(this.form); return false;" class="btn" value="Submit your suggestion" /> <a class="action" href="/cgi-bin/koha/opac-suggestions.pl">Cancel</a>
+                                    <input type="submit" class="btn" value="Submit your suggestion" /> <a class="action" href="/cgi-bin/koha/opac-suggestions.pl">Cancel</a>
                                 </fieldset>
                             </form>
                             [% END %]
           return true;
         });
         [% END %]
-    });
-
-    function Check(f) {
-        var _alertString="";
-        var alertString2;
-
-        if(f.title.value.length ==0){
-            _alertString += _("- You must enter a Title") + "\n";
-        }
-
-        if (_alertString.length==0) {
-            f.submit();
-        } else {
-            alertString2 = _("Form not submitted because of the following problem(s)");
-            alertString2 += "\n------------------------------------------------------------------------------------\n\n";
-            alertString2 += _alertString;
-            alert(alertString2);
+        [% IF ( op_add && mandatoryfields ) %]
+        {
+            var FldsRequired = [[% mandatoryfields %]];
+            for (var i = 0; i < FldsRequired.length; i++) {
+                var rq_input = $('#' + FldsRequired[i]);
+                if (rq_input.length != 1) continue;
+                $(rq_input).attr("required", "required");
+                var rq_label = $("label[for=" + rq_input.attr("id") + "]");
+                if (rq_label.length != 1) continue;
+                $(rq_label).addClass('required');
+            }
         }
-    }
+        [% END %]
+    });
 //]]>
 </script>
 [% END %]
index 628f864..b183364 100755 (executable)
@@ -207,6 +207,13 @@ if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) {
     $template->param( branchloop => $branchloop );
 }
 
+my $mandatoryfields = '';
+{
+    last unless ($op eq 'add');
+    my $fldsreq_sp = C4::Context->preference("OPACSuggestionMandatoryFields") || 'title';
+    $mandatoryfields = join(', ', (map { '"'.$_.'"'; } sort split(/\s*\,\s*/, $fldsreq_sp)));
+}
+
 $template->param(
     %$suggestion,
     suggestions_loop      => $suggestions_loop,
@@ -216,6 +223,7 @@ $template->param(
     messages              => \@messages,
     suggestionsview       => 1,
     suggested_by_anyone   => $suggested_by_anyone,
+    mandatoryfields       => $mandatoryfields,
     patrons_pending_suggestions_count => $patrons_pending_suggestions_count,
 );