You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/ui/javascripts/libs/ember-validations.min.js

2 lines
15 KiB

// Copyright: Copyright 2013 DockYard, LLC. and contributors.
!function(){Ember.Validations=Ember.Namespace.create({VERSION:"1.0.0.beta.2"})}(),function(){Ember.Validations.messages={render:function(t,s){if(Ember.I18n)return Ember.I18n.t("errors."+t,s);var i=new RegExp("{{(.*?)}}"),e="";return i.test(this.defaults[t])&&(e=i.exec(this.defaults[t])[1]),this.defaults[t].replace(i,s[e])},defaults:{inclusion:"is not included in the list",exclusion:"is reserved",invalid:"is invalid",confirmation:"doesn't match {{attribute}}",accepted:"must be accepted",empty:"can't be empty",blank:"can't be blank",present:"must be blank",tooLong:"is too long (maximum is {{count}} characters)",tooShort:"is too short (minimum is {{count}} characters)",wrongLength:"is the wrong length (should be {{count}} characters)",notANumber:"is not a number",notAnInteger:"must be an integer",greaterThan:"must be greater than {{count}}",greaterThanOrEqualTo:"must be greater than or equal to {{count}}",equalTo:"must be equal to {{count}}",lessThan:"must be less than {{count}}",lessThanOrEqualTo:"must be less than or equal to {{count}}",otherThan:"must be other than {{count}}",odd:"must be odd",even:"must be even",url:"is not a valid URL"}}}(),function(){Ember.Validations.Errors=Ember.Object.extend({unknownProperty:function(t){return this.set(t,Ember.makeArray()),this.get(t)}})}(),function(){var t=Ember.Mixin.create({isValid:function(){return 0===this.get("validators").compact().filterBy("isValid",!1).get("length")}.property("validators.@each.isValid"),isInvalid:Ember.computed.not("isValid")}),s=function(t,i){var o=t.get(i);t.removeObserver(i,s),t.validators.pushObject(Ember.isArray(o)?e.create({model:t,property:i,contentBinding:"model."+i}):o)},i=function(t){var s=t.classify();return Ember.Validations.validators.local[s]||Ember.Validations.validators.remote[s]},e=Ember.ArrayProxy.extend(t,{validate:function(){return this._validate()},_validate:function(){var t=this.get("content").invoke("_validate").without(void 0);return Ember.RSVP.all(t)}.on("init"),validators:Ember.computed.alias("content")});Ember.Validations.Mixin=Ember.Mixin.create(t,{init:function(){this._super(),this.errors=Ember.Validations.Errors.create(),this._dependentValidationKeys={},this.validators=Ember.makeArray(),void 0===this.get("validations")&&(this.validations={}),this.buildValidators(),this.validators.forEach(function(t){t.addObserver("errors.[]",this,function(t){var s=Ember.makeArray();this.validators.forEach(function(i){i.property===t.property&&(s=s.concat(i.errors))},this),this.set("errors."+t.property,s)})},this)},buildValidators:function(){var t;for(t in this.validations)this.validations[t].constructor===Object?this.buildRuleValidator(t):this.buildObjectValidator(t)},buildRuleValidator:function(t){var s;for(s in this.validations[t])this.validations[t].hasOwnProperty(s)&&this.validators.pushObject(i(s).create({model:this,property:t,options:this.validations[t][s]}))},buildObjectValidator:function(t){Ember.isNone(this.get(t))?this.addObserver(t,this,s):s(this,t)},validate:function(){var t=this;return this._validate().then(function(s){var i=t.get("errors");return s.contains(!1)?Ember.RSVP.reject(i):i})},_validate:function(){var t=this.validators.invoke("_validate").without(void 0);return Ember.RSVP.all(t)}.on("init")})}(),function(){Ember.Validations.patterns=Ember.Namespace.create({numericality:/^(-|\+)?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d*)?$/,blank:/^\s*$/})}(),function(){Ember.Validations.validators=Ember.Namespace.create(),Ember.Validations.validators.local=Ember.Namespace.create(),Ember.Validations.validators.remote=Ember.Namespace.create()}(),function(){Ember.Validations.validators.Base=Ember.Object.extend({init:function(){this.set("errors",Ember.makeArray()),this._dependentValidationKeys=Ember.makeArray(),this.conditionals={"if":this.get("options.if"),unless:this.get("options.unless")},this.model.addObserver(this.property,this,this._validate)},addObserversForDependentValidationKeys:function(){this._dependentValidationKeys.forEach(function(t){this.model.addObserver(t,this,this._validate)},this)}.on("init"),pushDependentValidationKeyToModel:fu