szurubooru/client/js/views/pools_header_view.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-05-04 04:53:28 +02:00
'use strict';
const events = require('../events.js');
const misc = require('../util/misc.js');
const search = require('../util/search.js');
const views = require('../util/views.js');
const PoolAutoCompleteControl =
require('../controls/pool_auto_complete_control.js');
const template = views.getTemplate('pools-header');
class PoolsHeaderView extends events.EventTarget {
constructor(ctx) {
super();
this._hostNode = ctx.hostNode;
views.replaceContent(this._hostNode, template(ctx));
if (this._queryInputNode) {
this._autoCompleteControl = new PoolAutoCompleteControl(
this._queryInputNode,
{
2020-06-05 03:01:28 +02:00
confirm: pool => this._autoCompleteControl.replaceSelectedText(
misc.escapeSearchTerm(pool.names[0]), true),
2020-05-04 04:53:28 +02:00
});
}
search.searchInputNodeFocusHelper(this._queryInputNode);
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
}
get _formNode() {
return this._hostNode.querySelector('form');
}
get _queryInputNode() {
return this._hostNode.querySelector('[name=search-text]');
}
_evtSubmit(e) {
e.preventDefault();
this._queryInputNode.blur();
this.dispatchEvent(new CustomEvent('navigate', {detail: {parameters: {
query: this._queryInputNode.value,
page: 1,
}}}));
}
}
module.exports = PoolsHeaderView;