szurubooru/client/js/views/pool_merge_view.js

81 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-05-04 04:53:28 +02:00
'use strict';
const events = require('../events.js');
const api = require('../api.js');
const views = require('../util/views.js');
const PoolAutoCompleteControl =
require('../controls/pool_auto_complete_control.js');
const template = views.getTemplate('pool-merge');
class PoolMergeView extends events.EventTarget {
constructor(ctx) {
super();
this._pool = ctx.pool;
this._hostNode = ctx.hostNode;
2020-06-05 03:01:28 +02:00
this._targetPoolId = null;
2020-05-04 04:53:28 +02:00
ctx.poolNamePattern = api.getPoolNameRegex();
views.replaceContent(this._hostNode, template(ctx));
views.decorateValidator(this._formNode);
if (this._targetPoolFieldNode) {
this._autoCompleteControl = new PoolAutoCompleteControl(
this._targetPoolFieldNode,
{
2020-05-05 00:15:30 +02:00
confirm: pool => {
2020-06-05 03:01:28 +02:00
this._targetPoolId = pool.id;
2020-05-04 04:53:28 +02:00
this._autoCompleteControl.replaceSelectedText(
2020-05-05 00:15:30 +02:00
pool.names[0], false);
}
2020-05-04 04:53:28 +02:00
});
}
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
}
clearMessages() {
views.clearMessages(this._hostNode);
}
enableForm() {
views.enableForm(this._formNode);
}
disableForm() {
views.disableForm(this._formNode);
}
showSuccess(message) {
views.showSuccess(this._hostNode, message);
}
showError(message) {
views.showError(this._hostNode, message);
}
_evtSubmit(e) {
e.preventDefault();
this.dispatchEvent(new CustomEvent('submit', {
detail: {
pool: this._pool,
2020-06-05 03:01:28 +02:00
targetPoolId: this._targetPoolId
2020-05-04 04:53:28 +02:00
},
}));
}
get _formNode() {
return this._hostNode.querySelector('form');
}
get _targetPoolFieldNode() {
return this._formNode.querySelector('input[name=target-pool]');
}
get _addAliasCheckboxNode() {
return this._formNode.querySelector('input[name=alias]');
}
}
module.exports = PoolMergeView;