Enable certain SMS settings -- always
authorJeff Godin <jgodin@tadl.org>
Mon, 22 Jun 2015 17:55:04 +0000 (13:55 -0400)
committerJeff Godin <jgodin@tadl.org>
Mon, 22 Jun 2015 17:55:04 +0000 (13:55 -0400)
Always enable certain SMS settings, and include some custom
validation.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/web/js/ui/default/actor/user/register.js

index 1401638..a82da9f 100644 (file)
@@ -921,9 +921,7 @@ function uEditDrawSettingRow(tbody, dividerRow, template, stype) {
         case 'opac.hold_notify':
             var template = localeStrings.HOLD_NOTIFY_PHONE + '<span name="hold_phone"></span>&nbsp;'
                 + localeStrings.HOLD_NOTIFY_EMAIL + '<span name="hold_email"></span>';
-            if(orgSettings['sms.enable']) {
-                template += '&nbsp;' + localeStrings.HOLD_NOTIFY_SMS + '<span name="hold_sms"></span>';
-            }
+            template += '&nbsp;' + localeStrings.HOLD_NOTIFY_SMS + '<span name="hold_sms"></span>';
             getByName(row, 'widget').innerHTML = template;
             var setting = userSettings['opac.hold_notify'];
             if(setting == null) setting = 'phone:email';
@@ -932,10 +930,8 @@ function uEditDrawSettingRow(tbody, dividerRow, template, stype) {
             var cb_email = new dijit.form.CheckBox({scrollOnFocus:false}, getByName(row, 'hold_email'));
             cb_email.attr('value', setting.indexOf('email') != -1);
             var cb_sms = null;
-            if(orgSettings['sms.enable']) {
-                cb_sms = new dijit.form.CheckBox({scrollOnFocus:false}, getByName(row, 'hold_sms'));
-                cb_sms.attr('value', setting.indexOf('sms') != -1);
-            }
+            cb_sms = new dijit.form.CheckBox({scrollOnFocus:false}, getByName(row, 'hold_sms'));
+            cb_sms.attr('value', setting.indexOf('sms') != -1);
             var func = function() {
                 var newVal = '';
                 var splitter = '';
@@ -947,7 +943,7 @@ function uEditDrawSettingRow(tbody, dividerRow, template, stype) {
                     newVal+= splitter + 'email';
                     splitter = ':';
                 }
-                if(orgSettings['sms.enable'] && cb_sms.checked) {
+                if(cb_sms.checked) {
                     newVal+= splitter + 'sms';
                     splitter = ':';
                 }
@@ -992,11 +988,36 @@ function uEditDrawSettingRow(tbody, dividerRow, template, stype) {
             dojo.connect(select, 'onChange', function(newVal) { userSettingsToUpdate[stype.name()] = newVal; });
             break;
         case 'opac.default_sms_notify':
-            if(!orgSettings['sms.enable']) return; // Skip when SMS is disabled
         case 'opac.default_phone':
             var tb = new dijit.form.TextBox({scrollOnFocus:false}, getByName(row, 'widget'));
             tb.attr('value', userSettings[stype.name()]);
-            dojo.connect(tb, 'onChange', function(newVal) { userSettingsToUpdate[stype.name()] = newVal; });
+            if (stype.name() === 'opac.default_sms_notify') {
+                dojo.create("div", {innerHTML: "<img id='sms_lookup_result'></img>"}, row);
+            }
+            dojo.connect(tb, 'onChange', function(newVal) {
+                if (newVal === '' || newVal.match(/\s+/)) {
+                    userSettingsToUpdate[stype.name()] = '';
+                    return;
+                }
+                var digits = newVal.replace(/\D/g, '');
+                var digits_trimmed = digits.replace(/^1/, '');
+                if (digits_trimmed.length == 10) {
+                    dojo.style(tb.domNode, "background-color", "");
+                    var formatted = digits_trimmed.replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3");
+                    tb.attr("value", formatted);
+                    if (newVal !== formatted) {
+                        newVal = formatted;
+                    } else {
+                        // only trigger this if we did NOT just change the value
+                        // (avoid double-lookup)
+                        if (stype.name() === 'opac.default_sms_notify') {
+                            dojo.byId('sms_lookup_result').src = 'https://util-ext.catalog.tadl.org/lookup_image/' + newVal + '?t=' + openils.User.authtoken;
+                        }
+                    }
+                } else {
+                    dojo.style(tb.domNode, "background-color", "yellow");
+                }
+                userSettingsToUpdate[stype.name()] = newVal; });
             break;
         default:
             var cb = new dijit.form.CheckBox({scrollOnFocus:false}, getByName(row, 'widget'));