Skip to content

Instantly share code, notes, and snippets.

@AaronGhent
Last active August 29, 2015 13:57
Show Gist options
  • Save AaronGhent/9658819 to your computer and use it in GitHub Desktop.
Save AaronGhent/9658819 to your computer and use it in GitHub Desktop.
/**
* @name: Modal Mixin
* @framework: Ember.JS
* @author: Aaron Ghent
*/
App.ModalMixin = Ember.Mixin.create({
defaultModal: 'modal',
modalsOpen: {},
actions: {
openModal: function (modalName, model, modal) {
modal = modal || this.defaultModal;
if (model) {
this.controllerFor(modalName).set('model', model);
}
this.modalsOpen[modal] = true;
return this.render(modalName, {
into: 'application',
outlet: modal
});
},
closeModal: function (modal) {
modal = modal || this.defaultModal;
this.modalsOpen[modal] = false;
return this.disconnectOutlet({
parentView: 'application',
outlet: modal
});
},
toggleModal: function (modalName, model, modal) {
modal = modal || this.defaultModal;
if (this.modalsOpen.hasOwnProperty(modal) && this.modalsOpen[modal]) {
this.send('closeModal');
} else {
this.send('openModal', modalName, model, modal);
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment