plan model with destroy and find
This commit is contained in:
parent
6f9195a7d4
commit
19a03aa2ca
|
@ -1,20 +1,21 @@
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import computed from "ember-addons/ember-computed-decorators";
|
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
|
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
@computed("model.plans")
|
|
||||||
plans(plans) {
|
|
||||||
return plans.filter(plan => !plan.deleted);
|
|
||||||
},
|
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
deletePlan(id) {
|
destroyPlan(plan) {
|
||||||
return ajax(`/patrons/admin/plans/${id}`, { method: "delete" });
|
plan.destroy().then(() =>
|
||||||
|
this.controllerFor("adminBackupsIndex")
|
||||||
|
.get("model")
|
||||||
|
.removeObject(backup)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
editPlan(id) {
|
editPlan(id) {
|
||||||
return DiscourseURL.redirectTo(`/admin/plugins/discourse-patrons/plans/${id}`);
|
return DiscourseURL.redirectTo(
|
||||||
|
`/admin/plugins/discourse-patrons/plans/${id}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
|
@ -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({
|
export default Discourse.Route.extend({
|
||||||
model() {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
|
|
||||||
export default Discourse.Route.extend({});
|
export default Discourse.Route.extend({});
|
||||||
|
|
|
@ -8,15 +8,22 @@
|
||||||
<th>{{i18n 'discourse_patrons.admin.plans.plan.interval'}}</th>
|
<th>{{i18n 'discourse_patrons.admin.plans.plan.interval'}}</th>
|
||||||
<th>{{i18n 'discourse_patrons.admin.plans.plan.amount'}}</th>
|
<th>{{i18n 'discourse_patrons.admin.plans.plan.amount'}}</th>
|
||||||
</thead>
|
</thead>
|
||||||
{{#each plans as |plan|}}
|
{{#each model as |plan|}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{plan.id}}</td>
|
<td>{{plan.id}}</td>
|
||||||
<td>{{plan.nickname}}</td>
|
<td>{{plan.nickname}}</td>
|
||||||
<td>{{plan.interval}}</td>
|
<td>{{plan.interval}}</td>
|
||||||
<td>{{plan.amount}}</td>
|
<td>{{plan.amount}}</td>
|
||||||
<td>
|
<td>
|
||||||
{{d-button action=(action "editPlan" plan.id) icon="far-edit" class="btn no-text btn-icon"}}
|
{{d-button
|
||||||
{{d-button action=(action "deletePlan" plan.id) icon="trash-alt" class="btn-danger btn no-text btn-icon"}}
|
action=(action "editPlan" plan.id)
|
||||||
|
icon="far-edit"
|
||||||
|
class="btn no-text btn-icon"}}
|
||||||
|
{{d-button
|
||||||
|
action=(route-action "destroyPlan")
|
||||||
|
actionParam=plan
|
||||||
|
icon="trash-alt"
|
||||||
|
class="btn-danger btn no-text btn-icon"}}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
@ -60,5 +60,8 @@ en:
|
||||||
nickname: Nickname
|
nickname: Nickname
|
||||||
interval: Interval
|
interval: Interval
|
||||||
amount: Amount
|
amount: Amount
|
||||||
|
operations:
|
||||||
|
destroy:
|
||||||
|
confirm: Are you sure you want to destroy this plan?
|
||||||
subscriptions:
|
subscriptions:
|
||||||
title: Subscriptions
|
title: Subscriptions
|
||||||
|
|
Loading…
Reference in New Issue