This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/controllers/change-post-notice.js
2020-12-01 15:31:26 -03:00

59 lines
1.3 KiB
JavaScript

import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import { action } from "@ember/object";
import { cookAsync } from "discourse/lib/text";
import discourseComputed from "discourse-common/utils/decorators";
import { isEmpty } from "@ember/utils";
export default Controller.extend(ModalFunctionality, {
post: null,
resolve: null,
reject: null,
notice: null,
saving: false,
@discourseComputed("saving", "notice")
disabled(saving, notice) {
return saving || isEmpty(notice);
},
onShow() {
this.setProperties({ notice: "", saving: false });
},
onClose() {
if (this.reject) {
this.reject();
}
},
@action
setNotice(notice) {
const { resolve, reject } = this;
this.setProperties({ saving: true, resolve: null, reject: null });
this.model
.updatePostField("notice", notice)
.then(() => {
if (notice) {
return cookAsync(notice, { features: { onebox: false } });
}
})
.then((cooked) =>
this.model.set(
"notice",
cooked
? {
type: "custom",
raw: notice,
cooked: cooked.string,
}
: null
)
)
.then(resolve, reject)
.finally(() => this.send("closeModal"));
},
});