discourse-subscriptions/assets/javascripts/discourse/controllers/admin-plugins-discourse-pat...

41 lines
988 B
Plaintext
Raw Normal View History

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) {
DiscourseURL.redirectTo(`/admin/plugins/discourse-patrons/products/${product_id}`);
},
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) {
this.set(
"model.plan.metadata",
{ group_name: this.get("model.groups.firstObject.name") }
);
}
this.get('model.plan').save().then(() => this.redirect(this.productId));
},
updatePlan() {
this.get('model.plan').update().then(() => this.redirect(this.productId));
2019-10-22 00:45:51 -04:00
}
}
});