basic plans form

This commit is contained in:
Rimian Perkins 2019-10-15 09:40:49 +11:00
parent 892478ab57
commit b727347b6c
13 changed files with 123 additions and 24 deletions

View File

@ -4,7 +4,7 @@ export default Ember.Controller.extend({
actions: {
destroyPlan(plan) {
plan.destroy().then(() =>
this.controllerFor("adminBackupsIndex")
this.controllerFor("adminPluginsDiscoursePatronsPlansIndex")
.get("model")
.removeObject(plan)
);

View File

@ -0,0 +1,19 @@
import DiscourseURL from "discourse/lib/url";
export default Ember.Controller.extend({
actions: {
destroyProduct(product) {
product.destroy().then(() =>
this.controllerFor("adminPluginsDiscoursePatronsProductsIndex")
.get("model")
.removeObject(product)
);
},
editProduct(id) {
return DiscourseURL.redirectTo(
`/admin/plugins/discourse-patrons/products/${id}`
);
}
}
});

View File

@ -0,0 +1,14 @@
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Ember.Controller.extend({
actions: {
createPlan() {
this.get("model")
.save()
.then(() => {
this.transitionToRoute("adminPlugins.discourse-patrons.products");
})
.catch(popupAjaxError);
}
}
});

View File

@ -4,7 +4,9 @@ export default {
map() {
this.route("discourse-patrons", function() {
this.route("dashboard");
this.route("products");
this.route("products", function() {
this.route("show", { path: "/:plan-id" });
});
this.route("plans", function() {
this.route("show", { path: "/:plan-id" });
});

View File

@ -1,7 +1,22 @@
import { ajax } from "discourse/lib/ajax";
const AdminPlan = Discourse.Model.extend({
destroy() {}
name: "",
interval: "month",
amount: 0,
intervals: ["day", "week", "month", "year"],
destroy() {},
save() {
const data = {
interval: this.interval,
amount: this.amount,
name: this.name
};
return ajax("/patrons/admin/plans", { method: "post", data });
}
});
AdminPlan.reopenClass({

View File

@ -0,0 +1,21 @@
import { ajax } from "discourse/lib/ajax";
const AdminProduct = Discourse.Model.extend({
destroy() {},
save() {
const data = {};
return ajax("/patrons/admin/products", { method: "post", data });
}
});
AdminProduct.reopenClass({
find() {
return ajax("/patrons/admin/products", { method: "get" }).then(result =>
result.map(product => AdminProduct.create(product))
);
}
});
export default AdminProduct;

View File

@ -1,22 +1,7 @@
import { ajax } from "discourse/lib/ajax";
import AdminPlan from "discourse/plugins/discourse-patrons/discourse/models/admin-plan";
export default Discourse.Route.extend({
model() {
return Ember.Object.create({
name: "",
interval: "month",
amount: 0,
intervals: ["day", "week", "month", "year"],
save() {
const data = {
interval: this.interval,
amount: this.amount,
name: this.name
};
return ajax("/patrons/admin/plans", { method: "post", data });
}
});
return AdminPlan.create();
}
});

View File

@ -1 +1,7 @@
export default Discourse.Route.extend({});
import AdminProduct from "discourse/plugins/discourse-patrons/discourse/models/admin-plan";
export default Discourse.Route.extend({
model() {
return AdminProduct.create();
}
});

View File

@ -5,6 +5,7 @@
<th>{{i18n 'discourse_patrons.admin.plans.plan.nickname'}}</th>
<th>{{i18n 'discourse_patrons.admin.plans.plan.interval'}}</th>
<th>{{i18n 'discourse_patrons.admin.plans.plan.amount'}}</th>
<th></th>
</thead>
{{#each model as |plan|}}
<tr>
@ -12,7 +13,7 @@
<td>{{plan.nickname}}</td>
<td>{{plan.interval}}</td>
<td>{{plan.amount}}</td>
<td>
<td class="td-right">
{{d-button
action=(action "editPlan" plan.id)
icon="far-edit"

View File

@ -2,10 +2,22 @@
<table class="table discourse-patrons-admin">
<thead>
<th></th>
<th></th>
</thead>
{{#each model as |product|}}
<tr>
<td>{{product.id}}</td>
<td class="td-right">
{{d-button
action=(action "editProduct" product.id)
icon="far-edit"
class="btn no-text btn-icon"}}
{{d-button
action=(route-action "destroyProduct")
actionParam=product
icon="trash-alt"
class="btn-danger btn no-text btn-icon"}}
</td>
</tr>
{{/each}}
</table>

View File

@ -1,2 +1,17 @@
<h4>{{i18n 'discourse_patrons.admin.products.title'}}</h4>
<form class="form-horizontal">
<div>
<label for="name">{{i18n 'discourse_patrons.admin.plans.show.name'}}</label>
{{input type="text" name="name" value=model.name}}
</div>
<div>
<label for="interval">{{i18n 'discourse_patrons.admin.products.show.groups'}}</label>
{{combo-box valueAttribute="value" content=model.intervals value=model.interval}}
</div>
</form>
<div class="buttons">
{{d-button label="discourse_patrons.admin.products.show.create" action="createProduct" icon="plus"}}
</div>

View File

@ -0,0 +1,9 @@
<p class="btn-right">
{{#link-to 'adminPlugins.discourse-patrons.products.show' 'new' class="btn btn-primary"}}
{{d-icon "plus"}}
<span>{{i18n 'discourse_patrons.admin.products.new'}}</span>
{{/link-to}}
</p>
{{outlet}}

View File

@ -38,8 +38,8 @@
}
}
.discourse-patrons-admin {
.amount {
table.discourse-patrons-admin {
.td-right {
text-align: right;
}
}