[open-ils-commits] [GIT] Evergreen ILS branch rel_2_12 updated. f2538c6bd0dd14579a985d20025c81c2120c8f59
Evergreen Git
git at git.evergreen-ils.org
Wed Aug 9 09:45:27 EDT 2017
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".
The branch, rel_2_12 has been updated
via f2538c6bd0dd14579a985d20025c81c2120c8f59 (commit)
from 938bff33e66717babb6ad2861d3dac3e8e22aa45 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit f2538c6bd0dd14579a985d20025c81c2120c8f59
Author: Cesar Velez <cesar.velez at equinoxinitiative.org>
Date: Tue May 23 16:36:44 2017 -0400
LP#1098685: Require OPAC patron holds w/ phone/SMS notification to enter that info
This provides some plain vanilla JS form validation, and error feedback
using a yellow background color on the culprit input field.
Signed-off by: Cesar Velez <cesar.velez at equinoxinitiative.org>
Signed-off-by: Chris Sharp <csharp at georgialibraries.org>
Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>
Conflicts:
Open-ILS/src/templates/opac/parts/js.tt2
diff --git a/Open-ILS/src/templates/opac/parts/js.tt2 b/Open-ILS/src/templates/opac/parts/js.tt2
index 4d5b400..2e878c7 100644
--- a/Open-ILS/src/templates/opac/parts/js.tt2
+++ b/Open-ILS/src/templates/opac/parts/js.tt2
@@ -59,6 +59,13 @@
IF CGI.https; url = url.replace('^http:', 'https:'); END; %]
<script type='text/javascript' id='EIT' src='[% url %]'></script>
[%- END %]
+
+<!-- Require some inputs and selections for browsers that don't support required form field element -->
+[% IF ctx.page == 'place_hold' %]
+ <script type="text/javascript" src="[% ctx.media_prefix %]/js/ui/default/opac/holds-validation.js">
+ </script>
+[% END %]
+
[%- IF want_dojo; -%]
<script type="text/javascript">
var djConfig = {
@@ -128,29 +135,5 @@ var aou_hash = {
};
</script>
-<!-- Require radio parts selection for browsers that don't support required form field element -->
-[% IF ctx.page == 'place_hold' %]
- <script type="text/javascript">
- function validateRadioSelection (radios) {
- for (i = 0; i < radios.length; ++ i)
- {
- if (radios[i].checked) return true;
- }
- return false;
- }
- function validateHoldForm() {
- if (validateRadioSelection (document.getElementsByName("part")))
- {
- return true;
- }
- else
- {
- alert ("Please select a part");
- return false;
- }
- }
- </script>
-[% END %]
-
<script type="text/javascript">if ($('client_tz_id')) { $('client_tz_id').value = OpenSRF.tz }</script>
[%- END; # want_dojo -%]
diff --git a/Open-ILS/src/templates/opac/parts/place_hold.tt2 b/Open-ILS/src/templates/opac/parts/place_hold.tt2
index 8bf1713..9ca96f9 100644
--- a/Open-ILS/src/templates/opac/parts/place_hold.tt2
+++ b/Open-ILS/src/templates/opac/parts/place_hold.tt2
@@ -23,7 +23,7 @@
ELSE; some_holds_allowed = 1; END;
END %]
- <form method="post" name="PlaceHold" [% IF hdata.parts.size > 0 AND enable.radio.parts == 'true' %] onsubmit="return validateHoldForm()" [% END %] >
+ <form method="post" name="PlaceHold" onsubmit="return validateHoldForm()" >
<input type="hidden" name="hold_type" value="[% CGI.param('hold_type') | html %]" />
[%
redirect = CGI.param('hold_source_page') || CGI.param('redirect_to') || CGI.referer;
@@ -175,7 +175,7 @@
<p>
[% l('Notify when hold is ready for pickup?') %]
<blockquote>
- <input type="checkbox" id="email_notify" name="email_notify" value="t"
+ <input class="hold-alert-method" type="checkbox" id="email_notify" name="email_notify" value="t"
[% IF !ctx.user.email %]disabled="true"[% ELSIF ctx.default_email_notify %]checked="checked"[% END %]/>
<label for="email_notify">[% l('Yes, by Email') %]</label><br/>
<blockquote>
@@ -183,7 +183,7 @@
ELSE; l('Email Address:') %] <span name="email_address">[% ctx.user.email %]</span>[% END %]
</blockquote>
[%- IF allow_phone_notifications == 'true' %]
- <input type="checkbox" id="phone_notify_checkbox" name="phone_notify_checkbox"
+ <input class="hold-alert-method" type="checkbox" id="phone_notify_checkbox" name="phone_notify_checkbox"
[% IF ctx.default_phone_notify %]checked="checked"[% END %]/>
<label for="phone_notify_checkbox">[% l('Yes, by Phone') %]</label><br/>
<blockquote>
@@ -193,7 +193,7 @@
</blockquote>
[%- END -%]
[% IF ctx.get_org_setting(ctx.search_ou, 'sms.enable') == 1 %]
- <input type="checkbox" id="sms_notify_checkbox" name="sms_notify_checkbox"
+ <input class="hold-alert-method" type="checkbox" id="sms_notify_checkbox" name="sms_notify_checkbox"
[% IF ctx.default_sms_notify %]checked="checked"[% END %]/>
<label for="sms_notify_checkbox">[% l('Yes, by Text Messaging') %]</label><br/>
<blockquote>
diff --git a/Open-ILS/web/js/ui/default/opac/holds-validation.js b/Open-ILS/web/js/ui/default/opac/holds-validation.js
new file mode 100644
index 0000000..842366c
--- /dev/null
+++ b/Open-ILS/web/js/ui/default/opac/holds-validation.js
@@ -0,0 +1,76 @@
+/* JS form validation for holds page alert methods */
+function resetBackgrounds(names){
+ for (var key in names) {
+ if (names.hasOwnProperty(key)) {
+ var l = document.getElementsByName(names[key]);
+ if (l.length > 0) {
+ l[0].style.backgroundColor = "";
+ }
+ }
+ }
+}
+
+function validateMethodSelections (alertMethodCboxes) {
+ var needsPhone = false;
+ var hasPhone = false;
+
+ var needsEmail = false;
+ var hasEmail = false;
+
+ var needsSms = false;
+ var hasSms = false;
+ var inputNames = { e: "email_address", ph: "phone_notify", sms: "sms_notify", carrier: "sms_carrier"};
+ resetBackgrounds(inputNames);
+
+ //Array.from(alertMethodCboxes).forEach(function(cbox){
+ for (var i = 0; i < alertMethodCboxes.length; i++){
+ var cbox = alertMethodCboxes[i];
+ if (cbox.checked && !cbox.disabled) {
+ switch(cbox.id){
+ case "email_notify_checkbox":
+ needsEmail = true;
+ hasEmail = document.getElementsByName(inputNames.e)[0].innerHTML !== "";
+ break;
+ case "phone_notify_checkbox":
+ needsPhone = true;
+ hasPhone = document.getElementsByName(inputNames.ph)[0].value !== "";
+ break;
+ case "sms_notify_checkbox":
+ needsSms = true;
+ var smsNumInput = document.getElementsByName(inputNames.sms)[0];
+ hasSms = document.getElementsByName(inputNames.carrier)[0].value !== "" && smsNumInput.value !== ""; // todo: properly validate phone nums
+ break;
+ }
+ }
+ }
+
+ var culprits = [];
+ var emailOK = (needsEmail && hasEmail) || (!needsEmail);
+ var phoneOK = needsPhone && hasPhone || (!needsPhone);
+ var smsOK = needsSms && hasSms || (!needsSms);
+
+ if (!phoneOK) {
+ culprits.push("phone_notify");
+ }
+ if (!smsOK) {
+ culprits.push("sms_notify", "sms_carrier");
+ }
+
+ var isFormOK = emailOK && phoneOK && smsOK;
+ return { isValid: isFormOK, culpritNames : culprits };
+}
+
+function validateHoldForm() {
+ var res = validateMethodSelections(document.getElementsByClassName("hold-alert-method"));
+ if (res.isValid)
+ {
+ return true;
+ } else {
+ alert ("Please complete hold notification method info.");
+ res.culpritNames.forEach(function(n){
+ document.getElementsByName(n)[0].style.backgroundColor = "yellow";
+ });
+ return false;
+ }
+}
+
-----------------------------------------------------------------------
Summary of changes:
Open-ILS/src/templates/opac/parts/js.tt2 | 31 ++------
Open-ILS/src/templates/opac/parts/place_hold.tt2 | 8 +-
.../web/js/ui/default/opac/holds-validation.js | 76 ++++++++++++++++++++
3 files changed, 87 insertions(+), 28 deletions(-)
create mode 100644 Open-ILS/web/js/ui/default/opac/holds-validation.js
hooks/post-receive
--
Evergreen ILS
More information about the open-ils-commits
mailing list