0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-23 09:50:28 +01:00
discourse-custom-wizard/assets/javascripts/discourse/lib/custom-wizard.js.es6

134 Zeilen
2,3 KiB
Text

2020-02-02 11:42:05 +01:00
function generateSelectKitContent(content) {
return content.map(i => ({id: i, name: i}))
}
2020-03-21 18:30:11 +01:00
function generateName(id) {
return id.replace(/[_\-]+/g, ' ')
.toLowerCase()
.replace(/(^\w|\b\w)/g, (m) => m.toUpperCase())
}
const profileFields = [
'name',
'user_avatar',
'date_of_birth',
'title',
'locale',
'location',
'website',
'bio_raw',
'profile_background',
'card_background',
'theme_id'
];
const connectors = [
2020-03-22 07:47:56 +01:00
{
id: 'eq',
name: '='
},{
id: 'gt',
name: '>'
},{
id: 'lt',
name: '<'
},{
id: 'gte',
name: '>='
},{
id: 'lte',
name: '<='
}
2020-03-21 18:30:11 +01:00
]
const actionTypes = [
'create_topic',
'update_profile',
'create_topic',
'update_profile',
'send_message',
'send_to_api',
'add_to_group',
'route_to',
'open_composer'
];
2020-03-24 10:35:46 +01:00
const selectionTypes = [
'text',
'wizardField',
'userField',
'group',
'category',
'tag'
]
const inputTypes = [
'pair',
'conditional',
'assignment'
]
function defaultInputType(options = {}) {
return options.hasOutput ? 'conditional' : 'pair';
}
function defaultSelectionType(inputType, options = {}) {
const textDisabled = options.textDisabled;
let type = 'text';
if (textDisabled === true ||
((typeof textDisabled == 'string') && textDisabled.indexOf(inputType) > -1)) {
for (let t of selectionTypes) {
let inputTypes = options[`${t}Selection`];
if (inputTypes === true ||
((typeof inputTypes == 'string') && inputTypes.indexOf(inputType) > -1)) {
type = t;
break;
}
}
}
return type;
}
2020-03-21 18:30:11 +01:00
function newInput(options = {}) {
2020-03-24 10:35:46 +01:00
let params = {
type: defaultInputType(options),
2020-03-23 06:41:04 +01:00
pairs: Ember.A([newPair({ index: 0, pairCount: 1 })])
2020-03-21 18:30:11 +01:00
}
if (options.hasOutput) {
2020-03-24 10:35:46 +01:00
params['output_type'] = defaultSelectionType('output', options);
2020-03-21 18:30:11 +01:00
}
return Ember.Object.create(params);
}
2020-03-23 06:41:04 +01:00
function newPair(options = {}) {
2020-03-21 18:30:11 +01:00
let params = {
2020-03-23 06:41:04 +01:00
index: options.index,
pairCount: options.pairCount,
2020-03-21 18:30:11 +01:00
key: '',
2020-03-24 10:35:46 +01:00
key_type: defaultSelectionType('text', options),
2020-03-21 18:30:11 +01:00
value: '',
2020-03-24 10:35:46 +01:00
value_type: defaultSelectionType('text', options),
2020-03-22 07:47:56 +01:00
connector: 'eq'
2020-03-21 18:30:11 +01:00
}
return Ember.Object.create(params);
}
export {
generateSelectKitContent,
profileFields,
actionTypes,
generateName,
2020-03-24 10:35:46 +01:00
defaultInputType,
defaultSelectionType,
2020-03-21 18:30:11 +01:00
connectors,
newInput,
newPair
};