2015-06-07 06:19:19 +03:00
|
|
|
import BaseValidator from './base';
|
2014-07-11 23:01:42 +04:00
|
|
|
|
2015-08-19 14:55:40 +03:00
|
|
|
export default BaseValidator.create({
|
2015-06-07 06:19:19 +03:00
|
|
|
properties: ['name', 'bio', 'email', 'location', 'website', 'roles'],
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
isActive(model) {
|
2015-06-07 06:19:19 +03:00
|
|
|
return (model.get('status') === 'active');
|
2014-07-11 23:01:42 +04:00
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
name(model) {
|
|
|
|
let name = model.get('name');
|
2014-07-11 23:01:42 +04:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
if (this.isActive(model)) {
|
2015-07-07 20:14:23 +03:00
|
|
|
if (validator.empty(name)) {
|
|
|
|
model.get('errors').add('name', 'Please enter a name.');
|
|
|
|
this.invalidate();
|
|
|
|
} else if (!validator.isLength(name, 0, 150)) {
|
2015-06-07 06:19:19 +03:00
|
|
|
model.get('errors').add('name', 'Name is too long');
|
|
|
|
this.invalidate();
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
}
|
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
bio(model) {
|
|
|
|
let bio = model.get('bio');
|
2014-07-11 23:01:42 +04:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
if (this.isActive(model)) {
|
2014-07-11 23:01:42 +04:00
|
|
|
if (!validator.isLength(bio, 0, 200)) {
|
2015-06-07 06:19:19 +03:00
|
|
|
model.get('errors').add('bio', 'Bio is too long');
|
|
|
|
this.invalidate();
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
}
|
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
email(model) {
|
|
|
|
let email = model.get('email');
|
2014-07-11 23:01:42 +04:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
if (!validator.isEmail(email)) {
|
|
|
|
model.get('errors').add('email', 'Please supply a valid email address');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
location(model) {
|
|
|
|
let location = model.get('location');
|
2014-07-11 23:01:42 +04:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
if (this.isActive(model)) {
|
2014-07-11 23:01:42 +04:00
|
|
|
if (!validator.isLength(location, 0, 150)) {
|
2015-06-07 06:19:19 +03:00
|
|
|
model.get('errors').add('location', 'Location is too long');
|
|
|
|
this.invalidate();
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
}
|
|
|
|
},
|
2014-07-11 23:01:42 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
website(model) {
|
|
|
|
let website = model.get('website');
|
|
|
|
|
|
|
|
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
|
2015-06-07 06:19:19 +03:00
|
|
|
if (this.isActive(model)) {
|
2015-10-28 14:36:45 +03:00
|
|
|
if (!validator.empty(website) &&
|
2014-11-17 07:35:32 +03:00
|
|
|
(!validator.isURL(website, {require_protocol: false}) ||
|
2014-07-14 20:32:55 +04:00
|
|
|
!validator.isLength(website, 0, 2000))) {
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
model.get('errors').add('website', 'Website is not a valid url');
|
|
|
|
this.invalidate();
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
}
|
2015-10-28 14:36:45 +03:00
|
|
|
/* jscs:enable requireCamelCaseOrUpperCaseIdentifiers */
|
2015-06-07 06:19:19 +03:00
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
roles(model) {
|
2015-06-07 06:19:19 +03:00
|
|
|
if (!this.isActive(model)) {
|
2015-10-28 14:36:45 +03:00
|
|
|
let roles = model.get('roles');
|
2014-07-14 20:32:55 +04:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
if (roles.length < 1) {
|
|
|
|
model.get('errors').add('role', 'Please select a role');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|