This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/controllers/delete-topic-confirm.js
jbrw a8c63ddb54
FIX: Call _clearFlash() when displaying a modal (#14848)
`d-modal-body.js` was setting the text of a `modal-alert` element to `""`, but not removing any classes on that element. Changing this to call `_clearFlash()` ensures that a variety of styling classes are also removed from the element, which prevents empty alert elements being included on any subsequent modals that are displayed.

Several other controllers have also been modified to change the class of the error from `alert-error` to `error. The `alert-` is unnecessary, as it is added by `_flash(msg)` within `d-modal-body.js`.
2021-11-09 17:51:50 -05:00

39 lines
1.1 KiB
JavaScript

import Controller, { inject as controller } from "@ember/controller";
import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import { action } from "@ember/object";
import discourseComputed from "discourse-common/utils/decorators";
// Modal that displays confirmation text when user deletes a topic
// The modal will display only if the topic exceeds a certain amount of views
export default Controller.extend(ModalFunctionality, {
topicController: controller("topic"),
deletingTopic: false,
@discourseComputed("deletingTopic")
buttonTitle(deletingTopic) {
return deletingTopic
? I18n.t("deleting")
: I18n.t("post.controls.delete_topic_confirm_modal_yes");
},
onShow() {
this.set("deletingTopic", false);
},
@action
deleteTopic() {
this.set("deletingTopic", true);
this.topicController.model
.destroy(this.currentUser)
.then(() => this.send("closeModal"))
.catch(() => {
this.flash(I18n.t("post.controls.delete_topic_error"), "error");
this.set("deletingTopic", false);
});
return false;
},
});