forked from rkrdovrgs/angular-fluent-validation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ng-fluent-validation.min.js
4 lines (4 loc) · 6.54 KB
/
ng-fluent-validation.min.js
1
2
3
4
(function(){"use strict";function t(n,t){for(var u=t.split("."),f=u.length,i=n,r=0;r<f;r++)if(i=i[u[r]],i===undefined||i===null)return;return i}function i(){function n(n){return n&&{}.toString.call(n)==="[object Function]"}function u(n){return n==undefined||n==null||n.length==0}function f(n){return n==undefined||n==null||n==""}function e(){function s(n,t){var i,r;if(n==null||n==undefined)return!0;if(i=t.validate(n),!i.isValid)for(r=0;r<i.errors.length;r++)e.push(i.errors[r]);return i.isValid}var o=[],e=[];this.ruleFor=function(e){var a,c,h,l;return n(e)?(a=e,h=r.match(e.toString(),"return\\s([a-zA-Z_$][a-zA-Z0-9_$]*\\.?)+"),h&&(h=h.replace("return ","").trim()),h.indexOf(".")!=-1&&(h=h.substring(h.indexOf(".")+1)),c=h):(c=e,a=function(n){return t(n,c)}),l={propSelector:a,propName:c},o.push(l),{must:function(n){l.validator=n;var t={withMessage:function(n){l.message=c?n.replace("{propertyName}",c):n},when:function(n){return l.condition=n,t}};return t},setValidator:function(n){return this.must(function(t,i){return s(i,n)})},setCollectionValidator:function(n){return this.must(function(t,r){return u(r)?!0:i.From(r).Count(function(t){return!s(t,n)})==0})},notNull:function(){var n=this.must(function(n,t){return t!==undefined&&t!==null&&t!==""});return n.withMessage("'{propertyName}' must not be null."),n},notEmpty:function(){var n=this.must(function(n,t){return t===undefined||t===null?!1:angular.isNumber(t)?t!=0:angular.isArray(t)?t.length>0:t.toString().trim()!=""});return n.withMessage("'{propertyName}' must not be empty."),n},notEqual:function(t){var i=this.must(function(i,r){var u=t;return n(t)&&(u=t(i)),r!==u});return n(t)||i.withMessage("'{propertyName}' must not be equal to '"+t+"'."),i},equal:function(t){var i=this.must(function(i,r){var u=t;return n(t)&&(u=t(i)),r===u});return n(t)||i.withMessage("'{propertyName}' must be equal to '"+t+"'."),i},length:function(n,t){var i=this.must(function(i,r){var u=t||(r||"").length;return!f(r)&&r.length>=n&&r.length<=u});return t==undefined?i.withMessage("'{propertyName}' must be at least "+n+" characters."):i.withMessage("'{propertyName}' must be between"+n+" and "+t+" characters."),i},lessThan:function(t){var i=this.must(function(i,r){r=parseFloat(r);var u=t;return n(t)&&(u=t(i)),r<u});return n(t)||i.withMessage("'{propertyName}' must be less than '"+t+"'."),i},lessThanOrEqual:function(t){var i=this.must(function(i,r){r=parseFloat(r);var u=t;return n(t)&&(u=t(i)),r<=u});return n(t)||i.withMessage("'{propertyName}' must be less than or equal to '"+t+"'."),i},greaterThan:function(t){var i=this.must(function(i,r){r=parseFloat(r);var u=t;return n(t)&&(u=t(i)),r>u});return n(t)||i.withMessage("'{propertyName}' must be greater than '"+t+"'."),i},greaterThanOrEqual:function(t){var i=this.must(function(i,r){r=parseFloat(r);var u=t;return n(t)&&(u=t(i)),r>=u});return n(t)||i.withMessage("'{propertyName}' must be greater than or equal to '"+t+"'."),i},matches:function(n,t){var i=this.must(function(i,u){return u==undefined||u==null||r.isMatch(u,n,t)});return i.withMessage("'{propertyName}' is not in the correct format."),i},emailAddress:function(){var t="^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$",n=this.must(function(n,i){return i!=undefined&&i!=null&&r.isMatch(i,t,"i")});return n.withMessage("'{propertyName}' is not a valid email address."),n}}};this.isValid=function(n){return this.validate(n).isValid};this.validate=function(n){e=[];var r=i.From(o).Where(function(t){var i=t.propSelector(n);return t.condition&&!t.condition(n,i)?!1:!t.validator(n,i)}).Select(function(n){return{errorMessage:n.message,propertyName:n.propName}}).ToArray(),f=u(r),t={$all:e};return angular.forEach(r,function(n){var i,u,r;if(e.push(n),n.propertyName.indexOf(".")<0)t[n.propertyName]==undefined&&(t[n.propertyName]=[]),t[n.propertyName].push(n.errorMessage);else for(i=n.propertyName.split("."),t[i[0]]==undefined&&(t[i[0]]={}),u=t[i[0]],r=1;r<i.length;r++)u[i[r]]==undefined&&r+1!=i.length&&(u[i[r]]={}),r+1==i.length&&(u[i[r]]==undefined&&(u[i[r]]=[]),u[i[r]].push(n.errorMessage)),u=u[i[r]]}),n.$errors=t,n.$isValid=f,{errors:r,isValid:f}}}var r=function(){var n=function(n,t,i){var r=new RegExp(t,i);return r.test(n)},t=function(n,t,i){var u=new RegExp(t,i),r=u.exec(n);if(r!=undefined&&r!=null)return r[0]};return{isMatch:n,match:t}}(),i={From:function(n){var t=function(t){var r=[];return angular.forEach(n,function(n,i){t(n,i)&&r.push(n)}),i.From(r)},r=function(t){var r=[];return angular.forEach(n,function(n){r.push(t(n))}),i.From(r)},u=function(t){if(t==undefined)return n.length;var i=0;return angular.forEach(n,function(n,r){t(n,r)&&i++}),i},f=function(){return n};return{Where:t,Select:r,Count:u,ToArray:f}}};return e}function r(n){function r(t,r,u,f,e){var o=i(t,r,u);return f!=undefined&&(o.prototype.$validate=function(){return f.validate(this)}),e!=undefined&&(o.$getOrCreate=function(t){var r=n.defer(),i=new e,u=parseInt(t);return u&&angular.isNumber(u)?i=o.get({id:t}):(i=new o(i),i.$promise=r.promise),r.resolve(),i}),o}var t=angular.injector(["ngResource"]),i=t.get("$resource");return r}function u(n){return{restrict:"A",scope:{ngValidationResult:"="},link:function(t,i){t.$$errorMessage=function(){var n=t.ngValidationResult;if(n)return i.addClass("has-error"),n.join("\n");i.removeClass("has-error")};var r=n(angular.element('<i class="glyphicon glyphicon-warning-sign validation-sign" ng-validation-visibility="{{ !!ngValidationResult }}"ng-show="ngValidationResult" popover="{{ $$errorMessage() }}" popover-placement="bottom" popover-animation="false" popover-trigger="mouseenter"><\/i>'))(t),u=i.find("label:first");u.size()>0?u.after(r):i.append(r)}}}function f(n){return{restrict:"A",scope:{ngValidationIcon:"="},link:function(t,i){var r=n(angular.element('<i class="glyphicon glyphicon-warning-sign validation-sign" ng-show="ngValidationIcon"><\/i>'))(t);i.append(r)}}}function e(n,t){return{restrict:"A",scope:{ngValidationErrors:"="},link:function(i,r,u){i.showIcon=!1;i.$watch("ngValidationErrors",function(){t(function(){i.showIcon=angular.element('section[ng-validation-group="'+u.ngValidationGroupIcon+'"]').find('i.validation-sign[ng-validation-visibility="true"]').size()>0})},!0);var f=n(angular.element('<i class="glyphicon glyphicon-warning-sign validation-sign" ng-show="showIcon"><\/i>'))(i);r.append(f)}}}var n=angular.module("ngFluentValidation",[]);n.factory("validator",[i]);n.factory("$resource",["$q",r]);n.directive("ngValidationResult",["$compile",u]);n.directive("ngValidationIcon",["$compile",f]);n.directive("ngValidationGroupIcon",["$compile","$timeout",e])})();
/*
//# sourceMappingURL=ng-fluent-validation.min.js.map
*/