Last active
March 12, 2017 10:42
-
-
Save otac0n/7407b440ab2ab62ead82 to your computer and use it in GitHub Desktop.
Bootstrap Modal for EmberJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is this