2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2019-10-30 16:13:48 -04:00
|
|
|
import Mixin from "@ember/object/mixin";
|
2020-03-06 12:36:56 -05:00
|
|
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
2019-11-05 11:37:32 -05:00
|
|
|
import { Promise } from "rsvp";
|
2020-11-03 10:38:56 -05:00
|
|
|
import { extractError } from "discourse/lib/ajax-error";
|
2020-03-06 12:36:56 -05:00
|
|
|
import { next } from "@ember/runloop";
|
2022-10-07 11:38:27 -04:00
|
|
|
import { inject as service } from "@ember/service";
|
2018-01-30 16:31:29 -05:00
|
|
|
|
2019-10-30 15:03:08 -04:00
|
|
|
export default Mixin.create(ModalFunctionality, {
|
2022-10-07 11:38:27 -04:00
|
|
|
dialog: service(),
|
2020-11-03 10:38:56 -05:00
|
|
|
errorMessage: null,
|
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({
|
2020-11-03 10:38:56 -05:00
|
|
|
errorMessage: null,
|
2018-01-30 16:31:29 -05:00
|
|
|
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,
|
|
|
|
postAction: "delete",
|
|
|
|
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");
|
2022-10-07 11:38:27 -04:00
|
|
|
this.dialog.confirm({
|
|
|
|
message: I18n.t("admin.user.confirm_cancel_penalty"),
|
|
|
|
didConfirm: () => {
|
2020-03-06 12:36:56 -05:00
|
|
|
next(() => {
|
|
|
|
this.set("confirmClose", true);
|
|
|
|
this.send("closeModal");
|
|
|
|
});
|
2022-10-07 11:38:27 -04:00
|
|
|
},
|
|
|
|
didCancel: () => this.send("reopenModal"),
|
2020-03-06 12:36:56 -05:00
|
|
|
});
|
|
|
|
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-01-30 16:31:29 -05: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);
|
|
|
|
}
|
|
|
|
})
|
2020-11-03 10:38:56 -05:00
|
|
|
.catch((error) => {
|
|
|
|
this.set("errorMessage", extractError(error));
|
|
|
|
});
|
2018-01-30 16:31:29 -05:00
|
|
|
},
|
|
|
|
});
|