Discovered the resolution within this informative piece:
An elegant solution surfaced, eliminating the need to reopen Ember.View
and ensuring functionality across all desired views.
The structure of the ApplicationRoute
remains consistent:
App.ApplicationRoute = Em.Route.extend({
actions: {
showModal: function() {
return this.render('modal', {
into: 'application',
outlet: 'modal'
});
}
closeModal: function() {
return this.disconnectOutlet({
parentView: 'application',
outlet: 'modal'
});
}
}
});
However, now we've taken advantage of overriding Ember.View
's didInsertElement
to schedule a function call:
Em.View.reopen({
didInsertElement: function() {
this._super();
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
}
});
In addition, I explicitly defined ModalView and created an afterRenderEvent function that pinpoints the .modal DOM node for seamless implementation!
App.ModalView = Em.View.extend({
afterRenderEvent: function() {
this.$('.modal').modal();
}
});
Observe it in action here:
Edit
A crucial step is manually destroying the view to ensure the modal reappears as expected:
App.ModalView = Em.View.extend({
var this = self;
afterRenderEvent: function() {
this.$('.modal')
.on('hidden.bs.modal', function() {
self.triggerAction({
action: 'closeModal'
});
})
.modal();
}
});
Edit 2
A more advanced solution emerges when dealing with modals incorporating components. The provided code snippets have been refreshed accordingly.