destroy products
This commit is contained in:
-8
@@ -2,14 +2,6 @@ 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}`
|
||||
|
||||
+5
-2
@@ -4,8 +4,11 @@ export default Ember.Controller.extend({
|
||||
actions: {
|
||||
createProduct() {
|
||||
// TODO: set default group name beforehand
|
||||
if(this.get("model.product.groupName") === undefined) {
|
||||
this.set("model.product.groupName", this.get("model.group.firstObject"));
|
||||
if (this.get("model.product.groupName") === undefined) {
|
||||
this.set(
|
||||
"model.product.groupName",
|
||||
this.get("model.group.firstObject")
|
||||
);
|
||||
}
|
||||
|
||||
this.get("model.product")
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
const AdminProduct = Discourse.Model.extend({
|
||||
active: true,
|
||||
|
||||
destroy() {},
|
||||
destroy() {
|
||||
return ajax(`/patrons/admin/products/${this.id}`, { method: "delete" });
|
||||
},
|
||||
|
||||
save() {
|
||||
const data = {
|
||||
@@ -17,7 +17,7 @@ const AdminProduct = Discourse.Model.extend({
|
||||
});
|
||||
|
||||
AdminProduct.reopenClass({
|
||||
find() {
|
||||
findAll() {
|
||||
return ajax("/patrons/admin/products", { method: "get" }).then(result =>
|
||||
result.map(product => AdminProduct.create(product))
|
||||
);
|
||||
|
||||
+7
-4
@@ -2,7 +2,7 @@ import AdminProduct from "discourse/plugins/discourse-patrons/discourse/models/a
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
model() {
|
||||
return AdminProduct.find();
|
||||
return AdminProduct.findAll();
|
||||
},
|
||||
|
||||
actions: {
|
||||
@@ -13,9 +13,12 @@ export default Discourse.Route.extend({
|
||||
I18n.t("yes_value"),
|
||||
confirmed => {
|
||||
if (confirmed) {
|
||||
this.controllerFor("adminPluginsDiscoursePatronsProductsIndex")
|
||||
.get("model")
|
||||
.removeObject(product);
|
||||
product.destroy().then(() => {
|
||||
this.controllerFor("adminPluginsDiscoursePatronsProductsIndex")
|
||||
.get("model")
|
||||
.removeObject(product);
|
||||
})
|
||||
.catch(data => bootbox.alert(data.jqXHR.responseJSON.errors.join("\n")));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
{{#each model as |product|}}
|
||||
<tr>
|
||||
<td>{{product.id}}</td>
|
||||
<td>{{product.group}}</td>
|
||||
<td>{{product.metadata.group_name}}</td>
|
||||
<td>{{product.active}}</td>
|
||||
<td class="td-right">
|
||||
{{d-button
|
||||
|
||||
Reference in New Issue
Block a user