destroy plans
This commit is contained in:
parent
1bedc1ba2f
commit
e2f1f0f523
|
@ -8,8 +8,14 @@ module DiscoursePatrons
|
||||||
before_action :set_api_key
|
before_action :set_api_key
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
begin
|
||||||
plans = ::Stripe::Plan.list
|
plans = ::Stripe::Plan.list
|
||||||
|
|
||||||
render_json_dump plans.data
|
render_json_dump plans.data
|
||||||
|
|
||||||
|
rescue ::Stripe::InvalidRequestError => e
|
||||||
|
return render_json_error e.message
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -31,8 +37,14 @@ module DiscoursePatrons
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
begin
|
||||||
plan = ::Stripe::Plan.delete(params[:id])
|
plan = ::Stripe::Plan.delete(params[:id])
|
||||||
|
|
||||||
render_json_dump plan
|
render_json_dump plan
|
||||||
|
|
||||||
|
rescue ::Stripe::InvalidRequestError => e
|
||||||
|
return render_json_error e.message
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -6,7 +6,9 @@ const AdminPlan = Discourse.Model.extend({
|
||||||
amount: 0,
|
amount: 0,
|
||||||
intervals: ["day", "week", "month", "year"],
|
intervals: ["day", "week", "month", "year"],
|
||||||
|
|
||||||
destroy() {},
|
destroy() {
|
||||||
|
return ajax(`/patrons/admin/plans/${this.id}`, { method: "delete" });
|
||||||
|
},
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
const data = {
|
const data = {
|
||||||
|
@ -20,7 +22,7 @@ const AdminPlan = Discourse.Model.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
AdminPlan.reopenClass({
|
AdminPlan.reopenClass({
|
||||||
find() {
|
findAll() {
|
||||||
return ajax("/patrons/admin/plans", { method: "get" }).then(result =>
|
return ajax("/patrons/admin/plans", { method: "get" }).then(result =>
|
||||||
result.map(plan => AdminPlan.create(plan))
|
result.map(plan => AdminPlan.create(plan))
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,7 +2,7 @@ import AdminPlan from "discourse/plugins/discourse-patrons/discourse/models/admi
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
model() {
|
model() {
|
||||||
return AdminPlan.find();
|
return AdminPlan.findAll();
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -13,9 +13,12 @@ export default Discourse.Route.extend({
|
||||||
I18n.t("yes_value"),
|
I18n.t("yes_value"),
|
||||||
confirmed => {
|
confirmed => {
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
|
plan.destroy().then(() => {
|
||||||
this.controllerFor("adminPluginsDiscoursePatronsPlansIndex")
|
this.controllerFor("adminPluginsDiscoursePatronsPlansIndex")
|
||||||
.get("model")
|
.get("model")
|
||||||
.removeObject(plan);
|
.removeObject(plan);
|
||||||
|
})
|
||||||
|
.catch(data => bootbox.alert(data.jqXHR.responseJSON.errors.join("\n")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -68,7 +68,7 @@ en:
|
||||||
active: Active
|
active: Active
|
||||||
product:
|
product:
|
||||||
product_id: Product ID
|
product_id: Product ID
|
||||||
group: Group
|
group: User Group
|
||||||
active: Active
|
active: Active
|
||||||
operations:
|
operations:
|
||||||
destroy:
|
destroy:
|
||||||
|
|
Loading…
Reference in New Issue