discourse-subscriptions/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-coupons.js
2024-11-29 16:42:50 +01:00

51 lines
1.1 KiB
JavaScript

import Controller from "@ember/controller";
import { action } from "@ember/object";
import { popupAjaxError } from "discourse/lib/ajax-error";
import AdminCoupon from "discourse/plugins/discourse-subscriptions/discourse/models/admin-coupon";
export default class AdminPluginsDiscourseSubscriptionsCouponsController extends Controller {
creating = null;
@action
openCreateForm() {
this.set("creating", true);
}
@action
closeCreateForm() {
this.set("creating", false);
}
@action
createNewCoupon(params) {
AdminCoupon.save(params)
.then(() => {
this.send("closeCreateForm");
this.send("reloadModel");
})
.catch(popupAjaxError);
}
@action
deleteCoupon(coupon) {
AdminCoupon.destroy(coupon)
.then(() => {
this.send("reloadModel");
})
.catch(popupAjaxError);
}
@action
toggleActive(coupon) {
const couponData = {
id: coupon.id,
active: !coupon.active,
};
AdminCoupon.update(couponData)
.then(() => {
this.send("reloadModel");
})
.catch(popupAjaxError);
}
}