mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-07-13 01:23: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) => {
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
<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">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user