ember-addons / bootstrap-for-ember

Bootstrap for Ember.js
http://ember-addons.github.io/bootstrap-for-ember
Apache License 2.0
704 stars 103 forks source link

Run code after modal has been closed #128

Closed BenjaminHorn closed 10 years ago

BenjaminHorn commented 10 years ago

Is there a hook or something to run some code after the modal has been closed (not with the buttins but with "x").

azuby commented 10 years ago

+1 I was just about to add this issue. Is the no cancel callback to, for instance, transition route when modal is closed or at least hide x so state isn't compromised?

asaf commented 10 years ago

Hey guys, Actually there is one [e18a4d96dcc3462] in 0.7.0,

All you have to do is make sure your controller has the Em.Evented mixin, then the modal will trigger a closed event on the controller.

Please reply if it satisfies you, I will leave this issue opened for now as it still needs to be documented.

Thanks.

azuby commented 10 years ago

@asaf Thank you very much! This approach is quite a nice way of handling the dismissed modal event.

I would like to clarify though that the closed event is on the component which is where you most listen for it, not on the controller that is creating the modal.

Is there any way that you could render an outlet using a this modal component and pass a form template that would have access to the model?

BenjaminHorn commented 10 years ago

a simple sample code would be nice

smcclstocks commented 10 years ago

do you have a code example of handling the closed event on a controller when the modal is programmatically created

asaf commented 10 years ago

@smcclstocks I'll add some example to the showcase

cristinawithout commented 10 years ago

An example using Programitically created modal.

Template: {{bs-button title="Create Modal" clicked="createModalProgramatically"}}

Controller:


Showcase.ShowComponentsModalController = Ember.Controller.extend(Ember.Evented, {
  manualButtons: [
      Ember.Object.create({title: 'Submit', clicked:"submitManual"})
      Ember.Object.create({title: 'Cancel', dismiss: 'modal'})
  ],
  actions: {
    submitManual: function() {
      Bootstrap.NM.push('Modal destroyed!', 'success');
      return Bootstrap.ModalManager.close('manualModal');
    },
    createModalProgramatically: function() {
      var myModal = Bootstrap.ModalManager.open('manualModal', 'Hello', 'demo-template', this.manualButtons, this);
      myModal.on('closed', function() {
        console.log(‘MyModal closed); // Every time the modal closes.
      });
    }
  }
});
Panman82 commented 10 years ago

IMO I'd rather have this as an action than DOM event. So you could pass in the name of the action to be called in the component. Ex: {{#bs-modal name='foobar' closed='actionName'}} Programmatically it would be another argument on the .open() method. Or have both so you can have the .on('closed', ...) way programmatically as well.

asaf commented 10 years ago

I really suggest you to go with: http://indexiatech.github.io/ember-components/#/component/component.modal/simple

The modal in this library is much cleaner and supports all these features you are looking for !

Asaf.