I have a component that needs to communicate with a controller and eventually perform some clean up after the controller says everything is ok (ie, jQuery \"un\"-in
send
and sendAction
are one way streets, that being said, you can send a defer to the action and expect it to resolve/reject it.
var defer = Ember.RSVP.defer();
defer.promise.then(function(resolvedValue){
alert(resolvedValue);
});
setTimeout(function(){
defer.resolve('hello world');
},2000);
Yours would look a bit like this
var defer = Ember.RSVP.defer(),
self = this;
defer.promise.then(function(){
self.closeModal();
},
function(){
alert('error');
});
this.sendAction('save', defer);
save action
actions: {
save: function(defer){
// if succeeded
defer.resolve();
// or if failure occurs
defer.reject();
}
}
Be careful, you want to make sure you don't leave out the reject route, you'd hate to have the modal stuck up there because the save failed and there wasn't a failure method.
Sorry I didn't convert to coffee script, I figure you'll either understand or convert and understand and I won't have given you a wrong answer.