Properly assign draft keys to Categories List view.
This commit is contained in:
parent
33d3f1fdd1
commit
92dc59fba9
|
@ -38,9 +38,14 @@ Discourse.ListController = Discourse.Controller.extend({
|
|||
|
||||
if (filterMode === 'categories') {
|
||||
return Discourse.CategoryList.list(filterMode).then(function(items) {
|
||||
listController.set('loading', false);
|
||||
listController.set('filterMode', filterMode);
|
||||
listController.set('categoryMode', true);
|
||||
listController.setProperties({
|
||||
loading: false,
|
||||
filterMode: filterMode,
|
||||
categoryMode: true,
|
||||
draft: items.draft,
|
||||
draft_key: items.draft_key,
|
||||
draft_sequence: items.draft_sequence
|
||||
});
|
||||
return items;
|
||||
});
|
||||
}
|
||||
|
@ -49,10 +54,16 @@ Discourse.ListController = Discourse.Controller.extend({
|
|||
if (!current) {
|
||||
current = Discourse.NavItem.create({ name: filterMode });
|
||||
}
|
||||
|
||||
return Discourse.TopicList.list(current).then(function(items) {
|
||||
listController.set('filterSummary', items.filter_summary);
|
||||
listController.set('filterMode', filterMode);
|
||||
listController.set('loading', false);
|
||||
listController.setProperties({
|
||||
loading: false,
|
||||
filterSummary: items.filter_summary,
|
||||
filterMode: filterMode,
|
||||
draft: items.draft,
|
||||
draft_key: items.draft_key,
|
||||
draft_sequence: items.draft_sequence
|
||||
})
|
||||
return items;
|
||||
});
|
||||
},
|
||||
|
@ -72,13 +83,12 @@ Discourse.ListController = Discourse.Controller.extend({
|
|||
|
||||
// Create topic button
|
||||
createTopic: function() {
|
||||
var topicList = this.get('controllers.listTopics.content');
|
||||
if (!topicList) return;
|
||||
this.get('controllers.composer').open({
|
||||
categoryName: this.get('category.name'),
|
||||
action: Discourse.Composer.CREATE_TOPIC,
|
||||
draftKey: topicList.get('draft_key'),
|
||||
draftSequence: topicList.get('draft_sequence')
|
||||
draft: this.get('draft'),
|
||||
draftKey: this.get('draft_key'),
|
||||
draftSequence: this.get('draft_sequence')
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -57,10 +57,13 @@ Discourse.CategoryList.reopenClass({
|
|||
|
||||
return finder.then(function(result) {
|
||||
var categoryList = Discourse.TopicList.create();
|
||||
categoryList.set('can_create_category', result.category_list.can_create_category);
|
||||
categoryList.set('can_create_topic', result.category_list.can_create_topic);
|
||||
categoryList.set('categories', route.categoriesFrom(result));
|
||||
categoryList.set('loaded', true);
|
||||
categoryList.setProperties({
|
||||
can_create_category: result.category_list.can_create_category,
|
||||
can_create_topic: result.category_list.can_create_topic,
|
||||
categories: route.categoriesFrom(result),
|
||||
draft_key: result.category_list.draft_key,
|
||||
draft_sequence: result.category_list.draft_sequence
|
||||
})
|
||||
return categoryList;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ Discourse.ListCategoriesRoute = Discourse.Route.extend({
|
|||
|
||||
setupController: function(controller, categoryList) {
|
||||
this.render('listCategories', { into: 'list', outlet: 'listView' });
|
||||
|
||||
this.controllerFor('list').setProperties({
|
||||
canCreateCategory: categoryList.get('can_create_category'),
|
||||
canCreateTopic: categoryList.get('can_create_topic'),
|
||||
|
|
|
@ -8,6 +8,11 @@ class CategoriesController < ApplicationController
|
|||
|
||||
def index
|
||||
@list = CategoryList.new(guardian)
|
||||
|
||||
@list.draft_key = Draft::NEW_TOPIC
|
||||
@list.draft_sequence = DraftSequence.current(current_user, Draft::NEW_TOPIC)
|
||||
@list.draft = Draft.get(current_user, @list.draft_key, @list.draft_sequence) if current_user
|
||||
|
||||
discourse_expires_in 1.minute
|
||||
|
||||
store_preloaded("categories_list", MultiJson.dump(CategoryListSerializer.new(@list, scope: guardian)))
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
class CategoryList
|
||||
include ActiveModel::Serialization
|
||||
|
||||
attr_accessor :categories, :topic_users, :uncategorized
|
||||
attr_accessor :categories,
|
||||
:topic_users,
|
||||
:uncategorized,
|
||||
:draft,
|
||||
:draft_key,
|
||||
:draft_sequence
|
||||
|
||||
def initialize(guardian=nil)
|
||||
@guardian = guardian || Guardian.new
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
class CategoryListSerializer < ApplicationSerializer
|
||||
|
||||
attributes :can_create_category, :can_create_topic
|
||||
attributes :can_create_category,
|
||||
:can_create_topic,
|
||||
:draft,
|
||||
:draft_key,
|
||||
:draft_sequence
|
||||
|
||||
has_many :categories, serializer: CategoryDetailedSerializer, embed: :objects
|
||||
|
||||
|
|
Loading…
Reference in New Issue