DEV: Convert `convert-to-public-topic` modal to component-based API (#22835)
This commit is contained in:
parent
99e05b1280
commit
106a0498f1
|
@ -0,0 +1,29 @@
|
||||||
|
<DModal
|
||||||
|
@title={{i18n "topic.make_public.title"}}
|
||||||
|
@closeModal={{@closeModal}}
|
||||||
|
class="convert-to-public-topic"
|
||||||
|
@flash={{this.flash}}
|
||||||
|
>
|
||||||
|
<:body>
|
||||||
|
<div class="instructions">
|
||||||
|
{{i18n "topic.make_public.choose_category"}}
|
||||||
|
</div>
|
||||||
|
<CategoryChooser
|
||||||
|
@value={{this.publicCategoryId}}
|
||||||
|
@onChange={{action (mut this.publicCategoryId)}}
|
||||||
|
/>
|
||||||
|
</:body>
|
||||||
|
<:footer>
|
||||||
|
<DButton
|
||||||
|
class="btn-primary"
|
||||||
|
@action={{this.makePublic}}
|
||||||
|
@label="composer.modal_ok"
|
||||||
|
@disabled={{this.saving}}
|
||||||
|
/>
|
||||||
|
<DButton
|
||||||
|
class="btn-flat d-modal-cancel"
|
||||||
|
@action={{@closeModal}}
|
||||||
|
@label="cancel"
|
||||||
|
/>
|
||||||
|
</:footer>
|
||||||
|
</DModal>
|
|
@ -0,0 +1,31 @@
|
||||||
|
import Component from "@glimmer/component";
|
||||||
|
import { tracked } from "@glimmer/tracking";
|
||||||
|
import { action } from "@ember/object";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
import I18n from "I18n";
|
||||||
|
|
||||||
|
export default class ConvertToPublicTopic extends Component {
|
||||||
|
@service appEvents;
|
||||||
|
|
||||||
|
@tracked publicCategoryId;
|
||||||
|
@tracked saving = false;
|
||||||
|
@tracked flash;
|
||||||
|
|
||||||
|
@action
|
||||||
|
async makePublic() {
|
||||||
|
try {
|
||||||
|
this.saving = true;
|
||||||
|
await this.args.model.topic.convertTopic("public", {
|
||||||
|
categoryId: this.publicCategoryId,
|
||||||
|
});
|
||||||
|
this.args.model.topic.set("archetype", "regular");
|
||||||
|
this.args.model.topic.set("category_id", this.publicCategoryId);
|
||||||
|
this.appEvents.trigger("header:show-topic", this.args.model.topic);
|
||||||
|
this.saving = false;
|
||||||
|
this.args.closeModal();
|
||||||
|
} catch (e) {
|
||||||
|
this.flash = I18n.t("generic_error");
|
||||||
|
this.saving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,27 +0,0 @@
|
||||||
import Controller from "@ember/controller";
|
|
||||||
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
||||||
|
|
||||||
export default 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);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -36,6 +36,7 @@ import showModal from "discourse/lib/show-modal";
|
||||||
import { spinnerHTML } from "discourse/helpers/loading-spinner";
|
import { spinnerHTML } from "discourse/helpers/loading-spinner";
|
||||||
import { BookmarkFormData } from "discourse/lib/bookmark";
|
import { BookmarkFormData } from "discourse/lib/bookmark";
|
||||||
import DeleteTopicConfirmModal from "discourse/components/modal/delete-topic-confirm";
|
import DeleteTopicConfirmModal from "discourse/components/modal/delete-topic-confirm";
|
||||||
|
import ConvertToPublicTopicModal from "discourse/components/modal/convert-to-public-topic";
|
||||||
|
|
||||||
let customPostMessageCallbacks = {};
|
let customPostMessageCallbacks = {};
|
||||||
|
|
||||||
|
@ -1185,9 +1186,8 @@ export default Controller.extend(bufferedProperty("model"), {
|
||||||
},
|
},
|
||||||
|
|
||||||
convertToPublicTopic() {
|
convertToPublicTopic() {
|
||||||
showModal("convert-to-public-topic", {
|
this.modal.show(ConvertToPublicTopicModal, {
|
||||||
model: this.model,
|
model: { topic: this.model },
|
||||||
modalClass: "convert-to-public-topic",
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ const KNOWN_LEGACY_MODALS = [
|
||||||
"change-owner",
|
"change-owner",
|
||||||
"change-post-notice",
|
"change-post-notice",
|
||||||
"change-timestamp",
|
"change-timestamp",
|
||||||
"convert-to-public-topic",
|
|
||||||
"create-account",
|
"create-account",
|
||||||
"create-invite-bulk",
|
"create-invite-bulk",
|
||||||
"create-invite",
|
"create-invite",
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
<DModalBody @title="topic.make_public.title">
|
|
||||||
|
|
||||||
<div class="instructions">
|
|
||||||
{{i18n "topic.make_public.choose_category"}}
|
|
||||||
</div>
|
|
||||||
<CategoryChooser
|
|
||||||
@value={{this.publicCategoryId}}
|
|
||||||
@onChange={{action (mut this.publicCategoryId)}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
</DModalBody>
|
|
||||||
|
|
||||||
<div class="modal-footer">
|
|
||||||
<DButton
|
|
||||||
@class="btn-primary"
|
|
||||||
@action={{action "makePublic"}}
|
|
||||||
@label="composer.modal_ok"
|
|
||||||
@disabled={{this.saving}}
|
|
||||||
/>
|
|
||||||
<DModalCancel @close={{route-action "closeModal"}} />
|
|
||||||
</div>
|
|
Loading…
Reference in New Issue