From f733efba5a72b58703fc80a5c87faafa343b1633 Mon Sep 17 00:00:00 2001 From: jloveland Date: Sun, 13 Sep 2015 16:32:22 -0400 Subject: [PATCH] renaming strength meter, hiding when password field is empty, and refactoring directives to use $validators --- .../password-validator.client.directive.js | 57 ++++++++++--------- .../password-verify.client.directive.js | 21 +++---- .../authentication/signup.client.view.html | 8 +-- .../password/reset-password.client.view.html | 8 +-- .../settings/change-password.client.view.html | 8 +-- 5 files changed, 49 insertions(+), 53 deletions(-) diff --git a/modules/users/client/directives/password-validator.client.directive.js b/modules/users/client/directives/password-validator.client.directive.js index a0ef1eaa95..535e534eec 100644 --- a/modules/users/client/directives/password-validator.client.directive.js +++ b/modules/users/client/directives/password-validator.client.directive.js @@ -4,39 +4,40 @@ angular.module('users') .directive('passwordValidator', ['PasswordValidator', function(PasswordValidator) { return { require: 'ngModel', - link: function(scope, element, attrs, modelCtrl) { - modelCtrl.$parsers.unshift(function (password) { - var result = PasswordValidator.getResult(password); - var strengthIdx = 0; + link: function(scope, element, attrs, ngModel) { + ngModel.$validators.requirements = function (password) { + var status = true; + if (password) { + var result = PasswordValidator.getResult(password); + var requirementsIdx = 0; - // Strength Meter - visual indicator for users - var strengthMeter = [ - { color: 'danger', progress: '20' }, - { color: 'warning', progress: '40' }, - { color: 'info', progress: '60' }, - { color: 'primary', progress: '80' }, - { color: 'success', progress: '100' } - ]; - var strengthMax = strengthMeter.length; + // requirements Meter - visual indicator for users + var requirementsMeter = [ + { color: 'danger', progress: '20' }, + { color: 'warning', progress: '40' }, + { color: 'info', progress: '60' }, + { color: 'primary', progress: '80' }, + { color: 'success', progress: '100' } + ]; - if (result.errors.length < strengthMeter.length) { - strengthIdx = strengthMeter.length - result.errors.length - 1; - } + if (result.errors.length < requirementsMeter.length) { + requirementsIdx = requirementsMeter.length - result.errors.length - 1; + } - scope.strengthColor = strengthMeter[strengthIdx].color; - scope.strengthProgress = strengthMeter[strengthIdx].progress; + scope.requirementsColor = requirementsMeter[requirementsIdx].color; + scope.requirementsProgress = requirementsMeter[requirementsIdx].progress; - if (result.errors.length) { - scope.popoverMsg = PasswordValidator.getPopoverMsg(); - scope.passwordErrors = result.errors; - modelCtrl.$setValidity('strength', false); - return undefined; - } else { - scope.popoverMsg = ''; - modelCtrl.$setValidity('strength', true); - return password; + if (result.errors.length) { + scope.popoverMsg = PasswordValidator.getPopoverMsg(); + scope.passwordErrors = result.errors; + status = false; + } else { + scope.popoverMsg = ''; + status = true; + } } - }); + return status; + }; } }; }]); diff --git a/modules/users/client/directives/password-verify.client.directive.js b/modules/users/client/directives/password-verify.client.directive.js index e31565dbde..acb876899e 100644 --- a/modules/users/client/directives/password-verify.client.directive.js +++ b/modules/users/client/directives/password-verify.client.directive.js @@ -7,27 +7,22 @@ angular.module('users') scope: { passwordVerify: '=' }, - link: function(scope, element, attrs, modelCtrl) { + link: function(scope, element, attrs, ngModel) { + var status = true; scope.$watch(function() { var combined; - if (scope.passwordVerify || modelCtrl.$viewValue) { - combined = scope.passwordVerify + '_' + modelCtrl.$viewValue; + if (scope.passwordVerify || ngModel) { + combined = scope.passwordVerify + '_' + ngModel; } return combined; }, function(value) { if (value) { - modelCtrl.$parsers.unshift(function(viewValue) { + ngModel.$validators.passwordVerify = function (password) { var origin = scope.passwordVerify; - if (origin !== viewValue) { - modelCtrl.$setValidity('passwordVerify', false); - return undefined; - } else { - modelCtrl.$setValidity('passwordVerify', true); - return viewValue; - } - }); + return (origin !== password) ? false : true; + }; } }); - } + } }; }); diff --git a/modules/users/client/views/authentication/signup.client.view.html b/modules/users/client/views/authentication/signup.client.view.html index 65fbb4bb5c..7093ff1392 100644 --- a/modules/users/client/views/authentication/signup.client.view.html +++ b/modules/users/client/views/authentication/signup.client.view.html @@ -38,13 +38,13 @@

Or sign up using your email

Password is required.

-

{{passwordError}}

+

{{passwordError}}

-
- - {{strengthProgress}}% +
+ + {{requirementsProgress}}%
diff --git a/modules/users/client/views/password/reset-password.client.view.html b/modules/users/client/views/password/reset-password.client.view.html index f0189ad681..e87f5c956b 100644 --- a/modules/users/client/views/password/reset-password.client.view.html +++ b/modules/users/client/views/password/reset-password.client.view.html @@ -9,7 +9,7 @@

Reset your password

Enter a new password.

-

{{passwordError}}

+

{{passwordError}}

@@ -21,9 +21,9 @@

Reset your password

Passwords do not match.

-
- - {{strengthProgress}}% +
+ + {{requirementsProgress}}%
diff --git a/modules/users/client/views/settings/change-password.client.view.html b/modules/users/client/views/settings/change-password.client.view.html index 01df17dd38..1537075575 100644 --- a/modules/users/client/views/settings/change-password.client.view.html +++ b/modules/users/client/views/settings/change-password.client.view.html @@ -15,7 +15,7 @@

Enter a new password.

-

{{passwordError}}

+

{{passwordError}}

@@ -27,9 +27,9 @@

Passwords do not match.

-
- - {{strengthProgress}}% +
+ + {{requirementsProgress}}%