2022-01-06 06:32:09 -05:00
|
|
|
import { action } from "@ember/object";
|
2024-01-16 11:51:44 -05:00
|
|
|
import Route from "@ember/routing/route";
|
2024-11-19 05:31:14 -05:00
|
|
|
import { service } from "@ember/service";
|
2024-01-16 11:51:44 -05:00
|
|
|
import { hash } from "rsvp";
|
|
|
|
import I18n from "I18n";
|
|
|
|
import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/models/admin-plan";
|
|
|
|
import AdminProduct from "discourse/plugins/discourse-subscriptions/discourse/models/admin-product";
|
2019-10-14 18:40:49 -04:00
|
|
|
|
2024-11-29 10:42:50 -05:00
|
|
|
export default class AdminPluginsDiscourseSubscriptionsProductsShowRoute extends Route {
|
|
|
|
@service dialog;
|
|
|
|
|
2019-10-15 23:15:01 -04:00
|
|
|
model(params) {
|
2019-10-24 23:00:59 -04:00
|
|
|
const product_id = params["product-id"];
|
2019-10-15 23:15:01 -04:00
|
|
|
let product;
|
2019-10-21 00:28:45 -04:00
|
|
|
let plans = [];
|
2019-10-15 23:15:01 -04:00
|
|
|
|
2019-10-24 23:00:59 -04:00
|
|
|
if (product_id === "new") {
|
2019-12-05 01:07:26 -05:00
|
|
|
product = AdminProduct.create({ active: false, isNew: true });
|
2019-10-24 23:00:59 -04:00
|
|
|
} else {
|
2019-10-21 00:28:45 -04:00
|
|
|
product = AdminProduct.find(product_id);
|
|
|
|
plans = AdminPlan.findAll({ product_id });
|
2019-10-15 23:15:01 -04:00
|
|
|
}
|
|
|
|
|
2020-05-28 11:32:57 -04:00
|
|
|
return hash({ plans, product });
|
2024-11-29 10:42:50 -05:00
|
|
|
}
|
2019-10-22 04:32:36 -04:00
|
|
|
|
2022-01-06 06:32:09 -05:00
|
|
|
@action
|
|
|
|
destroyPlan(plan) {
|
2022-10-17 14:42:40 -04:00
|
|
|
this.dialog.yesNoConfirm({
|
|
|
|
message: I18n.t(
|
|
|
|
"discourse_subscriptions.admin.plans.operations.destroy.confirm"
|
|
|
|
),
|
|
|
|
didConfirm: () => {
|
|
|
|
plan
|
|
|
|
.destroy()
|
|
|
|
.then(() => {
|
|
|
|
this.controllerFor("adminPluginsDiscourseSubscriptionsProductsShow")
|
|
|
|
.get("model.plans")
|
|
|
|
.removeObject(plan);
|
|
|
|
})
|
|
|
|
.catch((data) =>
|
|
|
|
this.dialog.alert(data.jqXHR.responseJSON.errors.join("\n"))
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2024-11-29 10:42:50 -05:00
|
|
|
}
|
|
|
|
}
|