2019-10-15 06:50:30 -04:00
|
|
|
import AdminProduct from "discourse/plugins/discourse-patrons/discourse/models/admin-product";
|
2019-10-21 00:28:45 -04:00
|
|
|
import AdminPlan from "discourse/plugins/discourse-patrons/discourse/models/admin-plan";
|
2019-10-15 06:50:30 -04:00
|
|
|
import Group from "discourse/models/group";
|
2019-10-14 18:40:49 -04:00
|
|
|
|
|
|
|
export default Discourse.Route.extend({
|
2019-10-15 23:15:01 -04:00
|
|
|
model(params) {
|
2019-10-21 00:28:45 -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-21 00:28:45 -04:00
|
|
|
if(product_id === 'new') {
|
2019-10-15 23:15:01 -04:00
|
|
|
product = AdminProduct.create({ active: true, isNew: true });
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-10-15 06:50:30 -04:00
|
|
|
const groups = Group.findAll({ ignore_automatic: true });
|
|
|
|
|
2019-10-21 00:28:45 -04:00
|
|
|
return Ember.RSVP.hash({ plans, product, groups });
|
2019-10-22 00:45:51 -04:00
|
|
|
},
|
2019-10-22 04:32:36 -04:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
destroyPlan(plan) {
|
|
|
|
bootbox.confirm(
|
|
|
|
I18n.t("discourse_patrons.admin.plans.operations.destroy.confirm"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
|
|
|
confirmed => {
|
|
|
|
if (confirmed) {
|
|
|
|
plan.destroy().then(() => {
|
|
|
|
this.controllerFor("adminPluginsDiscoursePatronsProductsShow")
|
|
|
|
.get("model.plans")
|
|
|
|
.removeObject(plan);
|
|
|
|
})
|
|
|
|
.catch(data => bootbox.alert(data.jqXHR.responseJSON.errors.join("\n")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-10-14 18:40:49 -04:00
|
|
|
});
|