let label = model.get('label'); let hasValidated = model.get('hasValidated'); if (isBlank(label)) { model.get('errors').add('label', 'You must specify a label'); this.invalidate(); } hasValidated.addObject('label'); }, url(model) { let url = model.get('url'); let hasValidated = model.get('hasValidated'); /* eslint-disable camelcase */ let validatorOptions = {require_protocol: true}; /* eslint-enable camelcase */ let urlRegex = new RegExp(/^(\/|#|[a-zA-Z0-9-]+:)/); if (isBlank(url)) { model.get('errors').add('url', 'You must specify a URL or relative path'); this.invalidate(); } else if (url.match(/\s/) || (!validator.isURL(url, validatorOptions) && !url.match(urlRegex))) { model.get('errors').add('url', 'You must specify a valid URL or relative path'); this.invalidate(); } hasValidated.addObject('url'); } });
if (images.length > 0) { event.preventDefault(); event.stopImmediatePropagation(); editor.run((postEditor) => { insertImageCards(images, postEditor); }); return; } let range = editor.range; let {html, text} = getContentFromPasteEvent(event); // if a URL is pasted and we have a selection, make that selection a link if (range && !range.isCollapsed && range.headSection === range.tailSection && range.headSection.isMarkerable) { if (text && validator.isURL(text)) { let linkMarkup = editor.builder.createMarkup('a', {href: text}); editor.run((postEditor) => { postEditor.addMarkupToRange(range, linkMarkup); }); editor.selectRange(range.tail); // prevent mobiledoc's default paste event handler firing event.preventDefault(); event.stopImmediatePropagation(); return; } } // if plain text is pasted we run it through our markdown parser so that // we get better output than mobiledoc's default text parsing and we can // provide an easier MD->Mobiledoc conversion route
location(model) { let location = model.get('location'); if (this.isActive(model)) { if (!validator.isLength(location || '', 0, 150)) { model.get('errors').add('location', 'Location is too long'); this.invalidate(); } } }, website(model) { let website = model.get('website'); // eslint-disable-next-line camelcase let isInvalidWebsite = !validator.isURL(website || '', {require_protocol: false}) || !validator.isLength(website || '', 0, 2000); if (this.isActive(model)) { if (!isBlank(website) && isInvalidWebsite) { model.get('errors').add('website', 'Website is not a valid url'); this.invalidate(); } } }, roles(model) { if (!this.isActive(model)) { let roles = model.get('roles'); if (roles.length < 1) {