From c800131fba5c600a02cd4ec30b9bd67139ee2330 Mon Sep 17 00:00:00 2001 From: Jacek Ablewicz Date: Fri, 5 Aug 2016 10:47:11 +0200 Subject: [PATCH] [PASSED QA] Bug 10848 - Allow configuration of mandatory/required fields on the suggestion form in OPAC 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 Signed-off-by: Katrin Fischer --- .../bootstrap/en/modules/opac-suggestions.tt | 41 ++++++++++------------ opac/opac-suggestions.pl | 8 +++++ 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt index a6a515a..cf4dec2 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt @@ -35,14 +35,14 @@

Enter a new purchase suggestion

Please fill out this form to make a purchase suggestion. You will receive an email when the library processes your suggestion

-

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.

+

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.

-
+
    -
  1. +
  2. -
  3. +
  4. @@ -89,7 +89,7 @@
    - Cancel + Cancel
    [% END %] @@ -337,25 +337,20 @@ 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 %] + }); //]]> [% END %] diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl index 628f864..b183364 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -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, ); -- 1.9.1