discourse-subscriptions/assets/javascripts/discourse/controllers/admin-plugins-discourse-sub...

67 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-01-16 11:51:44 -05:00
import Controller from "@ember/controller";
import { action } from "@ember/object";
2024-11-19 05:31:14 -05:00
import { service } from "@ember/service";
2024-01-16 11:51:44 -05:00
import { htmlSafe } from "@ember/template";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import discourseComputed from "discourse-common/utils/decorators";
import I18n from "I18n";
export default Controller.extend({
loading: false,
2022-10-17 14:42:40 -04:00
dialog: service(),
@discourseComputed
stripeConfigured() {
return !!this.siteSettings.discourse_subscriptions_public_key;
},
@discourseComputed
campaignEnabled() {
return this.siteSettings.discourse_subscriptions_campaign_enabled;
},
@discourseComputed
campaignProductSet() {
return !!this.siteSettings.discourse_subscriptions_campaign_product;
},
@action
triggerManualRefresh() {
ajax(`/s/admin/refresh`, {
method: "post",
}).then(() => {
2022-10-17 14:42:40 -04:00
this.dialog.alert(
I18n.t("discourse_subscriptions.campaign.refresh_page")
);
});
},
@action
createOneClickCampaign() {
2022-10-17 14:42:40 -04:00
this.dialog.yesNoConfirm({
title: I18n.t("discourse_subscriptions.campaign.confirm_creation_title"),
message: htmlSafe(
I18n.t("discourse_subscriptions.campaign.confirm_creation")
),
didConfirm: () => {
this.set("loading", true);
ajax(`/s/admin/create-campaign`, {
method: "post",
})
.then(() => {
this.set("loading", false);
2022-10-17 14:42:40 -04:00
this.dialog.confirm({
message: I18n.t("discourse_subscriptions.campaign.created"),
shouldDisplayCancel: false,
didConfirm: () => this.send("showSettings"),
didCancel: () => this.send("showSettings"),
});
})
.catch(popupAjaxError);
2022-10-17 14:42:40 -04:00
},
});
},
});