save the product
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
export default Ember.Controller.extend({
|
||||
actions: {
|
||||
createPlan() {
|
||||
this.get("model")
|
||||
this.get("model.plan")
|
||||
.save()
|
||||
.then(() => {
|
||||
this.transitionToRoute("adminPlugins.discourse-patrons.plans");
|
||||
|
||||
+9
@@ -17,6 +17,15 @@ export default Ember.Controller.extend({
|
||||
this.transitionToRoute("adminPlugins.discourse-patrons.products");
|
||||
})
|
||||
.catch(popupAjaxError);
|
||||
},
|
||||
|
||||
updateProduct() {
|
||||
this.get("model.product")
|
||||
.update()
|
||||
.then(() => {
|
||||
this.transitionToRoute("adminPlugins.discourse-patrons.products");
|
||||
})
|
||||
.catch(popupAjaxError);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ export default {
|
||||
this.route("discourse-patrons", function() {
|
||||
this.route("dashboard");
|
||||
this.route("products", function() {
|
||||
this.route("show", { path: "/:plan-id" });
|
||||
this.route("show", { path: "/:product-id" });
|
||||
});
|
||||
this.route("plans", function() {
|
||||
this.route("show", { path: "/:plan-id" });
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
const AdminProduct = Discourse.Model.extend({
|
||||
isNew: false,
|
||||
|
||||
destroy() {
|
||||
return ajax(`/patrons/admin/products/${this.id}`, { method: "delete" });
|
||||
},
|
||||
@@ -13,6 +15,16 @@ const AdminProduct = Discourse.Model.extend({
|
||||
};
|
||||
|
||||
return ajax("/patrons/admin/products", { method: "post", data });
|
||||
},
|
||||
|
||||
update() {
|
||||
const data = {
|
||||
name: this.name,
|
||||
groupName: this.groupName,
|
||||
active: this.active
|
||||
};
|
||||
|
||||
return ajax(`/patrons/admin/products/${this.id}`, { method: "patch", data });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -21,7 +33,13 @@ AdminProduct.reopenClass({
|
||||
return ajax("/patrons/admin/products", { method: "get" }).then(result =>
|
||||
result.map(product => AdminProduct.create(product))
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
find(id) {
|
||||
return ajax(`/patrons/admin/products/${id}`, { method: "get" }).then(product =>
|
||||
AdminProduct.create(product)
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export default AdminProduct;
|
||||
|
||||
+5
-1
@@ -1,7 +1,11 @@
|
||||
import AdminPlan from "discourse/plugins/discourse-patrons/discourse/models/admin-plan";
|
||||
import AdminProduct from "discourse/plugins/discourse-patrons/discourse/models/admin-product";
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
model() {
|
||||
return AdminPlan.create();
|
||||
const plan = AdminPlan.create();
|
||||
const products = AdminProduct.findAll();
|
||||
|
||||
return Ember.RSVP.hash({ plan, products });
|
||||
}
|
||||
});
|
||||
|
||||
+11
-2
@@ -2,8 +2,17 @@ import AdminProduct from "discourse/plugins/discourse-patrons/discourse/models/a
|
||||
import Group from "discourse/models/group";
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
model(param) {
|
||||
const product = AdminProduct.create();
|
||||
model(params) {
|
||||
const id = params['product-id'];
|
||||
let product;
|
||||
|
||||
if(id === 'new') {
|
||||
product = AdminProduct.create({ active: true, isNew: true });
|
||||
}
|
||||
else {
|
||||
product = AdminProduct.find(id);
|
||||
}
|
||||
|
||||
const groups = Group.findAll({ ignore_automatic: true });
|
||||
|
||||
return Ember.RSVP.hash({ product, groups });
|
||||
|
||||
+13
-9
@@ -2,18 +2,22 @@
|
||||
<h4>{{i18n 'discourse_patrons.admin.plans.title'}}</h4>
|
||||
|
||||
<form class="form-horizontal">
|
||||
<div>
|
||||
<p>
|
||||
<label for="name">{{i18n 'discourse_patrons.admin.plans.show.name'}}</label>
|
||||
{{input type="text" name="name" value=model.name}}
|
||||
</div>
|
||||
<div>
|
||||
{{input type="text" name="name" value=model.plan.name}}
|
||||
</p>
|
||||
<p>
|
||||
<label for="amount">{{i18n 'discourse_patrons.admin.plans.show.amount'}}</label>
|
||||
{{input type="text" name="name" value=model.amount}}
|
||||
</div>
|
||||
<div>
|
||||
{{input type="text" name="name" value=model.plan.amount}}
|
||||
</p>
|
||||
<p>
|
||||
<label for="product">{{i18n 'discourse_patrons.admin.plans.show.product'}}</label>
|
||||
{{combo-box valueAttribute="value" content=model.products value=defaultProduct}}
|
||||
</p>
|
||||
<p>
|
||||
<label for="interval">{{i18n 'discourse_patrons.admin.plans.show.interval'}}</label>
|
||||
{{combo-box valueAttribute="value" content=model.intervals value=model.interval}}
|
||||
</div>
|
||||
{{combo-box valueAttribute="value" content=model.plan.intervals value=model.plan.interval}}
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<div class="buttons">
|
||||
|
||||
+14
-10
@@ -2,20 +2,24 @@
|
||||
<h4>{{i18n 'discourse_patrons.admin.products.title'}}</h4>
|
||||
|
||||
<form class="form-horizontal">
|
||||
<div>
|
||||
<label for="name">{{i18n 'discourse_patrons.admin.plans.show.name'}}</label>
|
||||
<p>
|
||||
<label for="name">{{i18n 'discourse_patrons.admin.products.product.name'}}</label>
|
||||
{{input type="text" name="name" value=model.product.name}}
|
||||
</div>
|
||||
<div>
|
||||
<label for="interval">{{i18n 'discourse_patrons.admin.products.show.group'}}</label>
|
||||
</p>
|
||||
<p>
|
||||
<label for="interval">{{i18n 'discourse_patrons.admin.products.product.group'}}</label>
|
||||
{{combo-box valueAttribute="value" content=model.groups value=model.product.groupName}}
|
||||
</div>
|
||||
<div>
|
||||
<label for="interval">{{i18n 'discourse_patrons.admin.products.show.active'}}</label>
|
||||
</p>
|
||||
<p>
|
||||
<label for="interval">{{i18n 'discourse_patrons.admin.products.product.active'}}</label>
|
||||
{{input type="checkbox" checked=model.product.active}}
|
||||
</div>
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<div class="buttons">
|
||||
{{d-button label="discourse_patrons.admin.products.show.create" action="createProduct" icon="plus"}}
|
||||
{{#if model.product.isNew}}
|
||||
{{d-button label="discourse_patrons.admin.products.operations.create" action="createProduct" icon="plus"}}
|
||||
{{else}}
|
||||
{{d-button label="discourse_patrons.admin.products.operations.update" action="updateProduct" icon="fa-save"}}
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<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>
|
||||
<span>{{i18n 'discourse_patrons.admin.products.operations.new'}}</span>
|
||||
{{/link-to}}
|
||||
</p>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user