(function() { "use strict"; angular .module("agora.plus.formComponent") .directive("passwordFormComp", passwordFormComp) .directive("apPassword", apPassword); passwordFormComp.$inject = ["constant"]; function passwordFormComp(constant) { return { restrict: "E", link: linking, scope: {}, require: ["^form","ngModel"], replace: true, templateUrl:PCK_GLOBAL_VARIABLES.password_form_comp } linking.$inject = ["scope", "elem", "attrs", "ctrls"]; function linking(scope, elem, attrs, ctrls) { scope.imgPath = constant.imgPath; scope.form = ctrls[0]; scope.ngModel = ctrls[1]; if (typeof(attrs.required) !== "undefined") { scope.required = true; } scope.$watch("password.new.password",function (newValue,oldValue,scope) { if (scope.password) { if (scope.password.confirm && (scope.password.confirm.password !== newValue)) { scope.$broadcast("mismatch", {mismatch: true}); scope.ngModel.$setViewValue(null); } else if (scope.password.confirm && (scope.password.confirm.password === newValue) /*&& scope.password.new.complexity*/) { scope.$broadcast("mismatch", {mismatch: false}); scope.ngModel.$setViewValue(scope.password.new.password); } } }); scope.$watch("password.confirm.password",function (newValue,oldValue,scope) { if (scope.password) { if (scope.password.new && (scope.password.new.password !== newValue)) { scope.$broadcast("mismatch", {mismatch: true}); scope.ngModel.$setViewValue(null); } else if (scope.password.new && (scope.password.new.password === newValue) /*&& scope.password.confirm.complexity*/) { scope.$broadcast("mismatch", {mismatch: false}); scope.ngModel.$setViewValue(scope.password.new.password); } } }); /*scope.$on("complexity", function (ev, data) { if (scope.password) { if (scope.password.new && data.sender === "password") { scope.password.new.complexity = data.complexity; } else if (scope.password.confirm && data.sender === "password2") { scope.password.confirm.complexity = data.complexity; } } });*/ } } function apPassword() { return { restrict: "A", require: ["^form","^ngModel"], scope: {}, link: linking } linking.$inject = ["scope", "elem", "attrs", "ctrl"]; function linking(scope, elem, attrs, ctrl) { if (attrs.name === "password2") { scope.$on("mismatch", function (e,data) { if (data.mismatch) { ctrl[1].$setValidity("mismatch", false); } else { ctrl[1].$setValidity("mismatch", true); } }); } scope.$on("setRequired", function () { ctrl[1].$touched = true; }); /*ctrl[1].$parsers.unshift(function(password) { var hasNumbers = /\d/.test(password); var hasLowerCase = /[a-z]/.test(password); var hasUpperCase = /[A-Z]/.test(password); var hasNonalphas = false;//\W/.test(password); var characterGroupCount = hasUpperCase + hasLowerCase + hasNumbers + hasNonalphas; if ((password.length >= 8) && (characterGroupCount >= 3)) { if (ctrl[1].$error.complexity) { scope.$emit("complexity", {sender: ctrl[1].$name, complexity: true}); } ctrl[1].$setValidity("complexity", true); } else { if (!ctrl[1].$error.complexity) { scope.$emit("complexity", {sender: ctrl[1].$name, complexity: false}); } ctrl[1].$setValidity("complexity", false); } return password; });*/ } } }());