2019-12-13 11:54:32 +11:00
|
|
|
import Route from "@ember/routing/route";
|
2019-12-02 18:58:14 +11:00
|
|
|
import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/models/admin-plan";
|
2019-10-23 11:50:54 +11:00
|
|
|
import Group from "discourse/models/group";
|
2020-05-28 10:32:57 -05:00
|
|
|
import { hash } from "rsvp";
|
2019-10-21 15:28:45 +11:00
|
|
|
|
2019-12-13 11:54:32 +11:00
|
|
|
export default Route.extend({
|
2019-10-21 15:28:45 +11:00
|
|
|
model(params) {
|
2019-10-25 14:00:59 +11:00
|
|
|
const id = params["plan-id"];
|
|
|
|
const product = this.modelFor(
|
2019-12-02 18:58:14 +11:00
|
|
|
"adminPlugins.discourse-subscriptions.products.show"
|
2019-10-25 14:00:59 +11:00
|
|
|
).product;
|
2019-10-22 15:45:51 +11:00
|
|
|
let plan;
|
|
|
|
|
2019-10-25 14:00:59 +11:00
|
|
|
if (id === "new") {
|
|
|
|
plan = AdminPlan.create({
|
|
|
|
active: true,
|
|
|
|
isNew: true,
|
2020-05-28 10:32:57 -05:00
|
|
|
interval: "month",
|
2020-07-22 11:06:34 -05:00
|
|
|
type: "recurring",
|
|
|
|
isRecurring: true,
|
2021-05-26 12:33:31 -07:00
|
|
|
currency: this.siteSettings.discourse_subscriptions_currency,
|
2020-09-16 09:53:50 -05:00
|
|
|
product: product.get("id"),
|
2020-11-24 14:52:00 -06:00
|
|
|
metadata: {
|
|
|
|
group_name: null,
|
|
|
|
},
|
2019-10-25 14:00:59 +11:00
|
|
|
});
|
|
|
|
} else {
|
2020-09-16 09:53:50 -05:00
|
|
|
plan = AdminPlan.find(id).then((result) => {
|
2020-07-28 11:56:58 -05:00
|
|
|
result.isRecurring = result.type === "recurring";
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|
2019-10-22 15:45:51 +11:00
|
|
|
}
|
|
|
|
|
2019-10-23 11:50:54 +11:00
|
|
|
const groups = Group.findAll({ ignore_automatic: true });
|
|
|
|
|
2020-05-28 10:32:57 -05:00
|
|
|
return hash({ plan, product, groups });
|
2019-10-22 15:45:51 +11:00
|
|
|
},
|
2019-10-21 15:28:45 +11:00
|
|
|
|
2019-10-23 10:36:12 +11:00
|
|
|
renderTemplate() {
|
2019-12-03 10:52:46 +11:00
|
|
|
this.render(
|
|
|
|
"adminPlugins.discourse-subscriptions.products.show.plans.show",
|
|
|
|
{
|
|
|
|
into: "adminPlugins.discourse-subscriptions.products",
|
|
|
|
outlet: "main",
|
|
|
|
controller:
|
2020-09-16 09:53:50 -05:00
|
|
|
"adminPlugins.discourse-subscriptions.products.show.plans.show",
|
2019-12-03 10:52:46 +11:00
|
|
|
}
|
|
|
|
);
|
2020-09-16 09:53:50 -05:00
|
|
|
},
|
2019-10-21 15:28:45 +11:00
|
|
|
});
|