diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-plans-index.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-plans-index.js.es6 index aee4af9..b6b536b 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-plans-index.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-plans-index.js.es6 @@ -1,20 +1,21 @@ import { ajax } from "discourse/lib/ajax"; -import computed from "ember-addons/ember-computed-decorators"; import DiscourseURL from "discourse/lib/url"; +import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan"; export default Ember.Controller.extend({ - @computed("model.plans") - plans(plans) { - return plans.filter(plan => !plan.deleted); - }, - actions: { - deletePlan(id) { - return ajax(`/patrons/admin/plans/${id}`, { method: "delete" }); + destroyPlan(plan) { + plan.destroy().then(() => + this.controllerFor("adminBackupsIndex") + .get("model") + .removeObject(backup) + ); }, editPlan(id) { - return DiscourseURL.redirectTo(`/admin/plugins/discourse-patrons/plans/${id}`); + return DiscourseURL.redirectTo( + `/admin/plugins/discourse-patrons/plans/${id}` + ); } } }); diff --git a/assets/javascripts/discourse/models/plan.js.es6 b/assets/javascripts/discourse/models/plan.js.es6 new file mode 100644 index 0000000..a2524a5 --- /dev/null +++ b/assets/javascripts/discourse/models/plan.js.es6 @@ -0,0 +1,14 @@ +import { ajax } from "discourse/lib/ajax"; + +const Plan = Discourse.Model.extend({ + destroy() { } +}); + +Plan.reopenClass({ + find() { + return ajax("/patrons/admin/plans", { method: "get" }) + .then(result => result.plans.map(plan => Plan.create(plan))); + } +}); + +export default Plan; diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-plans-index.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-plans-index.js.es6 index 9809f55..07ad8ff 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-plans-index.js.es6 +++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-plans-index.js.es6 @@ -1,7 +1,24 @@ -import { ajax } from "discourse/lib/ajax"; +import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan"; export default Discourse.Route.extend({ model() { - return ajax("/patrons/admin/plans", { method: "get" }); + return Plan.find(); + }, + + actions: { + destroyPlan(plan) { + bootbox.confirm( + I18n.t("discourse-patrons.plans.operations.destroy.confirm"), + I18n.t("no_value"), + I18n.t("yes_value"), + confirmed => { + if (confirmed) { + this.controllerFor("adminPluginsDiscoursePatronsPlansIndex") + .get("model") + .removeObject(plan); + } + } + ); + } } }); diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-plans.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-plans.js.es6 index 6408cd8..55af882 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-plans.js.es6 +++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-plans.js.es6 @@ -1,2 +1 @@ - export default Discourse.Route.extend({}); diff --git a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-plans-index.hbs b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-plans-index.hbs index 25fb0d1..d2aa9bc 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-plans-index.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-plans-index.hbs @@ -8,15 +8,22 @@