2020-06-06 00:03:37 +02:00
|
|
|
"use strict";
|
2016-04-14 12:11:31 +02:00
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
const events = require("../events.js");
|
|
|
|
const search = require("../util/search.js");
|
|
|
|
const views = require("../util/views.js");
|
2016-04-14 12:11:31 +02:00
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
const template = views.getTemplate("users-header");
|
2016-04-14 12:11:31 +02:00
|
|
|
|
2016-08-28 18:53:06 +02:00
|
|
|
class UsersHeaderView extends events.EventTarget {
|
2016-06-14 10:31:48 +02:00
|
|
|
constructor(ctx) {
|
2016-08-28 18:53:06 +02:00
|
|
|
super();
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
this._hostNode = ctx.hostNode;
|
|
|
|
views.replaceContent(this._hostNode, template(ctx));
|
2016-04-14 12:11:31 +02:00
|
|
|
|
2016-08-28 18:53:06 +02:00
|
|
|
search.searchInputNodeFocusHelper(this._queryInputNode);
|
2016-04-14 21:01:33 +02:00
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
this._formNode.addEventListener("submit", (e) => this._evtSubmit(e));
|
2016-06-14 10:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get _formNode() {
|
2020-06-06 00:03:37 +02:00
|
|
|
return this._hostNode.querySelector("form");
|
2016-06-14 10:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get _queryInputNode() {
|
2020-06-06 00:03:37 +02:00
|
|
|
return this._formNode.querySelector("[name=search-text]");
|
2016-06-14 10:31:48 +02:00
|
|
|
}
|
2016-04-14 12:11:31 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
_evtSubmit(e) {
|
|
|
|
e.preventDefault();
|
2020-06-06 00:03:37 +02:00
|
|
|
this.dispatchEvent(
|
|
|
|
new CustomEvent("navigate", {
|
|
|
|
detail: {
|
|
|
|
parameters: {
|
|
|
|
query: this._queryInputNode.value,
|
|
|
|
page: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
2016-04-14 12:11:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 12:17:40 +02:00
|
|
|
module.exports = UsersHeaderView;
|