Files
discourse-subscriptions/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions.js
T

67 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-06-02 13:15:03 -05:00
import Controller from "@ember/controller";
2024-01-16 17:51:44 +01:00
import { action } from "@ember/object";
2024-11-19 10:31:14 +00:00
import { service } from "@ember/service";
2022-10-17 14:42:40 -04:00
import { htmlSafe } from "@ember/template";
2024-01-16 17:51:44 +01:00
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import discourseComputed from "discourse-common/utils/decorators";
import I18n from "I18n";
2021-06-02 13:15:03 -05:00
2024-11-29 15:42:50 +00:00
export default class AdminPluginsDiscourseSubscriptionsController extends Controller {
@service dialog;
loading = false;
2021-06-02 13:15:03 -05:00
@discourseComputed
stripeConfigured() {
return !!this.siteSettings.discourse_subscriptions_public_key;
2024-11-29 15:42:50 +00:00
}
2021-06-02 13:15:03 -05:00
@discourseComputed
campaignEnabled() {
return this.siteSettings.discourse_subscriptions_campaign_enabled;
2024-11-29 15:42:50 +00:00
}
2021-06-02 13:15:03 -05:00
@discourseComputed
campaignProductSet() {
return !!this.siteSettings.discourse_subscriptions_campaign_product;
2024-11-29 15:42:50 +00:00
}
2021-06-02 13:15:03 -05:00
@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")
2021-06-02 13:15:03 -05:00
);
});
2024-11-29 15:42:50 +00:00
}
2021-06-02 13:15:03 -05:00
@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: () => {
2021-06-02 13:15:03 -05:00
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"),
});
2021-06-02 13:15:03 -05:00
})
.catch(popupAjaxError);
2022-10-17 14:42:40 -04:00
},
});
2024-11-29 15:42:50 +00:00
}
}