Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: prefill topic title, body and category via URL #3406

Merged
merged 1 commit into from Apr 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/assets/javascripts/discourse/controllers/composer.js.es6
Expand Up @@ -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);
},

Expand Down
12 changes: 11 additions & 1 deletion app/assets/javascripts/discourse/mixins/open_composer.js
Expand Up @@ -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')
});
}

});

2 changes: 2 additions & 0 deletions app/assets/javascripts/discourse/routes/app-route-map.js.es6
Expand Up @@ -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'});
});
Expand Down
6 changes: 5 additions & 1 deletion app/assets/javascripts/discourse/routes/application.js.es6
Expand Up @@ -10,7 +10,7 @@ function unlessReadOnly(method) {
};
}

const ApplicationRoute = Discourse.Route.extend({
const ApplicationRoute = Discourse.Route.extend(Discourse.OpenComposer, {

siteTitle: Discourse.computed.setting('title'),

Expand Down Expand Up @@ -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);
}
},

Expand Down
19 changes: 19 additions & 0 deletions 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');
}
}
});
2 changes: 2 additions & 0 deletions config/routes.rb
Expand Up @@ -411,6 +411,8 @@
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+/}
Expand Down