discourse-subscriptions/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show.js.es6

48 lines
1.3 KiB
Plaintext
Raw Normal View History

2019-12-02 18:58:14 +11:00
import AdminProduct from "discourse/plugins/discourse-subscriptions/discourse/models/admin-product";
import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/models/admin-plan";
2019-10-15 09:40:49 +11:00
export default Discourse.Route.extend({
2019-10-16 14:15:01 +11:00
model(params) {
2019-10-25 14:00:59 +11:00
const product_id = params["product-id"];
2019-10-16 14:15:01 +11:00
let product;
2019-10-21 15:28:45 +11:00
let plans = [];
2019-10-16 14:15:01 +11:00
2019-10-25 14:00:59 +11:00
if (product_id === "new") {
2019-12-05 17:07:26 +11:00
product = AdminProduct.create({ active: false, isNew: true });
2019-10-25 14:00:59 +11:00
} else {
2019-10-21 15:28:45 +11:00
product = AdminProduct.find(product_id);
plans = AdminPlan.findAll({ product_id });
2019-10-16 14:15:01 +11:00
}
2019-10-23 11:50:54 +11:00
return Ember.RSVP.hash({ plans, product });
2019-10-22 15:45:51 +11:00
},
2019-10-22 19:32:36 +11:00
actions: {
destroyPlan(plan) {
bootbox.confirm(
2019-12-04 09:35:07 +11:00
I18n.t(
"discourse_subscriptions.admin.plans.operations.destroy.confirm"
),
2019-10-22 19:32:36 +11:00
I18n.t("no_value"),
I18n.t("yes_value"),
confirmed => {
if (confirmed) {
2019-10-25 14:00:59 +11:00
plan
.destroy()
.then(() => {
2019-12-03 10:52:46 +11:00
this.controllerFor(
"adminPluginsDiscourseSubscriptionsProductsShow"
)
2019-10-25 14:00:59 +11:00
.get("model.plans")
.removeObject(plan);
})
.catch(data =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
);
2019-10-22 19:32:36 +11:00
}
}
);
}
}
2019-10-15 09:40:49 +11:00
});