2015-11-18 10:50:48 +00:00
|
|
|
/* global key */
|
|
|
|
import Ember from 'ember';
|
2016-04-26 16:32:17 -05:00
|
|
|
import {invokeAction} from 'ember-invoke-action';
|
2015-11-18 10:50:48 +00:00
|
|
|
|
2016-01-19 10:00:44 -06:00
|
|
|
const {Component, run} = Ember;
|
2015-11-18 10:50:48 +00:00
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
tagName: 'section',
|
|
|
|
classNames: 'modal-content',
|
|
|
|
|
|
|
|
_previousKeymasterScope: null,
|
|
|
|
|
2016-01-19 10:00:44 -06:00
|
|
|
_setupShortcuts() {
|
2015-11-18 10:50:48 +00:00
|
|
|
run(function () {
|
|
|
|
document.activeElement.blur();
|
|
|
|
});
|
|
|
|
this._previousKeymasterScope = key.getScope();
|
|
|
|
|
|
|
|
key('enter', 'modal', () => {
|
|
|
|
this.send('confirm');
|
|
|
|
});
|
|
|
|
|
|
|
|
key('escape', 'modal', () => {
|
|
|
|
this.send('closeModal');
|
|
|
|
});
|
|
|
|
|
|
|
|
key.setScope('modal');
|
2016-01-19 10:00:44 -06:00
|
|
|
},
|
2015-11-18 10:50:48 +00:00
|
|
|
|
2016-01-19 10:00:44 -06:00
|
|
|
_removeShortcuts() {
|
2015-11-18 10:50:48 +00:00
|
|
|
key.unbind('enter', 'modal');
|
|
|
|
key.unbind('escape', 'modal');
|
|
|
|
|
|
|
|
key.setScope(this._previousKeymasterScope);
|
2016-01-19 10:00:44 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this._setupShortcuts();
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this._removeShortcuts();
|
|
|
|
},
|
2015-11-18 10:50:48 +00:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
confirm() {
|
|
|
|
throw new Error('You must override the "confirm" action in your modal component');
|
|
|
|
},
|
|
|
|
|
|
|
|
closeModal() {
|
2016-04-26 16:32:17 -05:00
|
|
|
invokeAction(this, 'closeModal');
|
2015-11-18 10:50:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|