0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-10 04:12:53 +01:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6

79 Zeilen
3,2 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";
2020-04-01 12:58:30 +02:00
import { default as discourseComputed, observes } from "discourse-common/utils/decorators";
2020-03-29 09:49:33 +02:00
import { getOwner } from 'discourse-common/lib/get-owner';
2020-04-02 07:21:57 +02:00
import { defaultSelectionType } from '../lib/wizard-mapper';
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') }),
2020-04-02 10:21:03 +02:00
showUserField: computed('activeType', function() { return this.showInput('userField') }),
2020-03-24 10:35:46 +01:00
showCategory: computed('activeType', function() { return this.showInput('category') }),
showTag: computed('activeType', function() { return this.showInput('tag') }),
showGroup: computed('activeType', function() { return this.showInput('group') }),
2020-04-02 10:21:03 +02:00
showUser: computed('activeType', function() { return this.showInput('user') }),
2020-03-24 10:35:46 +01:00
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') }),
2020-04-02 10:21:03 +02:00
userFieldEnabled: computed('options.userFieldSelection', 'inputType', function() { return this.optionEnabled('userFieldSelection') }),
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') }),
2020-04-02 10:21:03 +02:00
userEnabled: computed('options.userSelection', 'inputType', function() { return this.optionEnabled('userSelection') }),
2020-03-24 10:35:46 +01:00
actions: {
toggleType(type) {
this.set('activeType', type);
}
}
})