mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Merge pull request #3434 from techAPJ/patch-1
FEATURE: support category/subcategory name in new-topic route
This commit is contained in:
commit
4b1145dbb0
4 changed files with 22 additions and 4 deletions
|
@ -441,6 +441,23 @@ export default DiscourseController.extend({
|
||||||
|
|
||||||
if (opts.topicCategoryId) {
|
if (opts.topicCategoryId) {
|
||||||
this.set('model.categoryId', opts.topicCategoryId);
|
this.set('model.categoryId', opts.topicCategoryId);
|
||||||
|
} else if (opts.topicCategory) {
|
||||||
|
const splitCategory = opts.topicCategory.split("/");
|
||||||
|
let category;
|
||||||
|
|
||||||
|
if (!splitCategory[1]) {
|
||||||
|
category = this.site.get('categories').findProperty('nameLower', splitCategory[0].toLowerCase());
|
||||||
|
} else {
|
||||||
|
const categories = Discourse.Category.list();
|
||||||
|
const mainCategory = categories.findProperty('nameLower', splitCategory[0].toLowerCase());
|
||||||
|
category = categories.find(function(item) {
|
||||||
|
return item && item.get('nameLower') === splitCategory[1].toLowerCase() && item.get('parent_category_id') === mainCategory.id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (category) {
|
||||||
|
this.set('model.categoryId', category.get('id'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.topicBody) {
|
if (opts.topicBody) {
|
||||||
|
|
|
@ -17,12 +17,13 @@ Discourse.OpenComposer = Em.Mixin.create({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
openComposerWithParams: function(controller, title, body, category_id) {
|
openComposerWithParams: function(controller, title, body, category_id, category) {
|
||||||
this.controllerFor('composer').open({
|
this.controllerFor('composer').open({
|
||||||
action: Discourse.Composer.CREATE_TOPIC,
|
action: Discourse.Composer.CREATE_TOPIC,
|
||||||
topicTitle: title,
|
topicTitle: title,
|
||||||
topicBody: body,
|
topicBody: body,
|
||||||
topicCategoryId: category_id,
|
topicCategoryId: category_id,
|
||||||
|
topicCategory: category,
|
||||||
draftKey: controller.get('draft_key'),
|
draftKey: controller.get('draft_key'),
|
||||||
draftSequence: controller.get('draft_sequence')
|
draftSequence: controller.get('draft_sequence')
|
||||||
});
|
});
|
||||||
|
|
|
@ -148,8 +148,8 @@ const ApplicationRoute = Discourse.Route.extend(Discourse.OpenComposer, {
|
||||||
this.render(w, {into: 'modal/topic-bulk-actions', outlet: 'bulkOutlet', controller: factory ? controllerName : 'topic-bulk-actions'});
|
this.render(w, {into: 'modal/topic-bulk-actions', outlet: 'bulkOutlet', controller: factory ? controllerName : 'topic-bulk-actions'});
|
||||||
},
|
},
|
||||||
|
|
||||||
createNewTopicViaParams: function(title, body, category_id) {
|
createNewTopicViaParams: function(title, body, category_id, category) {
|
||||||
this.openComposerWithParams(this.controllerFor('discovery/topics'), title, body, category_id);
|
this.openComposerWithParams(this.controllerFor('discovery/topics'), title, body, category_id, category);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default Discourse.Route.extend({
|
||||||
if (self.controllerFor('navigation/default').get('canCreateTopic')) {
|
if (self.controllerFor('navigation/default').get('canCreateTopic')) {
|
||||||
// User can create topic
|
// User can create topic
|
||||||
Ember.run.next(function() {
|
Ember.run.next(function() {
|
||||||
e.send('createNewTopicViaParams', transition.queryParams.title, transition.queryParams.body, transition.queryParams.category_id);
|
e.send('createNewTopicViaParams', transition.queryParams.title, transition.queryParams.body, transition.queryParams.category_id, transition.queryParams.category);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue