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-custom-input.js.es6

73 Zeilen
1,8 KiB
Text

2020-03-24 10:35:46 +01:00
import {
newPair,
generateSelectKitContent,
defaultInputType
} from '../lib/custom-wizard';
import {
default as discourseComputed,
on
} from 'discourse-common/utils/decorators';
2020-03-24 11:14:42 +01:00
import { computed, set } from "@ember/object";
2020-03-24 10:35:46 +01:00
import { alias } from "@ember/object/computed";
2018-05-24 07:34:58 +02:00
2017-10-17 15:17:53 +02:00
export default Ember.Component.extend({
2020-03-24 10:35:46 +01: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 06:41:04 +01:00
}),
2020-03-21 18:30:11 +01:00
2020-03-24 10:35:46 +01:00
@on('init')
setDefaults() {
if (!this.type) this.set('type', defaultInputType(this.options));
},
@discourseComputed
inputTypes() {
return ['conditional', 'assignment'].map((type) => {
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-21 18:30:11 +01:00
actions: {
addPair() {
2020-03-23 06:41:04 +01:00
const pairs = this.get('input.pairs');
const pairCount = pairs.length + 1;
2020-03-24 11:14:42 +01:00
pairs.forEach(p => (set(p, 'pairCount', pairCount)));
2020-03-23 06:41:04 +01:00
pairs.pushObject(
newPair(Object.assign(
{},
this.options,
{
index: pairs.length,
pairCount,
}
))
2020-03-21 18:30:11 +01:00
);
},
removePair(pair) {
2020-03-23 06:41:04 +01:00
const pairs = this.get('input.pairs');
const pairCount = pairs.length - 1;
2020-03-24 11:14:42 +01:00
pairs.forEach(p => (set(p, 'pairCount', pairCount)));
2020-03-23 06:41:04 +01:00
pairs.removeObject(pair);
2017-10-17 15:17:53 +02:00
}
}
});