2015-06-07 06:19:19 +03:00
|
|
|
import BaseValidator from './base';
|
2019-01-22 16:09:38 +03:00
|
|
|
import validator from 'validator';
|
2022-05-16 13:38:32 +03:00
|
|
|
import {isBlank} from '@ember/utils';
|
2015-06-07 06:19:19 +03:00
|
|
|
|
2015-08-19 14:55:40 +03:00
|
|
|
export default BaseValidator.create({
|
2022-05-16 13:38:32 +03:00
|
|
|
properties: ['title', 'description', 'password', 'slackUrl'],
|
2015-10-28 14:36:45 +03:00
|
|
|
title(model) {
|
|
|
|
let title = model.get('title');
|
2014-06-24 10:33:24 +04:00
|
|
|
|
2018-03-19 20:56:09 +03: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
|
|
|
|
2018-03-19 20:56:09 +03:00
|
|
|
if (!validator.isLength(desc || '', 0, 200)) {
|
2015-06-07 06:19:19 +03:00
|
|
|
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');
|
2022-05-16 13:38:32 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
slackUrl(model) {
|
|
|
|
let slackUrl = model.get('slackUrl');
|
|
|
|
|
|
|
|
if (!isBlank(slackUrl) && !validator.isURL(slackUrl, {require_protocol: true})) {
|
|
|
|
model.get('errors').add(
|
|
|
|
'slackUrl',
|
|
|
|
'The URL must be in a format like https://hooks.slack.com/services/<your personal key>'
|
|
|
|
);
|
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
this.invalidate();
|
2015-05-11 18:35:55 +03:00
|
|
|
}
|
2014-06-24 10:33:24 +04:00
|
|
|
}
|
|
|
|
});
|