modal.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import Ember from 'ember';
  2. export default Ember.Service.extend({
  3. _modal: null,
  4. render: function(template, model) {
  5. this.container.lookup('route:application').render('modals.' + template, {
  6. into: 'application',
  7. outlet: 'modal',
  8. model: model || null
  9. });
  10. },
  11. disconnect: function() {
  12. this.container.lookup('route:application').disconnectOutlet({
  13. outlet: 'modal',
  14. parentView: 'application'
  15. });
  16. },
  17. _setupModal: function() {
  18. var modal = null;
  19. modal = Ember.$('#appModal').modal({show: false});
  20. modal.on('shown.bs.modal', function () {
  21. Ember.$('#appModal').focus();
  22. });
  23. var self = this;
  24. modal.on('hidden.bs.modal', function() {
  25. self.disconnect();
  26. });
  27. this.set('_modal', modal);
  28. },
  29. show: function(template, model) {
  30. if (!this.get('_modal')) {
  31. this._setupModal();
  32. }
  33. this.render(template, model);
  34. Ember.$('#appModal').modal('show');
  35. },
  36. hide: function() {
  37. Ember.$('#appModal').modal('hide');
  38. }
  39. });