discourse-subscriptions/assets/javascripts/discourse/routes/user-billing-subscriptions....

40 lines
1.1 KiB
Plaintext
Raw Normal View History

2019-12-12 19:54:32 -05:00
import Route from "@ember/routing/route";
2019-12-02 02:58:14 -05:00
import UserSubscription from "discourse/plugins/discourse-subscriptions/discourse/models/user-subscription";
import I18n from "I18n";
2019-10-28 20:43:32 -04:00
2019-12-12 19:54:32 -05:00
export default Route.extend({
2019-12-15 18:42:55 -05:00
templateName: "user/billing/subscriptions",
2019-10-28 20:43:32 -04:00
model() {
2019-10-31 22:43:09 -04:00
return UserSubscription.findAll();
2019-10-28 20:43:32 -04:00
},
2019-10-30 19:01:41 -04:00
actions: {
cancelSubscription(subscription) {
bootbox.confirm(
2019-10-30 22:31:24 -04:00
I18n.t(
2019-12-03 17:29:13 -05:00
"discourse_subscriptions.user.subscriptions.operations.destroy.confirm"
2019-10-30 22:31:24 -04:00
),
2019-10-30 19:01:41 -04:00
I18n.t("no_value"),
I18n.t("yes_value"),
2020-09-16 10:53:50 -04:00
(confirmed) => {
2019-10-30 19:01:41 -04:00
if (confirmed) {
2019-11-13 22:07:45 -05:00
subscription.set("loading", true);
2019-10-30 19:01:41 -04:00
subscription
.destroy()
2020-09-16 10:53:50 -04:00
.then((result) => subscription.set("status", result.status))
.catch((data) =>
2019-10-30 19:01:41 -04:00
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
2019-11-13 22:07:45 -05:00
)
.finally(() => {
subscription.set("loading", false);
this.refresh();
2019-11-13 22:07:45 -05:00
});
2019-10-30 19:01:41 -04:00
}
}
);
2020-09-16 10:53:50 -04:00
},
},
2019-10-28 20:43:32 -04:00
});