2021-08-10 08:45:23 +02:00
|
|
|
import Component from "@ember/component";
|
2021-09-24 11:58:42 +02:00
|
|
|
import CustomWizardSubscription from "../models/custom-wizard-subscription";
|
2021-08-10 08:45:23 +02:00
|
|
|
import { notEmpty } from "@ember/object/computed";
|
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2021-09-07 14:15:04 +02:00
|
|
|
import I18n from "I18n";
|
2021-08-10 08:45:23 +02:00
|
|
|
|
|
|
|
export default Component.extend({
|
2021-09-07 14:13:01 +02:00
|
|
|
classNameBindings: [
|
2021-09-24 11:58:42 +02:00
|
|
|
":custom-wizard-subscription",
|
2021-09-07 14:13:01 +02:00
|
|
|
"subscription.active:active:inactive",
|
|
|
|
],
|
|
|
|
subscribed: notEmpty("subscription"),
|
2021-08-10 08:45:23 +02:00
|
|
|
|
2021-09-07 14:13:01 +02:00
|
|
|
@discourseComputed("subscription.type")
|
2021-08-10 08:45:23 +02:00
|
|
|
title(type) {
|
2021-09-07 14:13:01 +02:00
|
|
|
return type
|
2021-09-24 11:58:42 +02:00
|
|
|
? I18n.t(`admin.wizard.subscription.subscription.title.${type}`)
|
|
|
|
: I18n.t("admin.wizard.subscription.not_subscribed");
|
2021-08-10 08:45:23 +02:00
|
|
|
},
|
|
|
|
|
2021-09-07 14:13:01 +02:00
|
|
|
@discourseComputed("subscription.active")
|
2021-08-10 08:45:23 +02:00
|
|
|
stateClass(active) {
|
2021-09-07 14:13:01 +02:00
|
|
|
return active ? "active" : "inactive";
|
2021-08-10 08:45:23 +02:00
|
|
|
},
|
|
|
|
|
2021-09-07 14:13:01 +02:00
|
|
|
@discourseComputed("stateClass")
|
2021-08-10 08:45:23 +02:00
|
|
|
stateLabel(stateClass) {
|
2021-10-19 14:49:06 +02:00
|
|
|
return I18n.t(
|
|
|
|
`admin.wizard.subscription.subscription.status.${stateClass}`
|
|
|
|
);
|
2021-08-10 08:45:23 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
update() {
|
2021-09-07 14:13:01 +02:00
|
|
|
this.set("updating", true);
|
2021-09-24 11:58:42 +02:00
|
|
|
CustomWizardSubscription.update()
|
2021-09-07 14:13:01 +02:00
|
|
|
.then((result) => {
|
|
|
|
if (result.success) {
|
|
|
|
this.setProperties({
|
|
|
|
updateIcon: "check",
|
|
|
|
subscription: result.subscription,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.set("updateIcon", "times");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.set("updating", false);
|
|
|
|
setTimeout(() => {
|
|
|
|
this.set("updateIcon", null);
|
|
|
|
}, 7000);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|