Bugzilla – Attachment 34325 Details for
Bug 10848
Allow configuration of mandatory/required fields on the suggestion form in OPAC
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10848 - Allow configuration of mandatory/required fields on the suggestion form in OPAC #1/2
Bug-10848---Allow-configuration-of-mandatoryrequir.patch (text/plain), 7.81 KB, created by
Biblibre Sandboxes
on 2014-12-11 14:49:32 UTC
(
hide
)
Description:
Bug 10848 - Allow configuration of mandatory/required fields on the suggestion form in OPAC #1/2
Filename:
MIME Type:
Creator:
Biblibre Sandboxes
Created:
2014-12-11 14:49:32 UTC
Size:
7.81 KB
patch
obsolete
>From f8efdaa729a2e87d781800c1799a6f04f446cc9b Mon Sep 17 00:00:00 2001 >From: Jacek Ablewicz <abl@biblos.pk.edu.pl> >Date: Fri, 20 Jun 2014 12:35:19 +0200 >Subject: [PATCH] Bug 10848 - Allow configuration of mandatory/required fields on the suggestion form in OPAC #1/2 >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >(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 >- impoves the method how required form fields are enforced, by >utilising new HTML5 "required" attribute (old method would still be >operational in old/legacy browsers which do not support "required" >attribute properly). > >Allowed fields that are configurable as mandatory/not mandatory >for suggestions made via OPAC are: author|copyrightdate|collectiontitle| >isbn|publishercode|place|note|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 only require the title field. >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, browser should enforce this field to be filled (in modern, >HTML5 compilant browsers), or (as a fallback mechanism for legacy >browsers) there should be an alert message displayed stating that some >mandatory fields are missing. >6/ In both modern and legacy browsers, 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. > >If possible, "legacy" browser tests should ideally involve IE9 and >(some older version of) Safari, which are rumored to have somehow >questionable reputation regarding "required" HTML attribute support. > >Signed-off-by: Valérie Bertrand <valerie.bertrand@univ-lyon3.fr> >--- > .../bootstrap/en/modules/opac-suggestions.tt | 37 ++++++++++++++++---- > opac/opac-suggestions.pl | 17 +++++++++ > 2 files changed, 47 insertions(+), 7 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 46d0031..4eb0a6f 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt >@@ -29,9 +29,14 @@ > <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> >+ [% IF (mandatoryfields) %] >+ <p>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 %] >+ <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. >+ [% END %] >+ 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" id="newsuggestionform" onsubmit="return Check(this);" method="post"> > <fieldset class="rows"> > <ol> > <li><label class="required" for="title">Title:</label><input type="text" id="title" name="title" class="span6" maxlength="255" /></li> >@@ -94,7 +99,7 @@ > <fieldset class="action"> > <input type="hidden" name="suggestedby" value="[% suggestedbyme %]" /> > <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 # IF op_add %] >@@ -304,23 +309,41 @@ > return true; > }); > [% END %] >+ [% IF ( op_add && mandatoryfields ) %] >+ var FldsRequired = [[% mandatoryfields %]]; >+ for (var i = 0; i < FldsRequired.length; i++) { >+ var rqinput = $('#' + FldsRequired[i]); >+ if (rqinput.length != 1) continue; >+ $(rqinput).attr("required", "required"); >+ var rqlabel = $("label[for=" + rqinput.attr("id") + "]"); >+ if (rqlabel.length != 1) continue; >+ $(rqlabel).addClass('required'); >+ } >+ [% END %] > }); > > function Check(f) { > var _alertString=""; > var alertString2; > >- if(f.title.value.length ==0){ >- _alertString += _("- You must enter a Title") + "\n"; >+ var FieldsRequired = [[% mandatoryfields %]]; >+ FieldsRequired.unshift("title"); >+ >+ for (var i = 0; i < FieldsRequired.length; i++) { >+ var lbl = FieldsRequired[i]; >+ if (!f[lbl] || (f[lbl].value.length != 0)) continue; >+ _alertString += _("- Some mandatory fields are missing") + "\n"; >+ break; > } > >- if (_alertString.length==0) { >- f.submit(); >+ if (_alertString.length == 0) { >+ return true; > } else { > alertString2 = _("Form not submitted because of the following problem(s)"); > alertString2 += "\n------------------------------------------------------------------------------------\n\n"; > alertString2 += _alertString; > alert(alertString2); >+ return false; > } > } > //]]> >diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl >index 2d89d93..770dd46 100755 >--- a/opac/opac-suggestions.pl >+++ b/opac/opac-suggestions.pl >@@ -156,6 +156,22 @@ if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) { > $template->param( branchloop => $branchloop ); > } > >+my $mandatoryfields = ''; >+{ >+ my $fldsreqsp = C4::Context->preference("OPACSuggestionMandatoryFields"); >+ last unless ($op eq 'add' && $fldsreqsp); >+ my $supported_rf = { >+ map { ($_, 1); } qw( >+ author copyrightdate isbn publishercode collectiontitle >+ place itemtype patronreason note >+ ) >+ }; >+ my %fh = map { >+ ($_ && $supported_rf->{$_})? ('"'.$_.'"', 1): (); >+ } (split(/\s*\|\s*/, $fldsreqsp)); >+ $mandatoryfields = join(',', (sort keys %fh)); >+} >+ > $template->param( > %$suggestion, > itemtypeloop=> $supportlist, >@@ -164,6 +180,7 @@ $template->param( > showall => $allsuggestions, > "op_$op" => 1, > suggestionsview => 1, >+ mandatoryfields => $mandatoryfields, > ); > > output_html_with_http_headers $input, $cookie, $template->output; >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10848
:
28721
|
28722
|
28792
|
29091
|
29092
|
34317
|
34318
|
34319
|
34324
|
34325
|
34326
|
34544
|
34545
|
34546
|
34547
|
35830
|
54016
|
54017
|
54018
|
54019
|
54020
|
54021
|
54083
|
54084
|
54356
|
54430
|
54431
|
54432