2016-04-14 12:11:31 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-12 20:11:43 +02:00
|
|
|
const router = require('../router.js');
|
2016-04-14 21:01:33 +02:00
|
|
|
const keyboard = require('../util/keyboard.js');
|
2016-04-14 12:11:31 +02:00
|
|
|
const misc = require('../util/misc.js');
|
|
|
|
const views = require('../util/views.js');
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
const template = views.getTemplate('users-header');
|
2016-04-14 12:11:31 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
class UsersHeaderView {
|
|
|
|
constructor(ctx) {
|
|
|
|
this._hostNode = ctx.hostNode;
|
|
|
|
views.replaceContent(this._hostNode, template(ctx));
|
2016-04-14 12:11:31 +02:00
|
|
|
|
2016-04-14 21:01:33 +02:00
|
|
|
keyboard.bind('q', () => {
|
2016-06-14 10:31:48 +02:00
|
|
|
this._formNode.querySelector('input').focus();
|
2016-04-14 21:01:33 +02:00
|
|
|
});
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
|
|
|
|
}
|
|
|
|
|
|
|
|
get _formNode() {
|
|
|
|
return this._hostNode.querySelector('form');
|
|
|
|
}
|
|
|
|
|
|
|
|
get _queryInputNode() {
|
|
|
|
return this._formNode.querySelector('[name=search-text]');
|
|
|
|
}
|
2016-04-14 12:11:31 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
_evtSubmit(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this._queryInputNode.blur();
|
|
|
|
router.show(
|
2016-07-07 21:18:35 +02:00
|
|
|
'/users/' + misc.formatUrlParameters({
|
|
|
|
query: this._queryInputNode.value,
|
2016-06-14 10:31:48 +02:00
|
|
|
}));
|
2016-04-14 12:11:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 12:17:40 +02:00
|
|
|
module.exports = UsersHeaderView;
|