From: Cesar Velez Date: Thu, 25 May 2017 18:34:12 +0000 (-0400) Subject: LP#1098685 html5 fix of Require OPAC patron holds phone/SMS alert info X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=26ba264c3fe4fac7bab0eb7d29a28385728fa255;p=working%2FEvergreen.git LP#1098685 html5 fix of Require OPAC patron holds phone/SMS alert info Uses HTML5 input required attrib when Modernizr says it's supported otherwise uses IE8 compatible JS. Client-side validates OPAC place hold form and highlights missing needed inputs. Signed-off by: Cesar Velez --- diff --git a/Open-ILS/src/templates/opac/css/style.css.tt2 b/Open-ILS/src/templates/opac/css/style.css.tt2 index 3daeb4985a..a299f37039 100644 --- a/Open-ILS/src/templates/opac/css/style.css.tt2 +++ b/Open-ILS/src/templates/opac/css/style.css.tt2 @@ -156,6 +156,7 @@ div.select-box-wrapper { #dash_checked, #dash_e_checked { color: [% css_colors.text_attention %]; } #dash_holds, #dash_e_holds { color: [% css_colors.text_attention %]; } #dash_pickup, #dash_e_pickup { color: [% css_colors.text_goodnews %]; } +.neededInput { background-color : [% css_colors.background_alert %]; } /* #dash_fines { color: [% css_colors.text_badnews %]; } diff --git a/Open-ILS/src/templates/opac/parts/base.tt2 b/Open-ILS/src/templates/opac/parts/base.tt2 index 8d7b07d1b9..e0cfcc6d3c 100644 --- a/Open-ILS/src/templates/opac/parts/base.tt2 +++ b/Open-ILS/src/templates/opac/parts/base.tt2 @@ -41,6 +41,7 @@ [% INCLUDE 'opac/parts/goog_analytics.tt2' %] [% END %] [% PROCESS 'opac/parts/stripe.tt2' %] +

[% l('Catalog') %]

diff --git a/Open-ILS/src/templates/opac/parts/js.tt2 b/Open-ILS/src/templates/opac/parts/js.tt2 index 845eed24c3..adec815752 100644 --- a/Open-ILS/src/templates/opac/parts/js.tt2 +++ b/Open-ILS/src/templates/opac/parts/js.tt2 @@ -132,6 +132,8 @@ var aou_hash = { [% IF ctx.page == 'place_hold' %] + + + [% END %] diff --git a/Open-ILS/src/templates/opac/parts/place_hold.tt2 b/Open-ILS/src/templates/opac/parts/place_hold.tt2 index 716b1209e6..87e2f90fbf 100644 --- a/Open-ILS/src/templates/opac/parts/place_hold.tt2 +++ b/Open-ILS/src/templates/opac/parts/place_hold.tt2 @@ -22,8 +22,7 @@ SET some_holds_allowed = 0 IF some_holds_allowed == -1; ELSE; some_holds_allowed = 1; END; END %] - -
0 AND enable.radio.parts == 'true' %] onsubmit="return validateHoldForm()" [% END %] > + [% redirect = CGI.param('hold_source_page') || CGI.param('redirect_to') || CGI.referer; 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 0000000000..1452673c18 --- /dev/null +++ b/Open-ILS/web/js/ui/default/opac/holds-validation.js @@ -0,0 +1,78 @@ +/* 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 plainJSValidate() { + //var res = validateMethodSelections(document.getElementsByClassName("hold-alert-method")); + var res = validateMethodSelections(document.querySelectorAll(".hold-alert-method")); /* IE 8 hack */ + if (res.isValid) + { + return true; + } else { + alert ("Please complete hold notification method info."); + // res.culpritNames.forEach(function(n){ /* can't do this in IE 8 grrr*/ + for (var i = 0; i < res.culpritNames.length; i++){ + document.forms["PlaceHold"].elements[res.culpritNames[i]].className = "neededInput"; + } + return false; + } +} + diff --git a/Open-ILS/web/js/ui/default/opac/modernizr.3.5.0.min.input_setclasses.js b/Open-ILS/web/js/ui/default/opac/modernizr.3.5.0.min.input_setclasses.js new file mode 100644 index 0000000000..90a3707187 --- /dev/null +++ b/Open-ILS/web/js/ui/default/opac/modernizr.3.5.0.min.input_setclasses.js @@ -0,0 +1,3 @@ +/*! modernizr 3.5.0 (Custom Build) | MIT * + * https://modernizr.com/download/?-input-setclasses !*/ +!function(e,n,t){function s(e,n){return typeof e===n}function a(){var e,n,t,a,o,i,f;for(var c in r)if(r.hasOwnProperty(c)){if(e=[],n=r[c],n.name&&(e.push(n.name.toLowerCase()),n.options&&n.options.aliases&&n.options.aliases.length))for(t=0;tt;t++)d[n[t]]=!!(n[t]in p);return d.list&&(d.list=!(!i("datalist")||!e.HTMLDataListElement)),d}(m),a(),o(l),delete f.addTest,delete f.addAsyncTest;for(var g=0;g