1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/discourse/models/custom-wizard-notice.js.es6

69 Zeilen
1,7 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({
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'),
@discourseComputed('type')
typeClass(type) {
return dasherize(type);
},
@discourseComputed('type')
typeLabel(type) {
return I18n.t(`admin.wizard.notice.type.${type}`);
},
2021-09-24 11:58:42 +02:00
dismiss() {
2021-11-01 14:52:29 +01:00
if (!this.get('canDismiss')) {
return;
}
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() {
if (!this.get('canHide')) {
return;
}
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 = {}) {
return ajax('/admin/wizards/notice', {
type: "GET",
data
}).catch(popupAjaxError);
2021-10-19 14:49:06 +02:00
},
2021-11-01 14:52:29 +01:00
dismissAll() {
return ajax('/admin/wizards/notice/dismiss', {
type: "PUT"
}).catch(popupAjaxError);
}
2021-09-24 11:58:42 +02:00
});
2021-10-19 14:49:06 +02:00
export default CustomWizardNotice;