43 lines
1.0 KiB
Plaintext
43 lines
1.0 KiB
Plaintext
|
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);
|
||
|
},
|
||
|
},
|
||
|
});
|