0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2025-02-13 08:17:01 +01:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-custom-input.js.es6

78 Zeilen
1,9 KiB
Text

2020-03-24 20:35:46 +11:00
import {
newPair,
generateSelectKitContent,
defaultInputType
} from '../lib/custom-wizard';
import {
default as discourseComputed,
on
} from 'discourse-common/utils/decorators';
2020-03-24 21:14:42 +11:00
import { computed, set } from "@ember/object";
2020-03-24 20:35:46 +11:00
import { alias } from "@ember/object/computed";
2018-05-24 15:34:58 +10:00
2017-10-17 21:17:53 +08:00
export default Ember.Component.extend({
2020-03-24 20:35:46 +11:00
classNameBindings: [':custom-input', 'type'],
inputType: alias('input.type'),
outputConnector: computed('inputTypes', function() {
const key = this.outputConnectorKey || `admin.wizard.input.${this.type}.output`;
return I18n.t(key).toLowerCase();
2020-03-23 16:41:04 +11:00
}),
2020-03-22 04:30:11 +11:00
2020-03-24 20:35:46 +11:00
@on('init')
setDefaults() {
if (!this.type) this.set('type', defaultInputType(this.options));
},
2020-03-30 17:16:03 +11:00
@discourseComputed('options.allowedInputs')
allowedInputs(option) {
return option || 'conditional,assignment';
},
@discourseComputed('allowedInputs')
inputTypes(allowedInputs) {
return allowedInputs.split(',').map((type) => {
2020-03-24 20:35:46 +11:00
return {
id: type,
name: I18n.t(`admin.wizard.input.${type}.prefix`)
}
});
},
@discourseComputed('options.hasOutput', 'input.type')
hasPairs(hasOutput, inputType) {
return !hasOutput || inputType === 'conditional';
},
@discourseComputed('input.type')
hasOutputConnector(inputType) {
return inputType === 'conditional';
},
2020-03-22 04:30:11 +11:00
actions: {
addPair() {
2020-03-23 16:41:04 +11:00
const pairs = this.get('input.pairs');
const pairCount = pairs.length + 1;
2020-03-24 21:14:42 +11:00
pairs.forEach(p => (set(p, 'pairCount', pairCount)));
2020-03-23 16:41:04 +11:00
pairs.pushObject(
newPair(Object.assign(
{},
this.options,
{
index: pairs.length,
pairCount,
}
))
2020-03-22 04:30:11 +11:00
);
},
removePair(pair) {
2020-03-23 16:41:04 +11:00
const pairs = this.get('input.pairs');
const pairCount = pairs.length - 1;
2020-03-24 21:14:42 +11:00
pairs.forEach(p => (set(p, 'pairCount', pairCount)));
2020-03-23 16:41:04 +11:00
pairs.removeObject(pair);
2017-10-17 21:17:53 +08:00
}
}
});