Category controller should use the correct category object

This commit is contained in:
Robin Ward 2013-05-24 10:56:17 -04:00
parent c0c97487d8
commit 1dae46021e
3 changed files with 19 additions and 10 deletions

View File

@ -37,6 +37,11 @@ Discourse.Site = Discourse.Model.extend({
});
Discourse.Site.reopenClass({
find: function() {
return Discourse.Site.create(PreloadStore.get('site'));
},
create: function(obj) {
var _this = this;
return Object.tap(this._super(obj), function(result) {

View File

@ -8,13 +8,13 @@
**/
Discourse.ApplicationRoute = Discourse.Route.extend({
setupController: function(controller) {
Discourse.set('site', Discourse.Site.create(PreloadStore.get('site')));
Discourse.set('site', Discourse.Site.find());
var currentUser = PreloadStore.get('currentUser');
if (currentUser) {
Discourse.set('currentUser', Discourse.User.create(currentUser));
}
// make sure we delete preloaded data
PreloadStore.remove('site');
PreloadStore.remove('currentUser');
}
});

View File

@ -8,17 +8,22 @@
**/
Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend({
setupController: function(controller, model) {
var slug = Em.get(model, 'slug');
var category = Discourse.get('site.categories').findProperty('slug', slug);
model: function(params) {
var categories = Discourse.Site.find().get('categories');
var slug = Em.get(params, 'slug');
category = categories.findProperty('slug', Em.get(params, 'slug'))
// In case the slug didn't work, try to find it by id instead.
if (!category) {
category = Discourse.get('site.categories').findProperty('id', parseInt(slug, 10));
}
if (!category) {
category = Discourse.Category.create({ name: slug, slug: slug });
category = categories.findProperty('id', parseInt(slug, 10));
}
return category;
},
setupController: function(controller, category) {
var listTopicsController = this.controllerFor('listTopics');
if (listTopicsController) {
var listContent = listTopicsController.get('content');
@ -27,7 +32,6 @@ Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend({
}
}
var listController = this.controllerFor('list');
var urlId = Discourse.Utilities.categoryUrlId(category);
listController.set('filterMode', "category/" + urlId);