|
|
|
@ -3,6 +3,7 @@ import { Events } from 'framework/events';
|
|
|
|
|
import { Keys } from 'const/keys';
|
|
|
|
|
import { Scrollable } from 'framework/views/scrollable';
|
|
|
|
|
import template from 'templates/select/select-entry-field.hbs';
|
|
|
|
|
import { PasswordPresenter } from 'util/formatting/password-presenter';
|
|
|
|
|
|
|
|
|
|
class SelectEntryFieldView extends View {
|
|
|
|
|
parent = 'body';
|
|
|
|
@ -19,18 +20,29 @@ class SelectEntryFieldView extends View {
|
|
|
|
|
|
|
|
|
|
constructor(model) {
|
|
|
|
|
super(model);
|
|
|
|
|
|
|
|
|
|
this.fields = this.model.entry ? this.getFields(this.model.entry) : [];
|
|
|
|
|
this.activeField = this.fields[0]?.field;
|
|
|
|
|
|
|
|
|
|
this.initScroll();
|
|
|
|
|
this.listenTo(Events, 'main-window-blur', this.mainWindowBlur);
|
|
|
|
|
this.setupKeys();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setupKeys() {
|
|
|
|
|
this.onKey(Keys.DOM_VK_UP, this.upPressed, false, 'select-entry-field');
|
|
|
|
|
this.onKey(Keys.DOM_VK_DOWN, this.downPressed, false, 'select-entry-field');
|
|
|
|
|
this.onKey(Keys.DOM_VK_ESCAPE, this.escPressed, false, 'select-entry-field');
|
|
|
|
|
this.onKey(Keys.DOM_VK_RETURN, this.enterPressed, false, 'select-entry-field');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
super.render(this.model);
|
|
|
|
|
super.render({
|
|
|
|
|
needsTouch: this.model.needsTouch,
|
|
|
|
|
deviceShortName: this.model.deviceShortName,
|
|
|
|
|
fields: this.fields,
|
|
|
|
|
activeField: this.activeField
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
document.activeElement.blur();
|
|
|
|
|
|
|
|
|
@ -44,17 +56,62 @@ class SelectEntryFieldView extends View {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cancelAndClose() {
|
|
|
|
|
this.result = null;
|
|
|
|
|
this.emit('result', this.result);
|
|
|
|
|
getFields(entry) {
|
|
|
|
|
return Object.entries(entry.getAllFields())
|
|
|
|
|
.map(([field, value]) => ({
|
|
|
|
|
field,
|
|
|
|
|
value
|
|
|
|
|
}))
|
|
|
|
|
.filter(({ value }) => value)
|
|
|
|
|
.map(({ field, value }) => ({
|
|
|
|
|
field,
|
|
|
|
|
value: value.isProtected ? PasswordPresenter.present(value.length) : value
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
upPressed(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (!this.activeField) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const activeIndex = this.fields.findIndex((f) => f.field === this.activeField) - 1;
|
|
|
|
|
if (activeIndex >= 0) {
|
|
|
|
|
this.activeField = this.fields[activeIndex].field;
|
|
|
|
|
this.render();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
downPressed(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (!this.activeField) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const activeIndex = this.fields.findIndex((f) => f.field === this.activeField) + 1;
|
|
|
|
|
if (activeIndex < this.fields.length) {
|
|
|
|
|
this.activeField = this.fields[activeIndex].field;
|
|
|
|
|
this.render();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
escPressed() {
|
|
|
|
|
this.cancelAndClose();
|
|
|
|
|
this.emit('result', undefined);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enterPressed() {
|
|
|
|
|
this.closeWithResult();
|
|
|
|
|
if (!this.activeField) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.emit('result', this.activeField);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itemClicked(e) {
|
|
|
|
|
const item = e.target.closest('.select-entry-field__item');
|
|
|
|
|
this.activeField = item.dataset.field;
|
|
|
|
|
|
|
|
|
|
this.emit('result', this.activeField);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mainWindowBlur() {
|
|
|
|
@ -72,7 +129,7 @@ class SelectEntryFieldView extends View {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cancelClicked() {
|
|
|
|
|
this.cancelAndClose();
|
|
|
|
|
this.emit('result', undefined);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|