1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/discourse/components/wizard-mapper.js.es6
Angus McLeod 7b3ed54f29 various
2020-04-05 11:37:09 +10:00

55 Zeilen
1,6 KiB
JavaScript

import { getOwner } from 'discourse-common/lib/get-owner';
import { on } from 'discourse-common/utils/decorators';
import { newInput, selectionTypes } from '../lib/wizard-mapper';
import { default as discourseComputed, observes } from 'discourse-common/utils/decorators';
import Component from "@ember/component";
import { A } from "@ember/array";
export default Component.extend({
classNames: 'wizard-mapper',
@discourseComputed('inputs.[]', 'options.singular')
canAdd(inputs, singular) {
return !singular || !inputs || inputs.length < 1;
},
@discourseComputed('options.@each')
inputOptions(options) {
let result = {
inputTypes: options.inputTypes || 'conditional,assignment',
pairConnector: options.pairConnector || null,
outputConnector: options.outputConnector || null
}
let inputTypes = ['key', 'value', 'output'];
inputTypes.forEach(type => {
result[`${type}DefaultSelection`] = options[`${type}DefaultSelection`] || null;
});
selectionTypes.forEach(type => {
if (options[`${type}Selection`]) {
result[`${type}Selection`] = options[`${type}Selection`]
} else {
result[`${type}Selection`] = type === 'text' ? true : false;
}
});
return result;
},
@observes('options.inputTypes')
clearInputs() {
this.get('inputs').clear();
},
actions: {
add() {
if (!this.get('inputs')) this.set('inputs', A());
this.get('inputs').pushObject(newInput(this.inputOptions));
},
remove(input) {
this.get('inputs').removeObject(input);
}
}
});