1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/discourse/components/wizard-mapper.js.es6
Angus McLeod 04d7fc1c59 various
2020-04-06 11:54:16 +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,
context: options.context || null
}
let inputTypes = ['key', 'value', 'output'];
inputTypes.forEach(type => {
result[`${type}Placeholder`] = options[`${type}Placeholder`] || null;
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;
},
actions: {
add() {
if (!this.get('inputs')) {
this.set('inputs', A());
}
this.get('inputs').pushObject(newInput(this.inputOptions));
},
remove(input) {
this.get('inputs').removeObject(input);
}
}
});