FIX: Hide topics list when loading new topics by category

This commit is contained in:
Robin Ward 2013-03-14 12:38:05 -04:00
parent f47240483c
commit 1715220d77
4 changed files with 57 additions and 45 deletions

View File

@ -1,11 +1,11 @@
/** /**
This controller supports actions when listing topics or categories This controller supports actions when listing topics or categories
@class ListController @class ListController
@extends Discourse.Controller @extends Discourse.Controller
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.ListController = Discourse.Controller.extend({ Discourse.ListController = Discourse.Controller.extend({
currentUserBinding: 'Discourse.currentUser', currentUserBinding: 'Discourse.currentUser',
categoriesBinding: 'Discourse.site.categories', categoriesBinding: 'Discourse.site.categories',
@ -30,37 +30,40 @@ Discourse.ListController = Discourse.Controller.extend({
}); });
}).property('filterSummary'), }).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) { load: function(filterMode) {
var current, var listController = this;
_this = this;
this.set('loading', true); this.set('loading', true);
if (filterMode === 'categories') { if (filterMode === 'categories') {
return Ember.Deferred.promise(function(deferred) { return Ember.Deferred.promise(function(deferred) {
return Discourse.CategoryList.list(filterMode).then(function(items) { Discourse.CategoryList.list(filterMode).then(function(items) {
_this.set('loading', false); listController.set('loading', false);
_this.set('filterMode', filterMode); listController.set('filterMode', filterMode);
_this.set('categoryMode', true); listController.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);
return deferred.resolve(items); 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 // Put in the appropriate page title based on our view

View File

@ -25,14 +25,15 @@ Discourse.FilteredListRoute = Discourse.Route.extend({
}, },
setupController: function() { setupController: function() {
var listController, listTopicsController, _ref, var listController = this.controllerFor('list');
_this = this; var listTopicsController = this.controllerFor('listTopics');
listController = this.controllerFor('list');
listTopicsController = this.controllerFor('listTopics');
listController.set('filterMode', this.filter); 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.load(this.filter).then(function(topicList) {
listController.set('category', null); listController.set('category', null);
listController.set('canCreateTopic', topicList.get('can_create_topic')); listController.set('canCreateTopic', topicList.get('can_create_topic'));

View File

@ -9,26 +9,34 @@
Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend({ Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend({
setupController: function(controller, model) { setupController: function(controller, model) {
var category, listController, slug, urlId, var slug = Em.get(model, 'slug');
_this = this; var category = Discourse.get('site.categories').findProperty('slug', slug);
slug = Em.get(model, 'slug');
category = Discourse.get('site.categories').findProperty('slug', slug);
if (!category) { if (!category) {
category = Discourse.get('site.categories').findProperty('id', parseInt(slug, 10)); category = Discourse.get('site.categories').findProperty('id', parseInt(slug, 10));
} }
if (!category) { if (!category) {
category = Discourse.Category.create({ name: slug, slug: slug }); category = Discourse.Category.create({ name: slug, slug: slug });
} }
listController = this.controllerFor('list'); var listTopicsController = this.controllerFor('listTopics');
urlId = Discourse.Utilities.categoryUrlId(category); 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); listController.set('filterMode', "category/" + urlId);
var router = this;
listController.load("category/" + urlId).then(function(topicList) { listController.load("category/" + urlId).then(function(topicList) {
listController.set('canCreateTopic', topicList.get('can_create_topic')); listController.set('canCreateTopic', topicList.get('can_create_topic'));
listController.set('category', category); listController.set('category', category);
_this.controllerFor('listTopics').set('content', topicList); router.controllerFor('listTopics').set('content', topicList);
}); });
} }

View File

@ -1,13 +1,13 @@
{{#unless controller.loading}} {{#unless controller.loading}}
{{#if content.loaded}} {{#if content.loaded}}
<div class='contents'> <div class='contents'>
{{#if content.topics.length}} {{#if content.topics.length}}
<table id='topic-list' {{bindAttr class="controller.category:filter-category"}}> <table id='topic-list' {{bindAttr class="controller.category:filter-category"}}>
<thead> <thead>
<tr> <tr>
{{#if Discourse.currentUser}} {{#if Discourse.currentUser}}
<th>&nbsp;</th> <th>&nbsp;</th>
{{/if}} {{/if}}
<th> <th>
{{i18n topic.title}} {{i18n topic.title}}
</th> </th>
@ -17,7 +17,7 @@
<th class='num'>{{i18n likes}}</th> <th class='num'>{{i18n likes}}</th>
<th class='num'>{{i18n views}}</th> <th class='num'>{{i18n views}}</th>
<th class='num activity' colspan='2'>{{i18n activity}}</th> <th class='num activity' colspan='2'>{{i18n activity}}</th>
</tr> </tr>
</thead> </thead>
{{#if view.rollUp}} {{#if view.rollUp}}
@ -30,10 +30,10 @@
</div> </div>
</td> </td>
</tr> </tr>
</tbody> </tbody>
{{else}} {{else}}
{{#group}} {{#group}}
{{collection contentBinding="content.inserted" tagName="tbody" itemViewClass="Discourse.TopicListItemView"}} {{collection contentBinding="content.inserted" tagName="tbody" itemViewClass="Discourse.TopicListItemView"}}
{{/group}} {{/group}}
{{/if}} {{/if}}
@ -52,7 +52,7 @@
</footer> </footer>
<h3> <h3>
{{view.footerMessage}} {{view.footerMessage}}
{{#if view.allLoaded}} {{#if view.allLoaded}}
{{#if controller.popular}} {{#if controller.popular}}
{{#if view.canCreateTopic}} {{#if view.canCreateTopic}}