Add list of posts to pools

This commit is contained in:
Ruin0x11
2020-05-04 00:09:33 -07:00
parent d59ecb8e23
commit e6bf102bc0
29 changed files with 267 additions and 117 deletions

View File

@ -22,8 +22,13 @@ class PoolCreateView extends events.EventTarget {
'input', e => this._evtNameInput(e));
}
if (this._postsFieldNode) {
this._postsFieldNode.addEventListener(
'input', e => this._evtPostsInput(e));
}
for (let node of this._formNode.querySelectorAll(
'input, select, textarea')) {
'input, select, textarea, posts')) {
node.addEventListener(
'change', e => {
this.dispatchEvent(new CustomEvent('change'));
@ -74,16 +79,31 @@ class PoolCreateView extends events.EventTarget {
this._namesFieldNode.setCustomValidity('');
}
_evtPostsInput(e) {
const regex = /^\d+$/;
const list = misc.splitByWhitespace(this._postsFieldNode.value);
for (let item of list) {
if (!regex.test(item)) {
this._postsFieldNode.setCustomValidity(
`Pool ID "${item}" is not an integer.`);
return;
}
}
this._postsFieldNode.setCustomValidity('');
}
_evtSubmit(e) {
e.preventDefault();
let pool = new Pool()
pool.names = misc.splitByWhitespace(this._namesFieldNode.value);
pool.category = this._categoryFieldNode.value;
pool.description = this._descriptionFieldNode.value;
this.dispatchEvent(new CustomEvent('submit', {
detail: {
pool: pool,
names: misc.splitByWhitespace(this._namesFieldNode.value),
category: this._categoryFieldNode.value,
description: this._descriptionFieldNode.value,
posts: misc.splitByWhitespace(this._postsFieldNode.value)
.map(i => parseInt(i, 10))
},
}));
}
@ -103,6 +123,10 @@ class PoolCreateView extends events.EventTarget {
get _descriptionFieldNode() {
return this._formNode.querySelector('.description textarea');
}
get _postsFieldNode() {
return this._formNode.querySelector('.posts input');
}
}
module.exports = PoolCreateView;