2019-10-31 13:37:24 -04:00
|
|
|
import { isEmpty } from "@ember/utils";
|
2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2018-06-15 11:03:24 -04:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
|
|
import PenaltyController from "admin/mixins/penalty-controller";
|
2017-11-13 13:41:36 -05:00
|
|
|
|
2019-10-23 13:06:54 -04:00
|
|
|
export default Controller.extend(PenaltyController, {
|
2017-11-13 13:41:36 -05:00
|
|
|
silenceUntil: null,
|
|
|
|
silencing: false,
|
|
|
|
|
|
|
|
onShow() {
|
2018-01-30 16:31:29 -05:00
|
|
|
this.resetModal();
|
|
|
|
this.setProperties({ silenceUntil: null, silencing: false });
|
2017-11-13 13:41:36 -05:00
|
|
|
},
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
@computed("silenceUntil", "reason", "silencing")
|
2017-11-13 13:41:36 -05:00
|
|
|
submitDisabled(silenceUntil, reason, silencing) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return (
|
2019-10-31 13:37:24 -04:00
|
|
|
silencing || isEmpty(silenceUntil) || !reason || reason.length < 1
|
2018-06-15 11:03:24 -04:00
|
|
|
);
|
2017-11-13 13:41:36 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
silence() {
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.submitDisabled) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return;
|
|
|
|
}
|
2017-11-13 13:41:36 -05:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("silencing", true);
|
2018-01-30 16:31:29 -05:00
|
|
|
this.penalize(() => {
|
2019-05-27 04:15:39 -04: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-30 16:31:29 -05:00
|
|
|
});
|
2018-06-15 11:03:24 -04:00
|
|
|
}).finally(() => this.set("silencing", false));
|
2017-11-13 13:41:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|