0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-12-02 05:21:10 +01:00
discourse-custom-wizard/assets/javascripts/discourse/models/custom-wizard-notice.js.es6

75 Zeilen
1,8 KiB
Text

2021-09-24 11:58:42 +02:00
import EmberObject from "@ember/object";
2021-11-01 14:52:29 +01:00
import discourseComputed from "discourse-common/utils/decorators";
2021-09-24 11:58:42 +02:00
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
2021-11-01 14:52:29 +01:00
import { and, not, notEmpty } from "@ember/object/computed";
import { dasherize } from "@ember/string";
import I18n from "I18n";
2021-09-24 11:58:42 +02:00
2021-11-01 14:52:29 +01:00
const CustomWizardNotice = EmberObject.extend({
2021-11-17 13:48:11 +01:00
expired: notEmpty("expired_at"),
dismissed: notEmpty("dismissed_at"),
hidden: notEmpty("hidden_at"),
notHidden: not("hidden"),
notDismissed: not("dismissed"),
canDismiss: and("dismissable", "notDismissed"),
canHide: and("can_hide", "notHidden"),
2021-11-01 14:52:29 +01:00
2021-11-17 13:48:11 +01:00
@discourseComputed("type")
2021-11-01 14:52:29 +01:00
typeClass(type) {
return dasherize(type);
},
2021-11-17 13:48:11 +01:00
@discourseComputed("type")
2021-11-01 14:52:29 +01:00
typeLabel(type) {
return I18n.t(`admin.wizard.notice.type.${type}`);
},
2021-09-24 11:58:42 +02:00
dismiss() {
2021-11-17 13:48:11 +01:00
if (!this.get("canDismiss")) {
2021-11-01 14:52:29 +01:00
return;
}
2021-11-17 13:48:11 +01:00
return ajax(`/admin/wizards/notice/${this.get("id")}/dismiss`, {
type: "PUT",
})
.then((result) => {
if (result.success) {
this.set("dismissed_at", result.dismissed_at);
}
})
.catch(popupAjaxError);
2021-10-19 14:49:06 +02:00
},
2021-11-01 14:52:29 +01:00
hide() {
2021-11-17 13:48:11 +01:00
if (!this.get("canHide")) {
2021-11-01 14:52:29 +01:00
return;
}
2021-11-17 13:48:11 +01:00
return ajax(`/admin/wizards/notice/${this.get("id")}/hide`, { type: "PUT" })
.then((result) => {
if (result.success) {
this.set("hidden_at", result.hidden_at);
}
})
.catch(popupAjaxError);
},
2021-09-24 11:58:42 +02:00
});
CustomWizardNotice.reopenClass({
2021-11-01 14:52:29 +01:00
list(data = {}) {
2021-11-17 13:48:11 +01:00
return ajax("/admin/wizards/notice", {
2021-11-01 14:52:29 +01:00
type: "GET",
2021-11-17 13:48:11 +01:00
data,
2021-11-01 14:52:29 +01:00
}).catch(popupAjaxError);
2021-10-19 14:49:06 +02:00
},
2021-11-01 14:52:29 +01:00
dismissAll() {
2021-11-17 13:48:11 +01:00
return ajax("/admin/wizards/notice/dismiss", {
type: "PUT",
2021-11-01 14:52:29 +01:00
}).catch(popupAjaxError);
2021-11-17 13:48:11 +01:00
},
2021-09-24 11:58:42 +02:00
});
2021-10-19 14:49:06 +02:00
export default CustomWizardNotice;