modal.js 972 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. var previousComponent = this.get('activeComponent');
  26. this.setProperties({
  27. activeComponent: component,
  28. activeModel: model
  29. });
  30. if (previousComponent === 'empty-modal') {
  31. Ember.$('#appModal').modal('show');
  32. }
  33. },
  34. hide: function() {
  35. Ember.$('#appModal').modal('hide');
  36. }
  37. });