2018-06-15 11:03:24 -04:00
|
|
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2019-10-30 16:13:48 -04:00
|
|
|
import Mixin from "@ember/object/mixin";
|
2020-03-06 12:36:56 -05:00
|
|
|
import { next } from "@ember/runloop";
|
2019-11-05 11:37:32 -05:00
|
|
|
import { Promise } from "rsvp";
|
2018-01-30 16:31:29 -05:00
|
|
|
|
2019-10-30 15:03:08 -04:00
|
|
|
export default Mixin.create(ModalFunctionality, {
|
2018-01-30 16:31:29 -05:00
|
|
|
reason: null,
|
|
|
|
message: null,
|
|
|
|
postEdit: null,
|
|
|
|
postAction: null,
|
|
|
|
user: null,
|
2019-01-03 12:03:01 -05:00
|
|
|
postId: null,
|
2018-01-30 16:31:29 -05:00
|
|
|
successCallback: null,
|
2020-03-06 12:36:56 -05:00
|
|
|
confirmClose: false,
|
2018-01-30 16:31:29 -05:00
|
|
|
|
|
|
|
resetModal() {
|
|
|
|
this.setProperties({
|
|
|
|
reason: null,
|
|
|
|
message: null,
|
|
|
|
loadingUser: true,
|
2019-01-03 12:03:01 -05:00
|
|
|
postId: null,
|
2018-01-30 16:31:29 -05:00
|
|
|
postEdit: null,
|
2018-06-15 11:03:24 -04:00
|
|
|
postAction: "delete",
|
2018-01-30 16:31:29 -05:00
|
|
|
before: null,
|
2020-03-06 12:36:56 -05:00
|
|
|
successCallback: null,
|
|
|
|
confirmClose: false
|
2018-01-30 16:31:29 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-03-06 12:36:56 -05: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-30 16:31:29 -05:00
|
|
|
penalize(cb) {
|
2019-05-27 04:15:39 -04:00
|
|
|
let before = this.before;
|
2019-11-05 11:37:32 -05:00
|
|
|
let promise = before ? before() : Promise.resolve();
|
2018-01-30 16:31:29 -05:00
|
|
|
|
|
|
|
return promise
|
|
|
|
.then(() => cb())
|
|
|
|
.then(result => {
|
2020-03-06 12:36:56 -05:00
|
|
|
this.set("confirmClose", true);
|
2018-06-15 11:03:24 -04:00
|
|
|
this.send("closeModal");
|
2019-05-27 04:15:39 -04:00
|
|
|
let callback = this.successCallback;
|
2018-01-30 16:31:29 -05:00
|
|
|
if (callback) {
|
|
|
|
callback(result);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
}
|
|
|
|
});
|