FIX: Properly allow no group to be selected (#33)
This commit is contained in:
parent
52817018aa
commit
d430098bad
|
@ -1,14 +1,31 @@
|
|||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import Controller from "@ember/controller";
|
||||
import { alias } from "@ember/object/computed";
|
||||
|
||||
const RECURRING = "recurring";
|
||||
const ONE_TIME = "one_time";
|
||||
|
||||
export default Controller.extend({
|
||||
// Also defined in settings.
|
||||
selectedCurrency: Ember.computed.alias("model.plan.currency"),
|
||||
selectedInterval: Ember.computed.alias("model.plan.interval"),
|
||||
selectedCurrency: alias("model.plan.currency"),
|
||||
selectedInterval: alias("model.plan.interval"),
|
||||
|
||||
@discourseComputed("model.plan.metadata.group_name")
|
||||
selectedGroup(groupName) {
|
||||
return groupName || "no-group";
|
||||
},
|
||||
|
||||
@discourseComputed("model.groups")
|
||||
availableGroups(groups) {
|
||||
return [
|
||||
{
|
||||
id: null,
|
||||
name: "no-group",
|
||||
},
|
||||
...groups,
|
||||
];
|
||||
},
|
||||
|
||||
@discourseComputed
|
||||
currencies() {
|
||||
|
@ -57,13 +74,9 @@ export default Controller.extend({
|
|||
},
|
||||
|
||||
createPlan() {
|
||||
// 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"),
|
||||
});
|
||||
if (this.model.plan.metadata.group_name === "no-group") {
|
||||
this.set("model.plan.metadata.group_name", null);
|
||||
}
|
||||
|
||||
this.get("model.plan")
|
||||
.save()
|
||||
.then(() => this.redirect(this.productId))
|
||||
|
@ -73,6 +86,9 @@ export default Controller.extend({
|
|||
},
|
||||
|
||||
updatePlan() {
|
||||
if (this.model.plan.metadata.group_name === "no-group") {
|
||||
this.set("model.plan.metadata.group_name", null);
|
||||
}
|
||||
this.get("model.plan")
|
||||
.update()
|
||||
.then(() => this.redirect(this.productId))
|
||||
|
|
|
@ -20,6 +20,9 @@ export default Route.extend({
|
|||
isRecurring: true,
|
||||
currency: Discourse.SiteSettings.discourse_subscriptions_currency,
|
||||
product: product.get("id"),
|
||||
metadata: {
|
||||
group_name: null,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
plan = AdminPlan.find(id).then((result) => {
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
<label for="interval">{{i18n 'discourse_subscriptions.admin.plans.plan.group'}}</label>
|
||||
{{combo-box
|
||||
valueProperty="name"
|
||||
content=model.groups
|
||||
value=model.plan.metadata.group_name
|
||||
content=availableGroups
|
||||
value=selectedGroup
|
||||
onChange=(action (mut model.plan.metadata.group_name))
|
||||
}}
|
||||
<div class="control-instructions">
|
||||
|
|
Loading…
Reference in New Issue