From 1dae46021e6a99bb5e844604c2b8ee3d91c5d7e6 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 24 May 2013 10:56:17 -0400 Subject: [PATCH] Category controller should use the correct category object --- .../javascripts/discourse/models/site.js | 5 +++++ .../discourse/routes/application_route.js | 4 ++-- .../discourse/routes/list_category_route.js | 20 +++++++++++-------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/discourse/models/site.js b/app/assets/javascripts/discourse/models/site.js index ce3ac8a9070..7b497b65f9e 100644 --- a/app/assets/javascripts/discourse/models/site.js +++ b/app/assets/javascripts/discourse/models/site.js @@ -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) { diff --git a/app/assets/javascripts/discourse/routes/application_route.js b/app/assets/javascripts/discourse/routes/application_route.js index c37be43a089..6e3c93831a9 100644 --- a/app/assets/javascripts/discourse/routes/application_route.js +++ b/app/assets/javascripts/discourse/routes/application_route.js @@ -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'); } }); diff --git a/app/assets/javascripts/discourse/routes/list_category_route.js b/app/assets/javascripts/discourse/routes/list_category_route.js index 7dadf1dd746..24f4656cf4e 100644 --- a/app/assets/javascripts/discourse/routes/list_category_route.js +++ b/app/assets/javascripts/discourse/routes/list_category_route.js @@ -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);