modal.js 859 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import Ember from 'ember';
  2. export default Ember.Service.extend({
  3. _modal: null,
  4. activeComponent: 'empty-modal',
  5. activeModel: null,
  6. _setupModal: function() {
  7. var modal = null;
  8. modal = Ember.$('#appModal').modal({show: false});
  9. modal.on('shown.bs.modal', function () {
  10. Ember.$('#appModal').focus();
  11. });
  12. var self = this;
  13. modal.on('hidden.bs.modal', function() {
  14. self.setProperties({
  15. activeComponent: 'empty-modal',
  16. activeModel: null
  17. });
  18. });
  19. this.set('_modal', modal);
  20. },
  21. show: function(component, model) {
  22. if (!this.get('_modal')) {
  23. this._setupModal();
  24. }
  25. this.setProperties({
  26. activeComponent: component,
  27. activeModel: model
  28. });
  29. Ember.$('#appModal').modal('show');
  30. },
  31. hide: function() {
  32. Ember.$('#appModal').modal('hide');
  33. }
  34. });