I'm trying to use the "Buffered Proxy" pattern on a collection of items in a form from a hasMany model. When complete, I'm trying to have a "Save" button, which triggers a save action, allow me to save all the as-yet unsaved changes I've made. More info on the BP in Ember:
http://coryforsyth.com/2013/06/27/ember-buffered-proxy-and-method-missing/
I can get all this to work fine with a top level model attribute, but I'm confused as to how to tell all my non-singleton itemControllers that I want them to save their buffers, then be able to call the grandparent to save the whole enchilada. I was hoping I'd be able to do something like this from the parent array controller:
actions: {
saveStuff: function() {
// Something like this possible?
this.get('allTheNonSingletonItemControllerChildren').send('saveThoseBuffers');
}
}
Child controller:
saveThoseBuffers: function() {
var grandParent = this.get('parentController').get('parentController');
this.applyBufferedChanges();
grandParent.saveEntireRecord(); // Not sure how this would work yet - can't use 'needs' because none of these controllers are singletons.
}
Grandparent:
saveEntireRecord: function() {
this.get('model').save().then(function() {
//other stuff;
}
}
View is something like:
{{#each stuff in childitems itemController="childController"}}
{{input type="text" value=stuff.name}}
{{/each}}
<button {{action 'saveStuff'}}>Save</button>
Nothing in the docs or SO has revealed the incantations for this.
UPDATE:
Based on a suggestion, I also tried:
children = this.get('content');
children.forEach(function(child) {
child.send('saveThoseBuffers');
});
but received:
"Uncaught Error: Attempted to handle event saveThoseBuffers
on while in state root.loaded.saved."
UPDATE 2:
Versions:
DEBUG: Ember : 1.5.0-beta.2 ember.js:3496
DEBUG: Ember Data : 1.0.0-beta.7+canary.b45e23ba ember.js:3496
DEBUG: Handlebars : 1.3.0 ember.js:3496
DEBUG: jQuery : 1.9.1 ember.js:3496
UPDATE 3:
Tried getting access to subcontrollers using:
var children = this.get('_subControllers');
That always returns an empty array, regardless of where itemController is set (in the ArrayController or in each loops using itemController=)
UPDATE 4:
I've created a JSFiddle that shows what I'm attempting is possible using _subControllers:
However, it only works by doing some setup in the route using setupController, which I don't see how I can use in my application (the controller in question cannot be named the same as the model, as it's for one 'mode' of viewing/editing that model using {{render}} and it uses an async hasMany relationship.)