discourse/app/assets/javascripts/admin/mixins/penalty-controller.js

Failed to ignore revisions in .git-blame-ignore-revs.

70 lines
1.7 KiB
JavaScript
Raw Normal View History

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