0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-29 12:20:27 +01:00
discourse-custom-wizard/assets/javascripts/discourse/controllers/admin-wizards-subscription.js.es6

63 Zeilen
1,7 KiB
Text

import Controller from "@ember/controller";
import discourseComputed from "discourse-common/utils/decorators";
2021-09-24 11:58:42 +02:00
import CustomWizardSubscription from "../models/custom-wizard-subscription";
import { alias } from "@ember/object/computed";
export default Controller.extend({
messageUrl: "https://thepavilion.io/t/3652",
2021-09-07 14:13:01 +02:00
messageType: "info",
messageKey: null,
2021-09-07 14:13:01 +02:00
showSubscription: alias("model.authentication.active"),
setup() {
2021-09-07 14:13:01 +02:00
const authentication = this.get("model.authentication");
const subscription = this.get("model.subscription");
const subscribed = subscription && subscription.active;
const authenticated = authentication && authentication.active;
if (!subscribed) {
2021-09-07 14:13:01 +02:00
this.set("messageKey", authenticated ? "not_subscribed" : "authorize");
} else {
2021-09-07 14:13:01 +02:00
this.set(
"messageKey",
!authenticated
? "subscription_expiring"
: subscribed
? "subscription_active"
: "subscription_inactive"
);
}
},
2021-09-07 14:13:01 +02:00
@discourseComputed("model.server")
messageOpts(server) {
return { server };
},
actions: {
unauthorize() {
2021-09-07 14:13:01 +02:00
this.set("unauthorizing", true);
2021-10-05 14:54:06 +02:00
CustomWizardSubscription.unauthorize()
2021-09-07 14:13:01 +02:00
.then((result) => {
if (result.success) {
this.setProperties({
messageKey: "unauthorized",
messageType: "warn",
"model.authentication": null,
"model.subscription": null,
});
} else {
this.setProperties({
messageKey: "unauthorize_failed",
messageType: "error",
});
}
})
.finally(() => {
this.set("unauthorizing", false);
});
},
},
});