From 1958b0205e921fa9f4ac91371106fe7c4f3dc93c Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 5 Aug 2014 11:33:15 +1000 Subject: [PATCH] FIX: sloppy topic draft handling Will open in categories page and category drill down --- .../javascripts/discourse/models/category_list.js | 1 + .../discourse/routes/build-category-route.js.es6 | 2 ++ .../discourse/routes/build-topic-route.js.es6 | 13 +------------ .../discourse/routes/discourse_route.js | 15 +++++++++++++++ .../routes/discovery_categories_route.js | 3 +++ .../discourse/routes/discovery_top_routes.js | 10 +--------- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/discourse/models/category_list.js b/app/assets/javascripts/discourse/models/category_list.js index d9c98d7c1c0..d60c41e978a 100644 --- a/app/assets/javascripts/discourse/models/category_list.js +++ b/app/assets/javascripts/discourse/models/category_list.js @@ -73,6 +73,7 @@ Discourse.CategoryList.reopenClass({ can_create_category: result.category_list.can_create_category, can_create_topic: result.category_list.can_create_topic, draft_key: result.category_list.draft_key, + draft: result.category_list.draft, draft_sequence: result.category_list.draft_sequence }); }); diff --git a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 index 099746bc3e3..04e90b4f3c4 100644 --- a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 @@ -85,6 +85,8 @@ export default function(filter, params) { this.controllerFor('search').set('searchContext', model.get('searchContext')); this.set('topics', null); + + this.openTopicDraft(topics); }, renderTemplate: function() { diff --git a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 index 267a5738df4..7804d700855 100644 --- a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 @@ -59,18 +59,7 @@ export default function(filter) { selected: [] }); - // If there's a draft, open the create topic composer - if (model.draft) { - var composer = this.controllerFor('composer'); - if (!composer.get('model.viewOpen')) { - composer.open({ - action: Discourse.Composer.CREATE_TOPIC, - draft: model.draft, - draftKey: model.draft_key, - draftSequence: model.draft_sequence - }); - } - } + this.openTopicDraft(model); this.controllerFor('navigation/default').set('canCreateTopic', model.get('can_create_topic')); }, diff --git a/app/assets/javascripts/discourse/routes/discourse_route.js b/app/assets/javascripts/discourse/routes/discourse_route.js index 41062fa152c..1db776cc78c 100644 --- a/app/assets/javascripts/discourse/routes/discourse_route.js +++ b/app/assets/javascripts/discourse/routes/discourse_route.js @@ -19,6 +19,21 @@ Discourse.Route = Em.Route.extend({ activate: function() { this._super(); Em.run.scheduleOnce('afterRender', Discourse.Route, 'cleanDOM'); + }, + + openTopicDraft: function(model){ + // If there's a draft, open the create topic composer + if (model.draft) { + var composer = this.controllerFor('composer'); + if (!composer.get('model.viewOpen')) { + composer.open({ + action: Discourse.Composer.CREATE_TOPIC, + draft: model.draft, + draftKey: model.draft_key, + draftSequence: model.draft_sequence + }); + } + } } }); diff --git a/app/assets/javascripts/discourse/routes/discovery_categories_route.js b/app/assets/javascripts/discourse/routes/discovery_categories_route.js index 1c7ae9331e8..dbe476455b4 100644 --- a/app/assets/javascripts/discourse/routes/discovery_categories_route.js +++ b/app/assets/javascripts/discourse/routes/discovery_categories_route.js @@ -38,6 +38,9 @@ Discourse.DiscoveryCategoriesRoute = Discourse.Route.extend(Discourse.OpenCompos // Only show either the Create Category or Create Topic button this.controllerFor('navigation/categories').set('canCreateCategory', model.get('can_create_category')); this.controllerFor('navigation/categories').set('canCreateTopic', model.get('can_create_topic') && !model.get('can_create_category')); + + this.openTopicDraft(model); + }, actions: { diff --git a/app/assets/javascripts/discourse/routes/discovery_top_routes.js b/app/assets/javascripts/discourse/routes/discovery_top_routes.js index 456e2c70934..1626965da86 100644 --- a/app/assets/javascripts/discourse/routes/discovery_top_routes.js +++ b/app/assets/javascripts/discourse/routes/discovery_top_routes.js @@ -21,15 +21,7 @@ Discourse.DiscoveryTopRoute = Discourse.Route.extend(Discourse.OpenComposer, { this.controllerFor('discovery/top').setProperties({ model: model, category: null }); this.controllerFor('navigation/default').set('canCreateTopic', model.get('can_create_topic')); - // If there's a draft, open the create topic composer - if (model.draft) { - this.controllerFor('composer').open({ - action: Discourse.Composer.CREATE_TOPIC, - draft: model.draft, - draftKey: model.draft_key, - draftSequence: model.draft_sequence - }); - } + this.openTopicDraft(model); }, renderTemplate: function() {