mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-07-12 17:13:28 +00:00
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 discourseComputed from "discourse-common/utils/decorators";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
import { alias } from "@ember/object/computed";
|
||||||
|
|
||||||
const RECURRING = "recurring";
|
const RECURRING = "recurring";
|
||||||
const ONE_TIME = "one_time";
|
const ONE_TIME = "one_time";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default Controller.extend({
|
||||||
// Also defined in settings.
|
// Also defined in settings.
|
||||||
selectedCurrency: Ember.computed.alias("model.plan.currency"),
|
selectedCurrency: alias("model.plan.currency"),
|
||||||
selectedInterval: Ember.computed.alias("model.plan.interval"),
|
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
|
@discourseComputed
|
||||||
currencies() {
|
currencies() {
|
||||||
@ -57,13 +74,9 @@ export default Controller.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
createPlan() {
|
createPlan() {
|
||||||
// TODO: set default group name beforehand
|
if (this.model.plan.metadata.group_name === "no-group") {
|
||||||
if (this.get("model.plan.metadata.group_name") === undefined) {
|
this.set("model.plan.metadata.group_name", null);
|
||||||
this.set("model.plan.metadata", {
|
|
||||||
group_name: this.get("model.groups.firstObject.name"),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.get("model.plan")
|
this.get("model.plan")
|
||||||
.save()
|
.save()
|
||||||
.then(() => this.redirect(this.productId))
|
.then(() => this.redirect(this.productId))
|
||||||
@ -73,6 +86,9 @@ export default Controller.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
updatePlan() {
|
updatePlan() {
|
||||||
|
if (this.model.plan.metadata.group_name === "no-group") {
|
||||||
|
this.set("model.plan.metadata.group_name", null);
|
||||||
|
}
|
||||||
this.get("model.plan")
|
this.get("model.plan")
|
||||||
.update()
|
.update()
|
||||||
.then(() => this.redirect(this.productId))
|
.then(() => this.redirect(this.productId))
|
||||||
|
@ -20,6 +20,9 @@ export default Route.extend({
|
|||||||
isRecurring: true,
|
isRecurring: true,
|
||||||
currency: Discourse.SiteSettings.discourse_subscriptions_currency,
|
currency: Discourse.SiteSettings.discourse_subscriptions_currency,
|
||||||
product: product.get("id"),
|
product: product.get("id"),
|
||||||
|
metadata: {
|
||||||
|
group_name: null,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
plan = AdminPlan.find(id).then((result) => {
|
plan = AdminPlan.find(id).then((result) => {
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="interval">{{i18n 'discourse_subscriptions.admin.plans.plan.group'}}</label>
|
<label for="interval">{{i18n 'discourse_subscriptions.admin.plans.plan.group'}}</label>
|
||||||
{{combo-box
|
{{combo-box
|
||||||
valueProperty="name"
|
valueProperty="name"
|
||||||
content=model.groups
|
content=availableGroups
|
||||||
value=model.plan.metadata.group_name
|
value=selectedGroup
|
||||||
onChange=(action (mut model.plan.metadata.group_name))
|
onChange=(action (mut model.plan.metadata.group_name))
|
||||||
}}
|
}}
|
||||||
<div class="control-instructions">
|
<div class="control-instructions">
|
||||||
@ -30,10 +30,10 @@
|
|||||||
{{#if planFieldDisabled}}
|
{{#if planFieldDisabled}}
|
||||||
{{input class="plan-amount plan-currency" disabled=true value=model.plan.currency}}
|
{{input class="plan-amount plan-currency" disabled=true value=model.plan.currency}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{combo-box
|
{{combo-box
|
||||||
disabled=planFieldDisabled
|
disabled=planFieldDisabled
|
||||||
content=currencies
|
content=currencies
|
||||||
value=model.plan.currency
|
value=model.plan.currency
|
||||||
onChange=(action (mut model.plan.currency))
|
onChange=(action (mut model.plan.currency))
|
||||||
}}
|
}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
@ -44,16 +44,16 @@
|
|||||||
{{i18n 'discourse_subscriptions.admin.plans.plan.recurring'}}
|
{{i18n 'discourse_subscriptions.admin.plans.plan.recurring'}}
|
||||||
</label>
|
</label>
|
||||||
{{#if planFieldDisabled}}
|
{{#if planFieldDisabled}}
|
||||||
{{input
|
{{input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
name="recurring"
|
name="recurring"
|
||||||
checked=model.plan.isRecurring
|
checked=model.plan.isRecurring
|
||||||
disabled=true
|
disabled=true
|
||||||
}}
|
}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{input
|
{{input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
name="recurring"
|
name="recurring"
|
||||||
checked=model.plan.isRecurring
|
checked=model.plan.isRecurring
|
||||||
change=(action 'changeRecurring')
|
change=(action 'changeRecurring')
|
||||||
}}
|
}}
|
||||||
@ -67,10 +67,10 @@
|
|||||||
{{#if planFieldDisabled}}
|
{{#if planFieldDisabled}}
|
||||||
{{input disabled=true value=selectedInterval}}
|
{{input disabled=true value=selectedInterval}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{combo-box
|
{{combo-box
|
||||||
valueProperty="name"
|
valueProperty="name"
|
||||||
content=availableIntervals
|
content=availableIntervals
|
||||||
value=selectedInterval
|
value=selectedInterval
|
||||||
onChange=(action (mut selectedInterval))
|
onChange=(action (mut selectedInterval))
|
||||||
}}
|
}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user