54e3099c56
- Controller lifetime is bound to route lifetime - View lifetime is bound to controller lifetime - Control lifetime is bound to view lifetime - Enhanced event dispatching - Enhanced responsiveness in some places - Views communicate user input to controllers via new event system
40 lines
1 KiB
JavaScript
40 lines
1 KiB
JavaScript
'use strict';
|
|
|
|
const router = require('../router.js');
|
|
const keyboard = require('../util/keyboard.js');
|
|
const misc = require('../util/misc.js');
|
|
const views = require('../util/views.js');
|
|
|
|
const template = views.getTemplate('users-header');
|
|
|
|
class UsersHeaderView {
|
|
constructor(ctx) {
|
|
this._hostNode = ctx.hostNode;
|
|
views.replaceContent(this._hostNode, template(ctx));
|
|
|
|
keyboard.bind('q', () => {
|
|
this._formNode.querySelector('input').focus();
|
|
});
|
|
|
|
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
|
|
}
|
|
|
|
get _formNode() {
|
|
return this._hostNode.querySelector('form');
|
|
}
|
|
|
|
get _queryInputNode() {
|
|
return this._formNode.querySelector('[name=search-text]');
|
|
}
|
|
|
|
_evtSubmit(e) {
|
|
e.preventDefault();
|
|
this._queryInputNode.blur();
|
|
router.show(
|
|
'/users/' + misc.formatSearchQuery({
|
|
text: this._queryInputNode.value,
|
|
}));
|
|
}
|
|
}
|
|
|
|
module.exports = UsersHeaderView;
|