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) => {
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
</p>
|
||||
<p>
|
||||
<label for="interval">{{i18n 'discourse_subscriptions.admin.plans.plan.group'}}</label>
|
||||
{{combo-box
|
||||
{{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">
|
||||
|
@ -30,10 +30,10 @@
|
|||
{{#if planFieldDisabled}}
|
||||
{{input class="plan-amount plan-currency" disabled=true value=model.plan.currency}}
|
||||
{{else}}
|
||||
{{combo-box
|
||||
disabled=planFieldDisabled
|
||||
content=currencies
|
||||
value=model.plan.currency
|
||||
{{combo-box
|
||||
disabled=planFieldDisabled
|
||||
content=currencies
|
||||
value=model.plan.currency
|
||||
onChange=(action (mut model.plan.currency))
|
||||
}}
|
||||
{{/if}}
|
||||
|
@ -44,16 +44,16 @@
|
|||
{{i18n 'discourse_subscriptions.admin.plans.plan.recurring'}}
|
||||
</label>
|
||||
{{#if planFieldDisabled}}
|
||||
{{input
|
||||
type="checkbox"
|
||||
name="recurring"
|
||||
{{input
|
||||
type="checkbox"
|
||||
name="recurring"
|
||||
checked=model.plan.isRecurring
|
||||
disabled=true
|
||||
}}
|
||||
{{else}}
|
||||
{{input
|
||||
type="checkbox"
|
||||
name="recurring"
|
||||
{{input
|
||||
type="checkbox"
|
||||
name="recurring"
|
||||
checked=model.plan.isRecurring
|
||||
change=(action 'changeRecurring')
|
||||
}}
|
||||
|
@ -67,10 +67,10 @@
|
|||
{{#if planFieldDisabled}}
|
||||
{{input disabled=true value=selectedInterval}}
|
||||
{{else}}
|
||||
{{combo-box
|
||||
{{combo-box
|
||||
valueProperty="name"
|
||||
content=availableIntervals
|
||||
value=selectedInterval
|
||||
content=availableIntervals
|
||||
value=selectedInterval
|
||||
onChange=(action (mut selectedInterval))
|
||||
}}
|
||||
{{/if}}
|
||||
|
|
Loading…
Reference in New Issue