mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Add list of posts to pools
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user