2021-04-12 07:10:02 +02:00
|
|
|
import { get, set } from "@ember/object";
|
2021-05-05 08:05:53 +02:00
|
|
|
import { getOwner } from "discourse-common/lib/get-owner";
|
2020-04-16 04:04:27 +02:00
|
|
|
|
|
|
|
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,
|
2021-09-22 10:22:05 +02:00
|
|
|
resume_on_revisit: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
theme_id: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
permitted: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
2021-03-28 11:06:49 +02:00
|
|
|
mapped: ["permitted"],
|
|
|
|
advanced: ["restart_on_revisit"],
|
|
|
|
required: ["id"],
|
2020-04-16 04:04:27 +02:00
|
|
|
dependent: {
|
2021-03-28 11:06:49 +02:00
|
|
|
after_time: "after_time_scheduled",
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
objectArrays: {
|
|
|
|
step: {
|
2021-03-28 11:06:49 +02:00
|
|
|
property: "steps",
|
|
|
|
required: false,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
action: {
|
2021-03-28 11:06:49 +02:00
|
|
|
property: "actions",
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
},
|
2020-04-16 04:04:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const step = {
|
|
|
|
basic: {
|
|
|
|
id: null,
|
2021-04-20 19:58:19 +02:00
|
|
|
index: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
title: null,
|
|
|
|
key: null,
|
|
|
|
banner: null,
|
2022-08-02 13:39:56 +02:00
|
|
|
banner_upload_id: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
raw_description: null,
|
|
|
|
required_data: null,
|
|
|
|
required_data_message: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
permitted_params: null,
|
2021-04-20 19:58:19 +02:00
|
|
|
condition: null,
|
|
|
|
force_final: false,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
2021-04-20 19:58:19 +02:00
|
|
|
mapped: ["required_data", "permitted_params", "condition", "index"],
|
|
|
|
advanced: ["required_data", "permitted_params", "condition", "index"],
|
2021-03-28 11:06:49 +02:00
|
|
|
required: ["id"],
|
|
|
|
dependent: {},
|
2020-04-16 04:04:27 +02:00
|
|
|
objectArrays: {
|
|
|
|
field: {
|
2021-03-28 11:06:49 +02:00
|
|
|
property: "fields",
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-04-16 04:04:27 +02:00
|
|
|
|
|
|
|
const field = {
|
|
|
|
basic: {
|
|
|
|
id: null,
|
2021-04-20 19:58:19 +02:00
|
|
|
index: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
label: null,
|
|
|
|
image: null,
|
2022-08-02 13:39:56 +02:00
|
|
|
image_upload_id: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
description: null,
|
|
|
|
required: null,
|
|
|
|
key: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
type: null,
|
2021-04-20 19:58:19 +02:00
|
|
|
condition: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
types: {},
|
2021-04-20 19:58:19 +02:00
|
|
|
mapped: ["prefill", "content", "condition", "index"],
|
|
|
|
advanced: ["property", "key", "condition", "index"],
|
2021-03-28 11:06:49 +02:00
|
|
|
required: ["id", "type"],
|
|
|
|
dependent: {},
|
|
|
|
objectArrays: {},
|
|
|
|
};
|
2020-04-16 04:04:27 +02:00
|
|
|
|
|
|
|
const action = {
|
|
|
|
basic: {
|
|
|
|
id: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
run_after: "wizard_completion",
|
|
|
|
type: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
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,
|
2020-04-16 04:04:27 +02:00
|
|
|
custom_fields: null,
|
2020-10-20 02:42:10 +02:00
|
|
|
skip_redirect: null,
|
|
|
|
suppress_notifications: null,
|
2022-09-19 12:09:34 +02:00
|
|
|
add_event: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
send_message: {
|
|
|
|
title: null,
|
|
|
|
post: null,
|
|
|
|
post_builder: null,
|
|
|
|
post_template: null,
|
|
|
|
skip_redirect: null,
|
|
|
|
custom_fields: null,
|
|
|
|
required: null,
|
2020-10-20 02:42:10 +02:00
|
|
|
recipient: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
suppress_notifications: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
open_composer: {
|
|
|
|
title: null,
|
|
|
|
post: null,
|
|
|
|
post_builder: null,
|
|
|
|
post_template: null,
|
|
|
|
category: null,
|
|
|
|
tags: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
custom_fields: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
update_profile: {
|
|
|
|
profile_updates: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
custom_fields: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
2020-05-23 00:42:26 +02:00
|
|
|
watch_categories: {
|
2020-05-24 09:56:27 +02:00
|
|
|
categories: null,
|
2020-05-25 15:59:31 +02:00
|
|
|
notification_level: null,
|
2020-07-20 05:06:36 +02:00
|
|
|
mute_remainder: null,
|
|
|
|
wizard_user: true,
|
2021-03-28 11:06:49 +02:00
|
|
|
usernames: null,
|
2020-05-23 00:42:26 +02:00
|
|
|
},
|
2020-05-30 21:26:14 +02:00
|
|
|
send_to_api: {
|
|
|
|
api: null,
|
|
|
|
api_endpoint: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
api_body: null,
|
2020-05-30 21:26:14 +02:00
|
|
|
},
|
2020-04-16 04:04:27 +02:00
|
|
|
add_to_group: {
|
2021-03-28 11:06:49 +02:00
|
|
|
group: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
route_to: {
|
|
|
|
url: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
code: null,
|
2020-07-09 04:19:36 +02:00
|
|
|
},
|
|
|
|
create_category: {
|
|
|
|
name: null,
|
|
|
|
slug: null,
|
|
|
|
color: null,
|
|
|
|
text_color: "FFFFFF",
|
|
|
|
parent_category_id: null,
|
2020-07-17 04:10:59 +02:00
|
|
|
permissions: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
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,
|
2020-07-17 04:10:59 +02:00
|
|
|
members_visibility_level: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
custom_fields: null,
|
|
|
|
},
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
mapped: [
|
2021-03-28 11:06:49 +02:00
|
|
|
"title",
|
|
|
|
"category",
|
|
|
|
"tags",
|
|
|
|
"visible",
|
|
|
|
"custom_fields",
|
|
|
|
"required",
|
|
|
|
"recipient",
|
|
|
|
"profile_updates",
|
|
|
|
"group",
|
|
|
|
"url",
|
|
|
|
"categories",
|
|
|
|
"mute_remainder",
|
|
|
|
"name",
|
|
|
|
"slug",
|
|
|
|
"color",
|
|
|
|
"text_color",
|
|
|
|
"parent_category_id",
|
|
|
|
"permissions",
|
|
|
|
"full_name",
|
|
|
|
"bio_raw",
|
|
|
|
"owner_usernames",
|
|
|
|
"usernames",
|
|
|
|
"grant_trust_level",
|
|
|
|
"mentionable_level",
|
|
|
|
"messageable_level",
|
|
|
|
"visibility_level",
|
|
|
|
"members_visibility_level",
|
2022-09-19 12:09:34 +02:00
|
|
|
"add_event",
|
2020-04-16 04:04:27 +02:00
|
|
|
],
|
|
|
|
advanced: [
|
2021-03-28 11:06:49 +02:00
|
|
|
"code",
|
|
|
|
"custom_fields",
|
|
|
|
"skip_redirect",
|
|
|
|
"suppress_notifications",
|
|
|
|
"required",
|
2020-04-16 04:04:27 +02:00
|
|
|
],
|
2021-03-28 11:06:49 +02:00
|
|
|
required: ["id", "type"],
|
|
|
|
dependent: {},
|
|
|
|
objectArrays: {},
|
|
|
|
};
|
2020-04-16 04:04:27 +02:00
|
|
|
|
|
|
|
const wizardSchema = {
|
|
|
|
wizard,
|
|
|
|
step,
|
|
|
|
field,
|
2021-03-28 11:06:49 +02:00
|
|
|
action,
|
|
|
|
};
|
2020-04-16 04:04:27 +02:00
|
|
|
|
|
|
|
export function buildFieldTypes(types) {
|
|
|
|
wizardSchema.field.types = types;
|
|
|
|
}
|
|
|
|
|
2021-01-27 06:08:26 +01:00
|
|
|
export function buildFieldValidations(validations) {
|
|
|
|
wizardSchema.field.validations = validations;
|
|
|
|
}
|
|
|
|
|
2022-08-15 13:53:31 +02:00
|
|
|
const siteSettings = getOwner(this).lookup("service:site-settings");
|
2021-05-05 08:05:53 +02:00
|
|
|
if (siteSettings.wizard_apis_enabled) {
|
2020-04-16 04:04:27 +02:00
|
|
|
wizardSchema.action.types.send_to_api = {
|
|
|
|
api: null,
|
|
|
|
api_endpoint: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
api_body: null,
|
|
|
|
};
|
2020-04-16 04:04:27 +02:00
|
|
|
}
|
|
|
|
|
2021-04-12 07:44:47 +02:00
|
|
|
export function setWizardDefaults(obj, itemType) {
|
2020-04-20 11:41:13 +02:00
|
|
|
const objSchema = wizardSchema[itemType];
|
|
|
|
const basicDefaults = objSchema.basic;
|
2021-03-28 11:06:49 +02:00
|
|
|
|
|
|
|
Object.keys(basicDefaults).forEach((property) => {
|
2020-04-20 11:41:13 +02:00
|
|
|
let defaultValue = get(basicDefaults, property);
|
|
|
|
if (defaultValue) {
|
|
|
|
set(obj, property, defaultValue);
|
2020-04-16 04:04:27 +02:00
|
|
|
}
|
|
|
|
});
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-20 23:21:44 +02:00
|
|
|
if (objSchema.types) {
|
|
|
|
const typeDefaults = objSchema.types[obj.type];
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-20 23:21:44 +02:00
|
|
|
if (typeDefaults) {
|
2021-03-28 11:06:49 +02:00
|
|
|
Object.keys(typeDefaults).forEach((property) => {
|
2020-04-20 23:21:44 +02:00
|
|
|
if (typeDefaults.hasOwnProperty(property)) {
|
|
|
|
set(obj, property, get(typeDefaults, property));
|
2021-03-28 11:06:49 +02:00
|
|
|
}
|
2020-04-20 23:21:44 +02:00
|
|
|
});
|
|
|
|
}
|
2020-04-16 04:04:27 +02:00
|
|
|
}
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-20 11:41:13 +02:00
|
|
|
return obj;
|
2020-04-16 04:04:27 +02:00
|
|
|
}
|
|
|
|
|
2021-03-28 11:06:49 +02:00
|
|
|
export default wizardSchema;
|