From 902b1242db9401fbda381cba9bf0c2042c6daef0 Mon Sep 17 00:00:00 2001 From: Jacek Ablewicz Date: Sun, 8 Jun 2014 12:04:24 +0200 Subject: [PATCH] Bug 10848 - Allow configuration of mandatory/required fields on the suggestion form in OPAC #1/2 (part #1: changes in opac-suggestions.* script + bootstrap template) This patch adds a configuration option which allows to define which fields (apart from the title) should be mandatory for a patron purchase suggestion form in OPAC. Supported fields that are configurable as mandatory/not mandatory for suggestions made via OPAC are: author|copyrightdate|isbn| publishercode|place|itemtype|patronreason. Note: this patch only applies to OPAC bootstrap theme. To test: 1/ Apply patch. 2/ Without 'OPACSuggestionMandatoryFields' option set, OPAC suggestion form should work as previously ("Only the title is required"). 3/ Set 'OPACSuggestionMandatoryFields' syspref to (e.g.) 'author|isbn|itemtype' 4/ Note that suggestion form in OPAC now requires 3 more fields to be entered and/or choosen (they should be labeled in red), and the user instruction changes slightly ("Form fields labeled in red are mandatory" ..). 5/ Try to submit some suggestions: for each field which is configured as mandatory, but is not filled with anything, there should be and extra message displayed regarding this field. 6/ Unless all mandatory fields are filled with something, form submission should not be possible. 7/ Repeat test 3-6 for all supported field names configurable as mandatory. --- .../bootstrap/en/modules/opac-suggestions.tt | 42 ++++++++++++++++---- opac/opac-suggestions.pl | 8 ++++ 2 files changed, 42 insertions(+), 8 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 e10f37e..206d7dc 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt @@ -29,19 +29,24 @@

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.

+ [% IF (mandatoryfields) %] +

Form fields labeled in red are mandatory. The more information you enter the easier it will be for the librarians to find the title you're requesting. + [% ELSE %] +

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. + [% END %] + The "Notes" field can be used to provide any additional information.

  1. -
  2. -
  3. -
  4. -
  5. +
  6. +
  7. +
  8. +
  9. -
  10. -
  11. +
  12. +
  13. [% FOREACH patron_reason_loo IN patron_reason_loop %] @@ -313,6 +318,27 @@ if(f.title.value.length ==0){ _alertString += _("- You must enter a Title") + "\n"; } + [% IF (mandatoryfields.author) %]if (f.author.value.length == 0){ + _alertString += _("- You must enter an Author") + "\n"; + }[% END %] + [% IF (mandatoryfields.copyrightdate) %]if (f.copyrightdate.value.length == 0){ + _alertString += _("- You must enter a Copyright date") + "\n"; + }[% END %] + [% IF (mandatoryfields.isbn) %]if (f.isbn.value.length == 0){ + _alertString += _("- You must enter a Standard number (ISBN, ISSN or other)") + "\n"; + }[% END %] + [% IF (mandatoryfields.publishercode) %]if (f.publishercode.value.length == 0){ + _alertString += _("- You must enter a Publisher") + "\n"; + }[% END %] + [% IF (mandatoryfields.place) %]if (f.place.value.length == 0){ + _alertString += _("- You must enter a Publication place") + "\n"; + }[% END %] + [% IF (mandatoryfields.itemtype) %]if (f.itemtype.value.length == 0){ + _alertString += _("- You must choose an Item type") + "\n"; + }[% END %] + [% IF (patron_reason_loop && mandatoryfields.patronreason) %]if (f.patronreason.value.length == 0){ + _alertString += _("- You must choose a Reason for suggestion") + "\n"; + }[% END %] if (_alertString.length==0) { f.submit(); diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl index ac6172d..f64e7a8 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -153,6 +153,13 @@ if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) { $template->param( branchloop => $branchloop ); } +my $mandatoryfields = {}; +{ + my $fldsreqsp = C4::Context->preference("OPACSuggestionMandatoryFields"); + ($op eq 'add' && $fldsreqsp) || last; + map { $_ && ($mandatoryfields->{$_} = 1); } (split(/\s*\|\s*/, $fldsreqsp)); +} + $template->param( %$suggestion, itemtypeloop=> $supportlist, @@ -161,6 +168,7 @@ $template->param( showall => $allsuggestions, "op_$op" => 1, suggestionsview => 1, + mandatoryfields => $mandatoryfields, ); output_html_with_http_headers $input, $cookie, $template->output; -- 1.7.10.4