diff --git a/app/assets/javascripts/discourse/controllers/list_controller.js b/app/assets/javascripts/discourse/controllers/list_controller.js index 1bcb0cfb880..74f08b8eb72 100644 --- a/app/assets/javascripts/discourse/controllers/list_controller.js +++ b/app/assets/javascripts/discourse/controllers/list_controller.js @@ -1,11 +1,11 @@ /** This controller supports actions when listing topics or categories - @class ListController + @class ListController @extends Discourse.Controller @namespace Discourse @module Discourse -**/ +**/ Discourse.ListController = Discourse.Controller.extend({ currentUserBinding: 'Discourse.currentUser', categoriesBinding: 'Discourse.site.categories', @@ -30,37 +30,40 @@ Discourse.ListController = Discourse.Controller.extend({ }); }).property('filterSummary'), + /** + Load a list based on a filter + + @method load + @param {String} filterMode the filter we want to load + @returns {Ember.Deferred} the promise that will resolve to the list of items. + **/ load: function(filterMode) { - var current, - _this = this; + var listController = this; this.set('loading', true); + if (filterMode === 'categories') { return Ember.Deferred.promise(function(deferred) { - return Discourse.CategoryList.list(filterMode).then(function(items) { - _this.set('loading', false); - _this.set('filterMode', filterMode); - _this.set('categoryMode', true); - return deferred.resolve(items); - }); - }); - } else { - current = (this.get('availableNavItems').filter(function(f) { - return f.name === filterMode; - }))[0]; - if (!current) { - current = Discourse.NavItem.create({ - name: filterMode - }); - } - return Ember.Deferred.promise(function(deferred) { - return Discourse.TopicList.list(current).then(function(items) { - _this.set('filterSummary', items.filter_summary); - _this.set('filterMode', filterMode); - _this.set('loading', false); + Discourse.CategoryList.list(filterMode).then(function(items) { + listController.set('loading', false); + listController.set('filterMode', filterMode); + listController.set('categoryMode', true); return deferred.resolve(items); }); }); } + + var current = (this.get('availableNavItems').filter(function(f) { return f.name === filterMode; }))[0]; + if (!current) { + current = Discourse.NavItem.create({ name: filterMode }); + } + return Ember.Deferred.promise(function(deferred) { + Discourse.TopicList.list(current).then(function(items) { + listController.set('filterSummary', items.filter_summary); + listController.set('filterMode', filterMode); + listController.set('loading', false); + return deferred.resolve(items); + }); + }); }, // Put in the appropriate page title based on our view diff --git a/app/assets/javascripts/discourse/routes/filtered_list_route.js b/app/assets/javascripts/discourse/routes/filtered_list_route.js index 9cd737fb080..bd124dffd51 100644 --- a/app/assets/javascripts/discourse/routes/filtered_list_route.js +++ b/app/assets/javascripts/discourse/routes/filtered_list_route.js @@ -25,14 +25,15 @@ Discourse.FilteredListRoute = Discourse.Route.extend({ }, setupController: function() { - var listController, listTopicsController, _ref, - _this = this; - listController = this.controllerFor('list'); - listTopicsController = this.controllerFor('listTopics'); + var listController = this.controllerFor('list'); + var listTopicsController = this.controllerFor('listTopics'); listController.set('filterMode', this.filter); - if (_ref = listTopicsController.get('content')) { - _ref.set('loaded', false); + + var listContent = listTopicsController.get('content'); + if (listContent) { + listContent.set('loaded', false); } + listController.load(this.filter).then(function(topicList) { listController.set('category', null); listController.set('canCreateTopic', topicList.get('can_create_topic')); diff --git a/app/assets/javascripts/discourse/routes/list_category_route.js b/app/assets/javascripts/discourse/routes/list_category_route.js index ac0b160190e..686b0324244 100644 --- a/app/assets/javascripts/discourse/routes/list_category_route.js +++ b/app/assets/javascripts/discourse/routes/list_category_route.js @@ -9,26 +9,34 @@ Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend({ setupController: function(controller, model) { - var category, listController, slug, urlId, - _this = this; - slug = Em.get(model, 'slug'); - category = Discourse.get('site.categories').findProperty('slug', slug); + var slug = Em.get(model, 'slug'); + var category = Discourse.get('site.categories').findProperty('slug', slug); if (!category) { category = Discourse.get('site.categories').findProperty('id', parseInt(slug, 10)); } - if (!category) { category = Discourse.Category.create({ name: slug, slug: slug }); } - listController = this.controllerFor('list'); - urlId = Discourse.Utilities.categoryUrlId(category); + var listTopicsController = this.controllerFor('listTopics'); + if (listTopicsController) { + var listContent = listTopicsController.get('content'); + if (listContent) { + listContent.set('loaded', false); + } + } + + + var listController = this.controllerFor('list'); + var urlId = Discourse.Utilities.categoryUrlId(category); listController.set('filterMode', "category/" + urlId); + + var router = this; listController.load("category/" + urlId).then(function(topicList) { listController.set('canCreateTopic', topicList.get('can_create_topic')); listController.set('category', category); - _this.controllerFor('listTopics').set('content', topicList); + router.controllerFor('listTopics').set('content', topicList); }); } diff --git a/app/assets/javascripts/discourse/templates/list/topics.js.handlebars b/app/assets/javascripts/discourse/templates/list/topics.js.handlebars index 44c0be22897..fd53561a74f 100644 --- a/app/assets/javascripts/discourse/templates/list/topics.js.handlebars +++ b/app/assets/javascripts/discourse/templates/list/topics.js.handlebars @@ -1,13 +1,13 @@ {{#unless controller.loading}} {{#if content.loaded}} -
- {{/if}} + {{/if}} | {{i18n topic.title}} | @@ -17,7 +17,7 @@{{i18n likes}} | {{i18n views}} | {{i18n activity}} | -
---|