2015-06-07 06:19:19 +03:00
|
|
|
import BaseValidator from './base';
|
|
|
|
|
2015-08-19 14:55:40 +03:00
|
|
|
export default BaseValidator.create({
|
2017-03-14 20:09:06 +03:00
|
|
|
properties: ['title', 'description', 'password'],
|
2015-10-28 14:36:45 +03:00
|
|
|
title(model) {
|
|
|
|
let title = model.get('title');
|
2014-06-24 10:33:24 +04:00
|
|
|
|
|
|
|
if (!validator.isLength(title, 0, 150)) {
|
2015-06-07 06:19:19 +03:00
|
|
|
model.get('errors').add('title', 'Title is too long');
|
|
|
|
this.invalidate();
|
2014-06-24 10:33:24 +04:00
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
description(model) {
|
|
|
|
let desc = model.get('description');
|
2014-06-24 10:33:24 +04:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
if (!validator.isLength(desc, 0, 200)) {
|
|
|
|
model.get('errors').add('description', 'Description is too long');
|
|
|
|
this.invalidate();
|
2014-06-24 10:33:24 +04:00
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
password(model) {
|
|
|
|
let isPrivate = model.get('isPrivate');
|
|
|
|
let password = model.get('password');
|
2014-06-24 10:33:24 +04:00
|
|
|
|
2015-05-11 18:35:55 +03:00
|
|
|
if (isPrivate && password === '') {
|
2015-06-07 06:19:19 +03:00
|
|
|
model.get('errors').add('password', 'Password must be supplied');
|
|
|
|
this.invalidate();
|
2015-05-11 18:35:55 +03:00
|
|
|
}
|
2014-06-24 10:33:24 +04:00
|
|
|
}
|
|
|
|
});
|