mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Allow choice of category when making a PM public (#7907)
* FEATURE: Allow choice of category when making a PM public Previously it would default to uncategorized, which was not ideal on some forums. This gives the staff member more choice about what they'd like to do. * Make the optional category more explicit * Joffrey's feedback
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
||||
|
||||
export default Ember.Controller.extend(ModalFunctionality, {
|
||||
publicCategoryId: null,
|
||||
saving: true,
|
||||
|
||||
onShow() {
|
||||
this.setProperties({ publicCategoryId: null, saving: false });
|
||||
},
|
||||
|
||||
actions: {
|
||||
makePublic() {
|
||||
let topic = this.model;
|
||||
topic
|
||||
.convertTopic("public", { categoryId: this.publicCategoryId })
|
||||
.then(() => {
|
||||
topic.set("archetype", "regular");
|
||||
topic.set("category_id", this.publicCategoryId);
|
||||
this.appEvents.trigger("header:show-topic", topic);
|
||||
this.send("closeModal");
|
||||
})
|
||||
.catch(popupAjaxError);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1073,11 +1073,17 @@ export default Ember.Controller.extend(bufferedProperty("model"), {
|
||||
},
|
||||
|
||||
convertToPublicTopic() {
|
||||
this.model.convertTopic("public");
|
||||
showModal("convert-to-public-topic", {
|
||||
model: this.model,
|
||||
modalClass: "convert-to-public-topic"
|
||||
});
|
||||
},
|
||||
|
||||
convertToPrivateMessage() {
|
||||
this.model.convertTopic("private");
|
||||
this.model
|
||||
.convertTopic("private")
|
||||
.then(() => window.location.reload())
|
||||
.catch(popupAjaxError);
|
||||
},
|
||||
|
||||
removeFeaturedLink() {
|
||||
|
||||
@@ -599,10 +599,12 @@ const Topic = RestModel.extend({
|
||||
});
|
||||
},
|
||||
|
||||
convertTopic(type) {
|
||||
return ajax(`/t/${this.id}/convert-topic/${type}`, { type: "PUT" })
|
||||
.then(() => window.location.reload())
|
||||
.catch(popupAjaxError);
|
||||
convertTopic(type, opts) {
|
||||
let args = { type: "PUT" };
|
||||
if (opts && opts.categoryId) {
|
||||
args.data = { category_id: opts.categoryId };
|
||||
}
|
||||
return ajax(`/t/${this.id}/convert-topic/${type}`, args);
|
||||
},
|
||||
|
||||
resetBumpDate() {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{{#d-modal-body title="topic.make_public.title"}}
|
||||
|
||||
<div class='instructions'>
|
||||
{{i18n "topic.make_public.choose_category"}}
|
||||
</div>
|
||||
{{category-chooser value=publicCategoryId}}
|
||||
|
||||
{{/d-modal-body}}
|
||||
|
||||
<div class='modal-footer'>
|
||||
{{d-button class="btn-primary" action=(action "makePublic") label="composer.modal_ok" disabled=saving}}
|
||||
{{d-modal-cancel close=(route-action "closeModal")}}
|
||||
</div>
|
||||
@@ -0,0 +1,5 @@
|
||||
.convert-to-public-topic .modal-body {
|
||||
.instructions {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
}
|
||||
@@ -821,7 +821,7 @@ class TopicsController < ApplicationController
|
||||
guardian.ensure_can_convert_topic!(topic)
|
||||
|
||||
if params[:type] == "public"
|
||||
converted_topic = topic.convert_to_public_topic(current_user)
|
||||
converted_topic = topic.convert_to_public_topic(current_user, category_id: params[:category_id])
|
||||
else
|
||||
converted_topic = topic.convert_to_private_message(current_user)
|
||||
end
|
||||
|
||||
@@ -1307,8 +1307,8 @@ class Topic < ActiveRecord::Base
|
||||
builder.query_single.first.to_i
|
||||
end
|
||||
|
||||
def convert_to_public_topic(user)
|
||||
public_topic = TopicConverter.new(self, user).convert_to_public_topic
|
||||
def convert_to_public_topic(user, category_id: nil)
|
||||
public_topic = TopicConverter.new(self, user).convert_to_public_topic(category_id)
|
||||
add_small_action(user, "public_topic") if public_topic
|
||||
public_topic
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user