2016-07-24 22:57:12 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Backbone = require('backbone');
|
|
|
|
const Keys = require('../../const/keys');
|
|
|
|
const KeyHandler = require('../../comp/key-handler');
|
|
|
|
|
|
|
|
let AutoTypePopupView = Backbone.View.extend({
|
|
|
|
el: 'body',
|
|
|
|
|
|
|
|
template: require('templates/auto-type/auto-type-select.hbs'),
|
|
|
|
|
|
|
|
events: {
|
2016-07-24 23:53:42 +02:00
|
|
|
'click .at-select__header-filter-clear': 'clearFilterText'
|
2016-07-24 22:57:12 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
result: null,
|
|
|
|
|
|
|
|
initialize() {
|
2016-07-24 23:10:03 +02:00
|
|
|
this.listenTo(Backbone, 'main-window-blur', this.mainWindowBlur);
|
2016-07-24 22:57:12 +02:00
|
|
|
KeyHandler.onKey(Keys.DOM_VK_ESCAPE, this.escPressed, this, false, true);
|
|
|
|
KeyHandler.onKey(Keys.DOM_VK_RETURN, this.enterPressed, this, false, true);
|
|
|
|
KeyHandler.onKey(Keys.DOM_VK_UP, this.upPressed, this, false, true);
|
|
|
|
KeyHandler.onKey(Keys.DOM_VK_DOWN, this.downPressed, this, false, true);
|
2016-07-24 23:53:42 +02:00
|
|
|
KeyHandler.onKey(Keys.DOM_VK_BACK_SPACE, this.backSpacePressed, this, false, true);
|
2016-07-24 22:57:12 +02:00
|
|
|
KeyHandler.on('keypress:auto-type', this.keyPressed.bind(this));
|
|
|
|
KeyHandler.setModal('auto-type');
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
2016-07-24 23:53:42 +02:00
|
|
|
this.renderTemplate({
|
|
|
|
filterText: this.model.filter.text
|
|
|
|
});
|
2016-07-24 22:57:12 +02:00
|
|
|
document.activeElement.blur();
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
remove() {
|
|
|
|
KeyHandler.offKey(Keys.DOM_VK_ESCAPE, this.escPressed, this);
|
|
|
|
KeyHandler.offKey(Keys.DOM_VK_RETURN, this.enterPressed, this);
|
|
|
|
KeyHandler.offKey(Keys.DOM_VK_UP, this.upPressed, this);
|
|
|
|
KeyHandler.offKey(Keys.DOM_VK_DOWN, this.downPressed, this);
|
2016-07-24 23:53:42 +02:00
|
|
|
KeyHandler.offKey(Keys.DOM_VK_BACK_SPACE, this.backSpacePressed, this);
|
2016-07-24 22:57:12 +02:00
|
|
|
KeyHandler.off('keypress:auto-type');
|
|
|
|
KeyHandler.setModal(null);
|
|
|
|
Backbone.View.prototype.remove.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
2016-07-24 23:10:03 +02:00
|
|
|
cancelAndClose() {
|
2016-07-24 22:57:12 +02:00
|
|
|
this.result = null;
|
|
|
|
this.trigger('result', this.result);
|
|
|
|
},
|
|
|
|
|
2016-07-24 23:10:03 +02:00
|
|
|
escPressed() {
|
|
|
|
this.cancelAndClose();
|
|
|
|
},
|
|
|
|
|
2016-07-24 22:57:12 +02:00
|
|
|
enterPressed() {
|
|
|
|
this.trigger('result', this.result);
|
|
|
|
},
|
|
|
|
|
|
|
|
upPressed() {
|
|
|
|
},
|
|
|
|
|
|
|
|
downPressed() {
|
|
|
|
},
|
|
|
|
|
|
|
|
keyPressed(e) {
|
2016-07-24 23:53:42 +02:00
|
|
|
if (e.which) {
|
|
|
|
this.model.filter.text += String.fromCharCode(e.which);
|
|
|
|
this.render();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
backSpacePressed() {
|
|
|
|
if (this.model.filter.text) {
|
|
|
|
this.model.filter.text = this.model.filter.text.substr(0, this.model.filter.text.length - 1);
|
|
|
|
this.render();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clearFilterText() {
|
|
|
|
this.model.filter.text = '';
|
|
|
|
this.render();
|
2016-07-24 23:10:03 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
mainWindowBlur() {
|
|
|
|
this.cancelAndClose();
|
2016-07-24 22:57:12 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = AutoTypePopupView;
|