abuder
April 30, 2015, 9:07am
1
Hi,
I have an problem, in my app is am master detail view. The master view display an paged list of customers, an on an detail view you can create an new customer. What is the best way to refresh the model on master view? The routes look like this.
this.route('accounts', function() {
this.route('account', {path: ':account_id'}, function() {
this.route('edit');
});
this.route('new');
});
gerrit
April 30, 2015, 9:58am
2
Usally in the accountsIndexController is the list of customers stored on the content property.
When you create a new custom, you can add him to the controller and he will appear in the list.
Something like this (if the save action is on the accountsNewRoute):
var self = this;
account.save().then(function(account) {
self.controllerFor('accountsIndex').pushObject(account)
}
)
abuder
April 30, 2015, 10:02am
3
Thank’s but it’s not so easy. I use query parameter an I don’t know if the object is in page or not, default the page is sorted by name.
CustomersRoute
import Ember from 'ember';
export default Ember.Route.extend({
queryParams: {
page: {
refreshModel: true
},
size:{
refreshModel: true
}
},
model:function(params){
console.log('model');
return this.store.find('customer', params);
},
afterModel: function(model){
model.forEach(function(customer) {
customer.set('selected', false);
});
},
setupController: function(controller,model){
controller.set('model',model);
controller.set('meta', model.get("meta"));
}
});
CustomerNewController
import Ember from 'ember';
export default Ember.Controller.extend({
needs: ['session'],
error: null,
actions: {
submit: function(){
var customer = this.get('model'),
_this = this;
customer.save().then(
function(){
_this.get('controllers.session').set("successMessage", "Kunde wurde angelegt");
_this.transitionToRoute('session.administration.customers', {queryParams: {page: 2, size: 5}});
},function(error){
_this.set('error',error.responseJSON);
_this.get('controllers.session').set("errorMessage", "Kunde konnte nicht angelegt werden");
});
}, // submit
cancel: function(){
this.get('model').rollback();
this.transitionToRoute('session.administration.customers',{queryParams: {page: 1, size: 5}});
}// cancel
} // actions
});