mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 03:44:29 +03:00
2f4f6db133
no issue - add ember-suave dependency - upgrade grunt-jscs dependency - add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc - separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc - standardize es6 usage across client
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
import Ember from 'ember';
|
|
|
|
/**
|
|
* Base validator that all validators should extend
|
|
* Handles checking of individual properties or the entire model
|
|
*/
|
|
export default Ember.Object.extend({
|
|
properties: [],
|
|
passed: false,
|
|
|
|
/**
|
|
* When passed a model and (optionally) a property name,
|
|
* checks it against a list of validation functions
|
|
* @param {Ember.Object} model Model to validate
|
|
* @param {string} prop Property name to check
|
|
* @return {boolean} True if the model passed all (or one) validation(s),
|
|
* false if not
|
|
*/
|
|
check(model, prop) {
|
|
this.set('passed', true);
|
|
|
|
if (prop && this[prop]) {
|
|
this[prop](model);
|
|
} else {
|
|
this.get('properties').forEach((property) => {
|
|
if (this[property]) {
|
|
this[property](model);
|
|
}
|
|
});
|
|
}
|
|
return this.get('passed');
|
|
},
|
|
|
|
invalidate() {
|
|
this.set('passed', false);
|
|
}
|
|
});
|