diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index bdbe52b9c89..831c2217326 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -435,6 +435,21 @@ export default DiscourseController.extend({ composerModel.set('composeState', Discourse.Composer.OPEN); composerModel.set('isWarning', false); + if (opts.topicTitle && opts.topicTitle.length <= this.get('maxTitleLength')) { + this.set('model.title', opts.topicTitle); + } + + if (opts.topicCategory) { + var category = Discourse.Category.list().findProperty('name', opts.topicCategory); + if (category && category.id) { + this.set('model.categoryId', category.id); + } + } + + if (opts.topicBody) { + this.set('model.reply', opts.topicBody); + } + this.get('controllers.composer-messages').queryFor(composerModel); }, diff --git a/app/assets/javascripts/discourse/mixins/open_composer.js b/app/assets/javascripts/discourse/mixins/open_composer.js index 674dfb9a0d0..58acafb6f99 100644 --- a/app/assets/javascripts/discourse/mixins/open_composer.js +++ b/app/assets/javascripts/discourse/mixins/open_composer.js @@ -15,7 +15,17 @@ Discourse.OpenComposer = Em.Mixin.create({ draftKey: controller.get('draft_key'), draftSequence: controller.get('draft_sequence') }); + }, + + openComposerWithParams: function(controller, title, body, category) { + this.controllerFor('composer').open({ + action: Discourse.Composer.CREATE_TOPIC, + topicTitle: title, + topicBody: body, + topicCategory: category, + draftKey: controller.get('draft_key'), + draftSequence: controller.get('draft_sequence') + }); } }); - diff --git a/app/assets/javascripts/discourse/routes/app-route-map.js.es6 b/app/assets/javascripts/discourse/routes/app-route-map.js.es6 index 21d61cda211..c16efc9ed99 100644 --- a/app/assets/javascripts/discourse/routes/app-route-map.js.es6 +++ b/app/assets/javascripts/discourse/routes/app-route-map.js.es6 @@ -90,6 +90,8 @@ export default function() { this.route('privacy', {path: '/privacy'}); this.route('guidelines', {path: '/guidelines'}); + this.route('new-topic', {path: '/new-topic'}); + this.resource('badges', function() { this.route('show', {path: '/:id/:slug'}); }); diff --git a/app/assets/javascripts/discourse/routes/application.js.es6 b/app/assets/javascripts/discourse/routes/application.js.es6 index 55967c0dbd9..f48a49142ae 100644 --- a/app/assets/javascripts/discourse/routes/application.js.es6 +++ b/app/assets/javascripts/discourse/routes/application.js.es6 @@ -10,7 +10,7 @@ function unlessReadOnly(method) { }; } -const ApplicationRoute = Discourse.Route.extend({ +const ApplicationRoute = Discourse.Route.extend(Discourse.OpenComposer, { siteTitle: Discourse.computed.setting('title'), @@ -145,6 +145,10 @@ const ApplicationRoute = Discourse.Route.extend({ factory = this.container.lookupFactory('controller:' + controllerName); this.render(w, {into: 'modal/topic-bulk-actions', outlet: 'bulkOutlet', controller: factory ? controllerName : 'topic-bulk-actions'}); + }, + + createNewTopicViaParams: function(title, body, category) { + this.openComposerWithParams(this.controllerFor('discovery/topics'), title, body, category); } }, diff --git a/app/assets/javascripts/discourse/routes/new-topic.js.es6 b/app/assets/javascripts/discourse/routes/new-topic.js.es6 new file mode 100644 index 00000000000..c6c0ebcee55 --- /dev/null +++ b/app/assets/javascripts/discourse/routes/new-topic.js.es6 @@ -0,0 +1,19 @@ +export default Discourse.Route.extend({ + beforeModel: function(transition) { + const self = this; + if (Discourse.User.current()) { + // User is logged in + self.replaceWith('discovery.latest').then(function(e) { + if (self.controllerFor('navigation/default').get('canCreateTopic')) { + // User can create topic + Ember.run.next(function() { + e.send('createNewTopicViaParams', transition.queryParams.title, transition.queryParams.body, transition.queryParams.category); + }); + } + }); + } else { + // User is not logged in + self.replaceWith('login'); + } + } +}); diff --git a/config/routes.rb b/config/routes.rb index d71ecc3c5bb..677b9fd985c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -411,6 +411,8 @@ Discourse::Application.routes.draw do get 'embed/comments' => 'embed#comments' get 'embed/count' => 'embed#count' + get "new-topic" => "list#latest" + # Topic routes get "t/id_for/:slug" => "topics#id_for_slug" get "t/:slug/:topic_id/wordpress" => "topics#wordpress", constraints: {topic_id: /\d+/}