Ghost/ghost/admin/app/components/modals/base.js
Kevin Ansfield 9d67980a7e Refactor modals
refs #5798, closes #5018
- adds new `gh-fullscreen-modal` component - modals are now specified in-context so that they can have deeper interaction with their surrounding components/controller/route, i.e. a modal component can be a thin confirm/deny wrapper over the underlying controller action keeping all context-sensitive logic in one place
- adds spin-buttons to all modals with async behaviour
- adds/improves behaviour of inline-validation in modals
- improves re-authenticate modal to properly handle validation and authentication errors
2016-01-12 20:53:08 +00:00

46 lines
1.0 KiB
JavaScript

/* global key */
import Ember from 'ember';
const {Component, on, run} = Ember;
export default Component.extend({
tagName: 'section',
classNames: 'modal-content',
_previousKeymasterScope: null,
setupShortcuts: on('didInsertElement', function () {
run(function () {
document.activeElement.blur();
});
this._previousKeymasterScope = key.getScope();
key('enter', 'modal', () => {
this.send('confirm');
});
key('escape', 'modal', () => {
this.send('closeModal');
});
key.setScope('modal');
}),
removeShortcuts: on('willDestroyElement', function () {
key.unbind('enter', 'modal');
key.unbind('escape', 'modal');
key.setScope(this._previousKeymasterScope);
}),
actions: {
confirm() {
throw new Error('You must override the "confirm" action in your modal component');
},
closeModal() {
this.attrs.closeModal();
}
}
});