0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-15 22:32:54 +01:00
discourse-custom-wizard/assets/javascripts/discourse/lib/wizard-schema.js.es6

285 Zeilen
5 KiB
Text

2020-04-20 11:41:13 +02:00
import { set, get } from "@ember/object";
const wizard = {
basic: {
id: null,
name: null,
background: null,
save_submissions: true,
multiple_submissions: null,
after_signup: null,
after_time: null,
after_time_scheduled: null,
required: null,
prompt_completion: null,
restart_on_revisit: null,
theme_id: null,
permitted: null
},
mapped: [
'permitted'
],
advanced: [
'restart_on_revisit',
],
required: [
'id',
],
dependent: {
after_time: 'after_time_scheduled'
},
objectArrays: {
step: {
property: 'steps',
required: false
},
action: {
property: 'actions',
required: false
}
}
};
const step = {
basic: {
id: null,
title: null,
key: null,
banner: null,
raw_description: null,
required_data: null,
required_data_message: null,
permitted_params: null
},
mapped: [
'required_data',
'permitted_params'
],
advanced: [
'required_data',
'permitted_params'
],
required: [
'id'
],
dependent: {
},
objectArrays: {
field: {
property: 'fields',
required: false
}
}
}
const field = {
basic: {
id: null,
label: null,
image: null,
description: null,
required: null,
key: null,
type: null
},
types: {},
mapped: [
'prefill',
'content'
],
advanced: [
'property',
'key'
],
required: [
'id',
'type'
],
dependent: {
},
objectArrays: {
}
}
const action = {
basic: {
id: null,
run_after: 'wizard_completion',
type: null
},
types: {
create_topic: {
title: null,
post: null,
post_builder: null,
post_template: null,
category: null,
tags: null,
2020-07-20 06:26:11 +02:00
visible: null,
custom_fields: null,
skip_redirect: null,
suppress_notifications: null,
},
send_message: {
title: null,
post: null,
post_builder: null,
post_template: null,
skip_redirect: null,
custom_fields: null,
required: null,
recipient: null,
suppress_notifications: null
},
open_composer: {
title: null,
post: null,
post_builder: null,
post_template: null,
category: null,
tags: null,
custom_fields: null
},
update_profile: {
profile_updates: null,
custom_fields: null
},
watch_categories: {
2020-05-24 09:56:27 +02:00
categories: null,
notification_level: null,
2020-07-20 05:06:36 +02:00
mute_remainder: null,
wizard_user: true,
usernames: null
},
2020-05-30 21:26:14 +02:00
send_to_api: {
api: null,
api_endpoint: null,
api_body: null
},
add_to_group: {
group: null
},
route_to: {
url: null,
code: null
},
create_category: {
name: null,
slug: null,
color: null,
text_color: "FFFFFF",
parent_category_id: null,
permissions: null,
custom_fields: null
2020-07-16 07:25:06 +02:00
},
create_group: {
name: null,
full_name: null,
title: null,
bio_raw: null,
2020-07-16 09:50:09 +02:00
owner_usernames: null,
usernames: null,
2020-07-16 07:25:06 +02:00
grant_trust_level: null,
mentionable_level: null,
messageable_level: null,
visibility_level: null,
members_visibility_level: null,
custom_fields: null
}
},
mapped: [
'title',
'category',
'tags',
2020-07-20 06:26:11 +02:00
'visible',
'custom_fields',
'required',
'recipient',
'profile_updates',
2020-04-29 03:47:08 +02:00
'group',
2020-05-24 09:56:27 +02:00
'url',
'categories',
'mute_remainder',
'name',
'slug',
'color',
'text_color',
'parent_category_id',
2020-07-16 09:50:09 +02:00
'permissions',
'full_name',
'bio_raw',
'owner_usernames',
'usernames',
'grant_trust_level',
'mentionable_level',
'messageable_level',
'visibility_level',
'members_visibility_level'
],
advanced: [
'code',
'custom_fields',
'skip_redirect',
'suppress_notifications',
'required'
],
required: [
'id',
'type'
],
dependent: {
},
objectArrays: {
}
}
const wizardSchema = {
wizard,
step,
field,
2020-05-26 12:52:25 +02:00
action
}
export function buildFieldTypes(types) {
wizardSchema.field.types = types;
}
2021-01-27 06:08:26 +01:00
export function buildFieldValidations(validations) {
wizardSchema.field.validations = validations;
}
if (Discourse.SiteSettings.wizard_apis_enabled) {
wizardSchema.action.types.send_to_api = {
api: null,
api_endpoint: null,
api_body: null
}
}
2020-04-20 11:41:13 +02:00
export function setWizardDefaults(obj, itemType, opts={}) {
const objSchema = wizardSchema[itemType];
const basicDefaults = objSchema.basic;
Object.keys(basicDefaults).forEach(property => {
let defaultValue = get(basicDefaults, property);
if (defaultValue) {
set(obj, property, defaultValue);
}
});
if (objSchema.types) {
const typeDefaults = objSchema.types[obj.type];
if (typeDefaults) {
Object.keys(typeDefaults).forEach(property => {
if (typeDefaults.hasOwnProperty(property)) {
set(obj, property, get(typeDefaults, property));
}
});
}
}
2020-04-20 11:41:13 +02:00
return obj;
}
export default wizardSchema;