I am using ember-data to edit a user with automatic model resolution
this.route('user', function() {
this.route('edit', { path: ':user_id'})
});
This works fine and the user can modify all aspects of the model DS.attribute
, DS.belongsTo
and DS.hasMany
.
The user can navigate away in a number of ways, in which case all changes should be removed from the model.
- Clicking a
Cancel
button - Clicking the
Broswer Back
button - Clicking the
Save
button but thepromise fails
. - Just Clicking some other link on the page which takes them somewhere else.
The changes should only be applied if the user explicitly wants them to by clicking the Save
button which consequently succeeds.
I considered using ember-buffered-proxy but I am not sure how this will cope with DS.belongsTo and DS.hasMany relationships. Regardless, before saving the model I will need to do buffer.applyBufferedChanges();
before saving and if the server fails I am in the save situation as before.
The willTransition
hook in the browser seems like the obvious place to do this but how can I ensure all changes are removed from the model given rollbackAttributes()
only works for DS.attribute
controls.
Aucun commentaire:
Enregistrer un commentaire