2019-10-23 00:55:06 -04:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
2019-10-22 00:45:51 -04:00
|
|
|
import DiscourseURL from "discourse/lib/url";
|
|
|
|
|
|
|
|
export default Ember.Controller.extend({
|
2019-10-23 00:55:06 -04:00
|
|
|
@computed("model.plan.isNew")
|
|
|
|
planFieldDisabled(isNew) {
|
|
|
|
return !isNew;
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed("model.product.id")
|
|
|
|
productId(id) {
|
|
|
|
return id;
|
|
|
|
},
|
|
|
|
|
2019-10-22 00:45:51 -04:00
|
|
|
redirect(product_id) {
|
2019-10-24 23:00:59 -04:00
|
|
|
DiscourseURL.redirectTo(
|
|
|
|
`/admin/plugins/discourse-patrons/products/${product_id}`
|
|
|
|
);
|
2019-10-22 00:45:51 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
cancelPlan(product_id) {
|
|
|
|
this.redirect(product_id);
|
|
|
|
},
|
|
|
|
|
|
|
|
createPlan() {
|
2019-10-23 00:55:06 -04:00
|
|
|
// TODO: set default group name beforehand
|
|
|
|
if (this.get("model.plan.metadata.group_name") === undefined) {
|
2019-10-24 23:00:59 -04:00
|
|
|
this.set("model.plan.metadata", {
|
|
|
|
group_name: this.get("model.groups.firstObject.name")
|
|
|
|
});
|
2019-10-23 00:55:06 -04:00
|
|
|
}
|
|
|
|
|
2019-10-24 23:00:59 -04:00
|
|
|
this.get("model.plan")
|
|
|
|
.save()
|
2019-10-30 21:41:02 -04:00
|
|
|
.then(() => this.redirect(this.productId))
|
|
|
|
.catch(data =>
|
|
|
|
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
|
|
|
|
);
|
2019-10-23 00:55:06 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
updatePlan() {
|
2019-10-24 23:00:59 -04:00
|
|
|
this.get("model.plan")
|
|
|
|
.update()
|
2019-10-30 21:41:02 -04:00
|
|
|
.then(() => this.redirect(this.productId))
|
|
|
|
.catch(data =>
|
|
|
|
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
|
|
|
|
);
|
2019-10-22 00:45:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|