Created
October 14, 2014 05:40
-
-
Save dbachet/c853e272942521cb7384 to your computer and use it in GitHub Desktop.
Add new created item to the list not refresh the list properly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ch.LinksNewController = Ember.ObjectController.extend({ | |
needs: 'categories', | |
categories: Ember.computed.alias('controllers.categories.model'), | |
languages: ['FR', 'EN'], | |
categoryNames: function() { | |
return this.get('categories').map(function(category) { | |
return { | |
id: category, | |
label: category.get('name') | |
}; | |
}); | |
}.property('categories.@each'), | |
actions: { | |
create: function() { | |
var self = this; | |
this.get('model').save().then(function(link){ | |
self.send('addNewLink', link); | |
}, function() { | |
self.set('hasErrors', true); | |
}); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ch.LinksIndexRoute = Ember.Route.extend({ | |
queryParams: { | |
category: { | |
refreshModel: true | |
} | |
}, | |
model: function (params) { | |
if (params) { | |
return this.store.findQuery('link', params); | |
} else { | |
return this.store.find('link'); | |
} | |
// return this.store.filter('link', params, function(link) { | |
// return true; | |
// }); | |
}, | |
renderTemplate: function () { | |
this._super.apply(this, arguments); | |
var currentUser = this.currentUser.get('content'); | |
var sidebarCategoriesController = this.controllerFor('categories'); | |
var linksNewController = this.controllerFor('links.new'); | |
var store = this.store; | |
// Fetch categories only if it hasn't been already | |
if (Ember.isEmpty(sidebarCategoriesController.get('model'))) { | |
sidebarCategoriesController.set('model', store.find('category')); | |
} | |
if (Ember.isEmpty(linksNewController.get('model'))) { | |
var newLink = store.createRecord('link', {user: currentUser}); | |
linksNewController.set('model', newLink); | |
} | |
this.render('links-new', { | |
outlet: 'links-new', | |
into: 'application', | |
controller: linksNewController | |
}); | |
this.render('sidebar-categories', { | |
outlet: 'sidebar-categories', | |
into: 'application', | |
controller: sidebarCategoriesController | |
}); | |
}, | |
actions: { | |
addNewLink: function(link) { | |
var linksIndexController = this.controllerFor('links.index'); | |
var categoryParams = linksIndexController.get('category'); | |
if (Ember.isNone(categoryParams)) { | |
this.store.push('Link', link); | |
// linksIndexController.get('model').pushObject(link); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment