Files
discourse-subscriptions/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-coupons.js.es6
T
Justin DiRose 400313cded FEATURE: Allow creation of coupons in admin panel (#43)
Adds full support to create coupon/promo codes in the Admin > Plugins > Subscriptions section of the plugin. The Create Coupon button opens a form on the same page, and the active checkboxes toggle the active status of the coupon code.
2021-01-13 11:47:22 -06:00

43 lines
1.0 KiB
JavaScript

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