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

@ -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);
}); });
} }