plans and products
This commit is contained in:
+13
@@ -3,6 +3,19 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
export default Ember.Controller.extend({
|
||||
actions: {
|
||||
createPlan() {
|
||||
let product;
|
||||
|
||||
if(this.get("model.plan.product_id")) {
|
||||
product = this.get("model.products")
|
||||
.filterBy('id', this.get("model.plan.product_id"))
|
||||
.get("firstObject");
|
||||
}
|
||||
else {
|
||||
product = this.get("model.products").get("firstObject");
|
||||
}
|
||||
|
||||
this.set("model.plan.product", product);
|
||||
|
||||
this.get("model.plan")
|
||||
.save()
|
||||
.then(() => {
|
||||
|
||||
@@ -14,9 +14,15 @@ const AdminPlan = Discourse.Model.extend({
|
||||
const data = {
|
||||
interval: this.interval,
|
||||
amount: this.amount,
|
||||
name: this.name
|
||||
name: this.name,
|
||||
product: {
|
||||
id: this.product.id,
|
||||
// name: this.product.name
|
||||
}
|
||||
};
|
||||
|
||||
console.log(12, data);
|
||||
|
||||
return ajax("/patrons/admin/plans", { method: "post", data });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
const AdminProduct = Discourse.Model.extend({
|
||||
isNew: false,
|
||||
metadata: {},
|
||||
|
||||
destroy() {
|
||||
return ajax(`/patrons/admin/products/${this.id}`, { method: "delete" });
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ajax } from "discourse/lib/ajax";
|
||||
const Plan = Discourse.Model.extend({});
|
||||
|
||||
Plan.reopenClass({
|
||||
find() {
|
||||
findAll() {
|
||||
return ajax("/patrons/plans", { method: "get" }).then(result =>
|
||||
result.plans.map(plan => Plan.create(plan))
|
||||
);
|
||||
|
||||
@@ -4,7 +4,8 @@ import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
|
||||
export default Discourse.Route.extend({
|
||||
model() {
|
||||
const group = Group.find();
|
||||
const plans = Plan.find().then(results => results.map(p => p.id));
|
||||
const plans = Plan.findAll().then(results => results.map(p => p.id));
|
||||
|
||||
return Ember.RSVP.hash({ group, plans });
|
||||
}
|
||||
});
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
</p>
|
||||
<p>
|
||||
<label for="product">{{i18n 'discourse_patrons.admin.plans.plan.product'}}</label>
|
||||
{{combo-box valueAttribute="value" content=model.products value=defaultProduct}}
|
||||
{{combo-box valueAttribute="id" content=model.products value=model.plan.product_id}}
|
||||
</p>
|
||||
<p>
|
||||
<label for="interval">{{i18n 'discourse_patrons.admin.plans.plan.interval'}}</label>
|
||||
|
||||
Reference in New Issue
Block a user