2016-03-29 11:40:44 +03:00
|
|
|
import BaseValidator from './base';
|
2019-01-22 16:09:38 +03:00
|
|
|
import validator from 'validator';
|
2017-11-16 15:36:17 +03:00
|
|
|
import {isBlank} from '@ember/utils';
|
2016-03-29 11:40:44 +03:00
|
|
|
|
|
|
|
export default BaseValidator.create({
|
|
|
|
properties: ['url'],
|
|
|
|
|
|
|
|
url(model) {
|
|
|
|
let url = model.get('url');
|
|
|
|
let hasValidated = model.get('hasValidated');
|
|
|
|
|
2017-11-16 15:36:17 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
if (!isBlank(url) && !validator.isURL(url, {require_protocol: true})) {
|
2016-03-29 11:40:44 +03:00
|
|
|
model.get('errors').add(
|
|
|
|
'url',
|
2016-11-14 16:16:51 +03:00
|
|
|
'The URL must be in a format like https://hooks.slack.com/services/<your personal key>'
|
2016-03-29 11:40:44 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
hasValidated.addObject('url');
|
|
|
|
}
|
|
|
|
});
|