FIX: Hide topics list when loading new topics by category
This commit is contained in:
parent
f47240483c
commit
1715220d77
|
@ -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
|
||||
|
|
|
@ -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'));
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
{{#unless controller.loading}}
|
||||
{{#if content.loaded}}
|
||||
<div class='contents'>
|
||||
<div class='contents'>
|
||||
{{#if content.topics.length}}
|
||||
<table id='topic-list' {{bindAttr class="controller.category:filter-category"}}>
|
||||
<thead>
|
||||
<tr>
|
||||
{{#if Discourse.currentUser}}
|
||||
<th> </th>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
<th>
|
||||
{{i18n topic.title}}
|
||||
</th>
|
||||
|
@ -17,7 +17,7 @@
|
|||
<th class='num'>{{i18n likes}}</th>
|
||||
<th class='num'>{{i18n views}}</th>
|
||||
<th class='num activity' colspan='2'>{{i18n activity}}</th>
|
||||
</tr>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
{{#if view.rollUp}}
|
||||
|
@ -30,10 +30,10 @@
|
|||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</tbody>
|
||||
{{else}}
|
||||
{{#group}}
|
||||
{{collection contentBinding="content.inserted" tagName="tbody" itemViewClass="Discourse.TopicListItemView"}}
|
||||
{{collection contentBinding="content.inserted" tagName="tbody" itemViewClass="Discourse.TopicListItemView"}}
|
||||
{{/group}}
|
||||
{{/if}}
|
||||
|
||||
|
@ -52,7 +52,7 @@
|
|||
</footer>
|
||||
|
||||
<h3>
|
||||
{{view.footerMessage}}
|
||||
{{view.footerMessage}}
|
||||
{{#if view.allLoaded}}
|
||||
{{#if controller.popular}}
|
||||
{{#if view.canCreateTopic}}
|
||||
|
|
Loading…
Reference in New Issue