0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-09-20 07:41:11 +02:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6

80 Zeilen
2,9 KiB
Text

2020-04-01 07:03:26 +02:00
import { alias } from "@ember/object/computed";
2020-03-24 10:35:46 +01:00
import { computed } from "@ember/object";
import {
default as discourseComputed,
2020-03-29 09:49:33 +02:00
observes,
2020-03-24 10:35:46 +01:00
} from "discourse-common/utils/decorators";
import { defaultSelectionType } from '../lib/custom-wizard';
2020-03-29 09:49:33 +02:00
import { getOwner } from 'discourse-common/lib/get-owner';
2020-03-24 10:35:46 +01:00
export default Ember.Component.extend({
2020-04-01 07:03:26 +02:00
classNames: 'mapper-selector',
2020-03-24 10:35:46 +01:00
groups: alias('site.groups'),
categories: computed(function() {
return this.site.categories.map(c => ({ id: c.id, name: c.name }));
}),
2020-03-29 09:49:33 +02:00
@discourseComputed
userFields() {
const controller = getOwner(this).lookup('controller:admin-wizard');
2020-04-01 07:03:26 +02:00
return controller.model.userFields;
},
@discourseComputed
wizardFields() {
const controller = getOwner(this).lookup('controller:admin-wizard');
return controller.wizardFields;
2020-03-29 09:49:33 +02:00
},
2020-03-24 10:35:46 +01:00
@observes('options.@each')
resetActiveType() {
this.set('activeType', defaultSelectionType(this.selectorType, this.options));
},
@observes('activeType')
clearValue() {
this.set('value', null);
},
@discourseComputed('customPlaceholder')
textPlaceholder(customPlaceholder) {
return customPlaceholder || 'admin.wizard.text';
},
showInput(type) {
2020-04-01 07:03:26 +02:00
return this.activeType === type && this[`${type}Enabled`];
2020-03-24 10:35:46 +01:00
},
2020-04-01 07:03:26 +02:00
showText: computed('activeType', function() { return this.showInput('text') }),
2020-03-24 10:35:46 +01:00
showWizard: computed('activeType', function() { return this.showInput('wizard') }),
showUser: computed('activeType', function() { return this.showInput('user') }),
showCategory: computed('activeType', function() { return this.showInput('category') }),
showTag: computed('activeType', function() { return this.showInput('tag') }),
showGroup: computed('activeType', function() { return this.showInput('group') }),
optionEnabled(type) {
const options = this.options;
if (!options) return false;
const option = options[type];
if (option === true) return true;
if (typeof option !== 'string') return false;
const types = [this.selectorType, this.inputType];
return option.split(',').filter(o => types.indexOf(o) !== -1).length
},
2020-04-01 07:03:26 +02:00
textEnabled: computed('options.textSelection', 'inputType', function() { return this.optionEnabled('textSelection') }),
wizardEnabled: computed('options.wizardSelection', 'inputType', function() { return this.optionEnabled('wizardSelection') }),
userEnabled: computed('options.userSelection', 'inputType', function() { return this.optionEnabled('userSelection') }),
2020-03-24 10:35:46 +01:00
categoryEnabled: computed('options.categorySelection', 'inputType', function() { return this.optionEnabled('categorySelection') }),
tagEnabled: computed('options.tagSelection', 'inputType', function() { return this.optionEnabled('tagSelection') }),
groupEnabled: computed('options.groupSelection', 'inputType', function() { return this.optionEnabled('groupSelection') }),
actions: {
toggleType(type) {
this.set('activeType', type);
}
}
})