Merge pull request #3406 from techAPJ/patch-2
FEATURE: prefill topic title, body and category via URL
This commit is contained in:
commit
d7d93c20d7
|
@ -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);
|
||||
},
|
||||
|
||||
|
|
|
@ -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')
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -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'});
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@ function unlessReadOnly(method) {
|
|||
};
|
||||
}
|
||||
|
||||
const ApplicationRoute = Discourse.Route.extend({
|
||||
const ApplicationRoute = Discourse.Route.extend(Discourse.OpenComposer, {
|
||||
|
||||
siteTitle: Discourse.computed.setting('title'),
|
||||
|
||||
|
@ -146,6 +146,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);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
});
|
|
@ -415,6 +415,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+/}
|
||||
|
|
Loading…
Reference in New Issue