2017-01-16 18:30:54 +01:00
|
|
|
import { Template } from 'meteor/templating';
|
2015-12-19 04:24:00 +01:00
|
|
|
|
2017-01-16 18:30:54 +01:00
|
|
|
import { dialogUtils } from '../../../lib/dialogUtils';
|
2015-12-19 04:24:00 +01:00
|
|
|
|
2016-01-09 18:41:33 +01:00
|
|
|
// Global object of key names (TODO: put this somewhere else)
|
2017-01-16 18:30:54 +01:00
|
|
|
const keys = {
|
2015-12-21 15:29:19 +01:00
|
|
|
ESC: 27,
|
|
|
|
|
ENTER: 13
|
|
|
|
|
};
|
|
|
|
|
|
2015-12-19 04:24:00 +01:00
|
|
|
Template.confirmDeleteDialog.events({
|
2017-01-16 18:30:54 +01:00
|
|
|
'click #cancel, click #close'() {
|
|
|
|
|
// Action canceled, just close dialog without calling callback
|
|
|
|
|
dialogUtils.closeHandler(false);
|
2015-12-19 04:24:00 +01:00
|
|
|
},
|
2017-01-16 18:30:54 +01:00
|
|
|
'click #confirm'() {
|
|
|
|
|
// Action confirmed, close dialog and calls callback, if exists
|
|
|
|
|
dialogUtils.closeHandler();
|
2015-12-19 04:24:00 +01:00
|
|
|
},
|
2017-01-16 18:30:54 +01:00
|
|
|
'keydown #confirmDeleteDialog'(e) {
|
|
|
|
|
// Action canceled, just close dialog without calling callback
|
2015-12-21 15:29:19 +01:00
|
|
|
if (e.which === keys.ESC) {
|
2017-01-16 18:30:54 +01:00
|
|
|
dialogUtils.closeHandler(false);
|
2016-01-09 18:41:33 +01:00
|
|
|
return false;
|
2015-12-21 15:29:19 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-19 04:24:00 +01:00
|
|
|
if (this.keyPressAllowed === false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-16 18:30:54 +01:00
|
|
|
// If Enter is pressed
|
2015-12-21 15:29:19 +01:00
|
|
|
if (e.which === keys.ENTER) {
|
2017-01-16 18:30:54 +01:00
|
|
|
// Action confirmed, close dialog and calls callback, if exists
|
|
|
|
|
dialogUtils.closeHandler();
|
2015-12-19 04:24:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
2016-01-11 11:32:20 +01:00
|
|
|
});
|