2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2018-01-31 05:31:29 +08:00
|
|
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2019-10-31 04:13:48 +08:00
|
|
|
import Mixin from "@ember/object/mixin";
|
2020-03-07 01:36:56 +08:00
|
|
|
import { next } from "@ember/runloop";
|
2019-11-06 00:37:32 +08:00
|
|
|
import { Promise } from "rsvp";
|
2020-08-27 00:57:13 +08:00
|
|
|
import bootbox from "bootbox";
|
2018-01-31 05:31:29 +08:00
|
|
|
|
2019-10-31 03:03:08 +08:00
|
|
|
export default Mixin.create(ModalFunctionality, {
|
2018-01-31 05:31:29 +08:00
|
|
|
reason: null,
|
|
|
|
message: null,
|
|
|
|
postEdit: null,
|
|
|
|
postAction: null,
|
|
|
|
user: null,
|
2019-01-04 01:03:01 +08:00
|
|
|
postId: null,
|
2018-01-31 05:31:29 +08:00
|
|
|
successCallback: null,
|
2020-03-07 01:36:56 +08:00
|
|
|
confirmClose: false,
|
2018-01-31 05:31:29 +08:00
|
|
|
|
|
|
|
resetModal() {
|
|
|
|
this.setProperties({
|
|
|
|
reason: null,
|
|
|
|
message: null,
|
|
|
|
loadingUser: true,
|
2019-01-04 01:03:01 +08:00
|
|
|
postId: null,
|
2018-01-31 05:31:29 +08:00
|
|
|
postEdit: null,
|
|
|
|
postAction: "delete",
|
|
|
|
before: null,
|
2020-03-07 01:36:56 +08:00
|
|
|
successCallback: null,
|
|
|
|
confirmClose: false,
|
2018-01-31 05:31:29 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-03-07 01:36:56 +08:00
|
|
|
beforeClose() {
|
|
|
|
// prompt a confirmation if we have unsaved content
|
|
|
|
if (
|
|
|
|
!this.confirmClose &&
|
|
|
|
((this.reason && this.reason.length > 1) ||
|
|
|
|
(this.message && this.message.length > 1))
|
|
|
|
) {
|
|
|
|
this.send("hideModal");
|
|
|
|
bootbox.confirm(I18n.t("admin.user.confirm_cancel_penalty"), (result) => {
|
|
|
|
if (result) {
|
|
|
|
next(() => {
|
|
|
|
this.set("confirmClose", true);
|
|
|
|
this.send("closeModal");
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
next(() => this.send("reopenModal"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-01-31 05:31:29 +08:00
|
|
|
penalize(cb) {
|
2019-05-27 16:15:39 +08:00
|
|
|
let before = this.before;
|
2019-11-06 00:37:32 +08:00
|
|
|
let promise = before ? before() : Promise.resolve();
|
2018-01-31 05:31:29 +08:00
|
|
|
|
|
|
|
return promise
|
|
|
|
.then(() => cb())
|
|
|
|
.then((result) => {
|
2020-03-07 01:36:56 +08:00
|
|
|
this.set("confirmClose", true);
|
2018-01-31 05:31:29 +08:00
|
|
|
this.send("closeModal");
|
2019-05-27 16:15:39 +08:00
|
|
|
let callback = this.successCallback;
|
2018-01-31 05:31:29 +08:00
|
|
|
if (callback) {
|
|
|
|
callback(result);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
},
|
|
|
|
});
|