1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/discourse/components/wizard-mapper.js.es6

56 Zeilen
1,6 KiB
Text

2020-04-01 07:03:26 +02:00
import { getOwner } from 'discourse-common/lib/get-owner';
import { on } from 'discourse-common/utils/decorators';
2020-04-05 03:37:09 +02:00
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";
2020-04-01 07:03:26 +02:00
2020-04-05 03:37:09 +02:00
export default Component.extend({
2020-04-01 07:03:26 +02:00
classNames: 'wizard-mapper',
@discourseComputed('inputs.[]', 'options.singular')
canAdd(inputs, singular) {
return !singular || !inputs || inputs.length < 1;
},
2020-04-05 03:37:09 +02:00
@discourseComputed('options.@each')
2020-04-01 07:03:26 +02:00
inputOptions(options) {
2020-04-05 03:37:09 +02:00
let result = {
inputTypes: options.inputTypes || 'conditional,assignment',
2020-04-01 07:03:26 +02:00
pairConnector: options.pairConnector || null,
2020-04-06 03:54:16 +02:00
outputConnector: options.outputConnector || null,
context: options.context || null
2020-04-01 07:03:26 +02:00
}
2020-04-05 03:37:09 +02:00
let inputTypes = ['key', 'value', 'output'];
inputTypes.forEach(type => {
2020-04-06 03:54:16 +02:00
result[`${type}Placeholder`] = options[`${type}Placeholder`] || null;
2020-04-05 03:37:09 +02:00
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;
}
});
2020-04-06 03:54:16 +02:00
2020-04-05 03:37:09 +02:00
return result;
},
2020-04-01 07:03:26 +02:00
actions: {
add() {
2020-04-06 03:54:16 +02:00
if (!this.get('inputs')) {
this.set('inputs', A());
}
2020-04-01 07:03:26 +02:00
this.get('inputs').pushObject(newInput(this.inputOptions));
},
remove(input) {
this.get('inputs').removeObject(input);
}
}
});