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) {
|
2022-10-07 22:13:42 +03:00
|
|
|
let title = model.title;
|
2014-06-24 10:33:24 +04:00
|
|
|
|
2018-03-19 20:56:09 +03:00
|
|
|
if (!validator.isLength(title || '', 0, 150)) {
|
2022-10-07 22:13:42 +03:00
|
|
|
model.errors.add('title', 'Title is too long');
|
2015-06-07 06:19:19 +03:00
|
|
|
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) {
|
2022-10-07 22:13:42 +03:00
|
|
|
let desc = model.description;
|
2014-06-24 10:33:24 +04:00
|
|
|
|
2018-03-19 20:56:09 +03:00
|
|
|
if (!validator.isLength(desc || '', 0, 200)) {
|
2022-10-07 22:13:42 +03:00
|
|
|
model.errors.add('description', 'Description is too long');
|
2015-06-07 06:19:19 +03:00
|
|
|
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) {
|
2022-10-07 22:13:42 +03:00
|
|
|
let isPrivate = model.isPrivate;
|
|
|
|
let password = model.password;
|
2014-06-24 10:33:24 +04:00
|
|
|
|
2015-05-11 18:35:55 +03:00
|
|
|
if (isPrivate && password === '') {
|
2022-10-07 22:13:42 +03:00
|
|
|
model.errors.add('password', 'Password must be supplied');
|
2022-05-16 13:38:32 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
slackUrl(model) {
|
2022-10-07 22:13:42 +03:00
|
|
|
let slackUrl = model.slackUrl;
|
2022-05-16 13:38:32 +03:00
|
|
|
|
|
|
|
if (!isBlank(slackUrl) && !validator.isURL(slackUrl, {require_protocol: true})) {
|
2022-10-07 22:13:42 +03:00
|
|
|
model.errors.add(
|
2022-05-16 13:38:32 +03:00
|
|
|
'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
|
|
|
}
|
|
|
|
});
|