2015-11-18 13:50:48 +03:00
|
|
|
/* global key */
|
2016-06-30 13:21:47 +03:00
|
|
|
import Component from 'ember-component';
|
|
|
|
import run from 'ember-runloop';
|
2016-04-27 00:32:17 +03:00
|
|
|
import {invokeAction} from 'ember-invoke-action';
|
2015-11-18 13:50:48 +03:00
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
tagName: 'section',
|
|
|
|
classNames: 'modal-content',
|
|
|
|
|
|
|
|
_previousKeymasterScope: null,
|
|
|
|
|
2016-01-19 19:00:44 +03:00
|
|
|
_setupShortcuts() {
|
2015-11-18 13:50:48 +03: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 19:00:44 +03:00
|
|
|
},
|
2015-11-18 13:50:48 +03:00
|
|
|
|
2016-01-19 19:00:44 +03:00
|
|
|
_removeShortcuts() {
|
2015-11-18 13:50:48 +03:00
|
|
|
key.unbind('enter', 'modal');
|
|
|
|
key.unbind('escape', 'modal');
|
|
|
|
|
|
|
|
key.setScope(this._previousKeymasterScope);
|
2016-01-19 19:00:44 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this._setupShortcuts();
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this._removeShortcuts();
|
|
|
|
},
|
2015-11-18 13:50:48 +03:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
confirm() {
|
|
|
|
throw new Error('You must override the "confirm" action in your modal component');
|
|
|
|
},
|
|
|
|
|
|
|
|
closeModal() {
|
2016-04-27 00:32:17 +03:00
|
|
|
invokeAction(this, 'closeModal');
|
2015-11-18 13:50:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|