0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-26 11:00:28 +01:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-custom-input-selector.js.es6

77 Zeilen
2,8 KiB
Text

2020-03-24 10:35:46 +01:00
import { alias, equal } from "@ember/object/computed";
import { computed } from "@ember/object";
import {
default as discourseComputed,
2020-03-29 09:49:33 +02:00
observes,
on
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({
classNames: 'input-selector',
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');
return controller.get('model.userFields');
},
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';
},
showText: equal('activeType', 'text'),
showInput(type) {
return this.activeType === type && this[`${type}Enabled`] && !this[`${type}Disabled`];
},
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
},
textDisabled: computed('options.textDisabled', 'inputType', function() { return this.optionEnabled('textDisabled') }),
wizardEnabled: computed('options.wizardFieldSelection', 'inputType', function() { return this.optionEnabled('wizardFieldSelection') }),
userEnabled: computed('options.userFieldSelection', 'inputType', function() { return this.optionEnabled('userFieldSelection') }),
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);
}
}
})