discourse-subscriptions/assets/javascripts/discourse/routes/admin-plugins-discourse-sub...

37 lines
1009 B
JavaScript

import { action } from "@ember/object";
import Route from "@ember/routing/route";
import { service } from "@ember/service";
import I18n from "I18n";
import AdminProduct from "discourse/plugins/discourse-subscriptions/discourse/models/admin-product";
export default class AdminPluginsDiscourseSubscriptionsProductsIndexRoute extends Route {
@service dialog;
model() {
return AdminProduct.findAll();
}
@action
destroyProduct(product) {
this.dialog.yesNoConfirm({
message: I18n.t(
"discourse_subscriptions.admin.products.operations.destroy.confirm"
),
didConfirm: () => {
return product
.destroy()
.then(() => {
this.controllerFor(
"adminPluginsDiscourseSubscriptionsProductsIndex"
)
.get("model")
.removeObject(product);
})
.catch((data) =>
this.dialog.alert(data.jqXHR.responseJSON.errors.join("\n"))
);
},
});
}
}