mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
3f361f8742
no issue - drops the `var Foo = Ember.Thing.extend({}); export default Foo;` syntax in favour of exporting directly, eg: `export default Ember.Thing.extend({})` - discussion on this change [here](https://github.com/TryGhost/Ghost/pull/5340#issuecomment-105828423) and [here](https://github.com/TryGhost/Ghost/pull/5694#discussion-diff-37511606)
39 lines
1.1 KiB
JavaScript
39 lines
1.1 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: function (model, prop) {
|
|
var self = this;
|
|
|
|
this.set('passed', true);
|
|
|
|
if (prop && this[prop]) {
|
|
this[prop](model);
|
|
} else {
|
|
this.get('properties').forEach(function (property) {
|
|
if (self[property]) {
|
|
self[property](model);
|
|
}
|
|
});
|
|
}
|
|
return this.get('passed');
|
|
},
|
|
invalidate: function () {
|
|
this.set('passed', false);
|
|
}
|
|
});
|