Handle keyboard shortcuts for modal popup

This commit is contained in:
Marvin Scholz 2017-01-20 15:45:12 +01:00
parent 360a80b795
commit c77ba5c611

View file

@ -13,6 +13,9 @@ var app = new Vue({
currentItem: false,
showModal: false
},
created: function () {
window.addEventListener('keyup', this.handleKeyup);
},
methods: {
detailPopup: function (itm, event) {
// `this` inside methods points to the Vue instance
@ -44,6 +47,27 @@ var app = new Vue({
if (index > -1) {
this.items.splice(index, 1);
}
},
handleKeyup: function (event) {
if (this.showModal) {
enter = 13;
backspace = 8;
remove = 46;
esc = 27;
if (event.keyCode === enter) {
if (this.mode === 1) {
return;
}
this.approveItem(this.currentItem.ID);
} else if (event.keyCode === backspace || event.keyCode === remove) {
if (this.mode === 2) {
return;
}
this.rejectItem(this.currentItem.ID);
} else if (event.keyCode === esc) {
this.showModal = false;
}
}
}
}
})