0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00
discourse-custom-wizard/assets/javascripts/discourse/controllers/admin-wizards-notices.js.es6

69 Zeilen
1,8 KiB
Text

2021-11-01 14:52:29 +01:00
import Controller from "@ember/controller";
import CustomWizardNotice from "../models/custom-wizard-notice";
import discourseComputed from "discourse-common/utils/decorators";
import { notEmpty } from "@ember/object/computed";
import { A } from "@ember/array";
import I18n from "I18n";
export default Controller.extend({
messageUrl: "https://thepavilion.io/t/3652",
messageKey: "info",
messageIcon: "info-circle",
messageClass: "info",
hasNotices: notEmpty("notices"),
page: 0,
loadingMore: false,
canLoadMore: true,
2021-11-17 13:48:11 +01:00
@discourseComputed("notices.[]", "notices.@each.dismissed")
2021-11-01 14:52:29 +01:00
allDismisssed(notices) {
2021-11-17 13:48:11 +01:00
return notices.every((n) => !n.canDismiss || n.dismissed);
2021-11-01 14:52:29 +01:00
},
loadMoreNotices() {
if (!this.canLoadMore) {
return;
}
const page = this.get("page");
this.set("loadingMore", true);
CustomWizardNotice.list({ page, include_all: true })
.then((result) => {
if (result.notices.length === 0) {
this.set("canLoadMore", false);
return;
}
this.get("notices").pushObjects(
2021-11-17 13:48:11 +01:00
A(result.notices.map((notice) => CustomWizardNotice.create(notice)))
2021-11-01 14:52:29 +01:00
);
})
.finally(() => this.set("loadingMore", false));
},
actions: {
loadMore() {
if (this.canLoadMore) {
this.set("page", this.page + 1);
this.loadMoreNotices();
}
},
dismissAll() {
bootbox.confirm(
I18n.t("admin.wizard.notice.dismiss_all.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
(result) => {
if (result) {
2021-11-17 13:48:11 +01:00
this.set("loadingMore", true);
CustomWizardNotice.dismissAll().finally(() =>
this.set("loadingMore", false)
);
2021-11-01 14:52:29 +01:00
}
}
);
2021-11-17 13:48:11 +01:00
},
},
2021-11-01 14:52:29 +01:00
});