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"-initialization). I think the best way to accomplish this is with a promise so that the component can clean up after the controller completes its task. But how can a controller action return a promise? Alternatively, can a component call a dynamic method directly on a controller?
For example, lets say I have a ModalDialogComponent
.
App.ModalDialogComponent = Ember.Component.extend
didInsertElement: ->
@$('.modal').modal('show')
actions:
save: ->
@sendAction('save').then(@closeModal.bind(@))
# some other actions are omitted
closeModal: ->
@$('.modal').modal('hide')
And I can instantiate the component inside a template named foo
,
{{modal-form save="save" ...}}
And implement the save
method on FooController
App.FooController = Ember.ObjectController.extend
save: ->
# how can we tell the component that this was successful?
As you can see, I only want the closeModal
function to execute if the save
action was successful. In other words, only close the modal if the record was saved successfully.
Is this possible, or am I going about it completely wrong?