2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2018-01-31 05:31:29 +08:00
|
|
|
import PenaltyController from "admin/mixins/penalty-controller";
|
2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-11-01 01:37:24 +08:00
|
|
|
import { isEmpty } from "@ember/utils";
|
2017-11-14 02:41:36 +08:00
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend(PenaltyController, {
|
2017-11-14 02:41:36 +08:00
|
|
|
silenceUntil: null,
|
|
|
|
silencing: false,
|
|
|
|
|
|
|
|
onShow() {
|
2018-01-31 05:31:29 +08:00
|
|
|
this.resetModal();
|
|
|
|
this.setProperties({ silenceUntil: null, silencing: false });
|
2017-11-14 02:41:36 +08:00
|
|
|
},
|
|
|
|
|
2021-07-13 02:36:56 +08:00
|
|
|
finishedSetup() {
|
|
|
|
this.set("silenceUntil", this.user?.next_penalty);
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("silenceUntil", "reason", "silencing")
|
2017-11-14 02:41:36 +08:00
|
|
|
submitDisabled(silenceUntil, reason, silencing) {
|
2019-11-02 01:57:22 +08:00
|
|
|
return silencing || isEmpty(silenceUntil) || !reason || reason.length < 1;
|
2017-11-14 02:41:36 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
silence() {
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.submitDisabled) {
|
2017-11-14 02:41:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set("silencing", true);
|
2018-01-31 05:31:29 +08:00
|
|
|
this.penalize(() => {
|
2019-05-27 16:15:39 +08:00
|
|
|
return this.user.silence({
|
|
|
|
silenced_till: this.silenceUntil,
|
|
|
|
reason: this.reason,
|
|
|
|
message: this.message,
|
|
|
|
post_id: this.postId,
|
|
|
|
post_action: this.postAction,
|
|
|
|
post_edit: this.postEdit,
|
2018-01-31 05:31:29 +08:00
|
|
|
});
|
|
|
|
}).finally(() => this.set("silencing", false));
|
2017-11-14 02:41:36 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|