2021-09-03 10:46:32 +02:00
|
|
|
import SingleSelectComponent from "select-kit/components/single-select";
|
2022-03-25 12:18:54 +01:00
|
|
|
import Subscription from "../mixins/subscription";
|
|
|
|
import wizardSchema from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
|
|
|
|
import {
|
|
|
|
subscriptionTypeSufficient,
|
|
|
|
subscriptionTypes
|
|
|
|
} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-subscription";
|
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2021-09-03 10:46:32 +02:00
|
|
|
|
2022-03-25 12:18:54 +01:00
|
|
|
const nameKey = function(feature, attribute, value) {
|
|
|
|
if (feature === 'action') {
|
|
|
|
return `admin.wizard.action.${value}.label`;
|
|
|
|
} else {
|
|
|
|
return `admin.wizard.${feature}.${attribute}.${value}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SingleSelectComponent.extend(Subscription, {
|
2021-09-24 11:58:42 +02:00
|
|
|
classNames: ["combo-box", "wizard-subscription-selector"],
|
2021-09-03 10:46:32 +02:00
|
|
|
|
|
|
|
selectKitOptions: {
|
|
|
|
autoFilterable: false,
|
|
|
|
filterable: false,
|
|
|
|
showFullTitle: true,
|
2021-10-19 14:49:06 +02:00
|
|
|
headerComponent:
|
|
|
|
"wizard-subscription-selector/wizard-subscription-selector-header",
|
2021-09-03 10:46:32 +02:00
|
|
|
caretUpIcon: "caret-up",
|
2021-09-07 14:13:01 +02:00
|
|
|
caretDownIcon: "caret-down",
|
2021-09-03 10:46:32 +02:00
|
|
|
},
|
|
|
|
|
2022-03-25 12:18:54 +01:00
|
|
|
requiredSubscriptionType(feature, attribute, value) {
|
|
|
|
let attributes = this.subscriptionAttributes[feature];
|
|
|
|
if (!attributes || !attributes[attribute]) return null;
|
|
|
|
|
|
|
|
let requiredType = null;
|
|
|
|
Object.keys(attributes[attribute]).some(subscriptionType => {
|
|
|
|
let values = attributes[attribute][subscriptionType];
|
|
|
|
if (values[0] === "*" || values.includes(value)) {
|
|
|
|
if (subscriptionTypes.includes(subscriptionType)) {
|
|
|
|
requiredType = subscriptionType;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
return requiredType;
|
|
|
|
},
|
|
|
|
|
|
|
|
@discourseComputed('feature', 'attribute')
|
|
|
|
content(feature, attribute) {
|
|
|
|
return wizardSchema[feature][attribute].map((value) => {
|
|
|
|
let requiredSubscriptionType = this.requiredSubscriptionType(feature, attribute, value);
|
|
|
|
return {
|
|
|
|
id: value,
|
|
|
|
name: I18n.t(nameKey(feature, attribute, value)),
|
|
|
|
subscriptionType: requiredSubscriptionType,
|
|
|
|
disabled: !subscriptionTypeSufficient(this.subscriptionType, requiredSubscriptionType)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2021-09-03 10:46:32 +02:00
|
|
|
modifyComponentForRow() {
|
2021-09-24 11:58:42 +02:00
|
|
|
return "wizard-subscription-selector/wizard-subscription-selector-row";
|
2021-09-07 14:13:01 +02:00
|
|
|
},
|
|
|
|
});
|