Skip to content

Instantly share code, notes, and snippets.

@otac0n
Last active March 12, 2017 10:42
Show Gist options
  • Save otac0n/7407b440ab2ab62ead82 to your computer and use it in GitHub Desktop.
Save otac0n/7407b440ab2ab62ead82 to your computer and use it in GitHub Desktop.
Bootstrap Modal for EmberJS
App = Ember.Application.create();
App.BootstrapModalView = Ember.View.extend({
classNames: ['modal', 'fade'],
layout: Ember.Handlebars.compile('<div class="modal-dialog"><div class="modal-content">{{yield}}</div></div>'),
didInsertElement: function () {
this._super();
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
},
afterRenderEvent: function () {
var self = this;
this.$().on('hidden.bs.modal', function (e) {
self.get('controller').send("afterDismiss");
}).modal('show');
},
willDestroyElement: function () {
this.$().off().removeClass('fade').modal('hide').data('bs.modal', null);
},
actions: {
dismiss: function () {
this.$().modal('hide');
}
}
});
App.Router.map(function () {
this.resource('users', function () {
this.resource('addUser', { path: '/add' });
});
});
App.AddUserView = App.BootstrapModalView.extend();
App.AddUserController = Ember.Controller.extend({
afterDismiss: function () {
this.transitionToRoute('users');
}
});
<script type="text/x-handlebars" id="users">
{{#link-to 'addUser'}}Add User{{/link-to}}
{{outlet}}
</script>
<script type="text/x-handlebars" id="addUser">
<div class="modal-header">
<h3 class="modal-title">Add User</h3>
</div>
<div class="modal-body">
<!-- Standard Bootstrap/Ember stuff. -->
</div>
<div class="modal-footer">
<button class="btn btn-link" {{action 'dismiss' target='view'}}>Cancel</button>
<button class="btn btn-primary">Create</button>
</div>
</script>
@makwanakalpesh1
Copy link

what is this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment