2020-04-20 11:41:13 +02:00
|
|
|
import { set, get } from "@ember/object";
|
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,
|
|
|
|
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,
|
|
|
|
title: null,
|
|
|
|
key: null,
|
|
|
|
banner: null,
|
|
|
|
raw_description: null,
|
|
|
|
required_data: null,
|
|
|
|
required_data_message: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
permitted_params: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
2021-03-28 11:06:49 +02:00
|
|
|
mapped: ["required_data", "permitted_params"],
|
|
|
|
advanced: ["required_data", "permitted_params"],
|
|
|
|
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
|
|
|
|
2021-03-29 08:17:57 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* unit: custom_wizard:templates_and_builder
|
|
|
|
* type: step
|
|
|
|
* number: 2
|
|
|
|
* title: Add the attribute to the wizard schema
|
|
|
|
* description: Custom Wizard templates are modeled in the client via
|
|
|
|
* the wizard-schema, which, along with the serialization in
|
|
|
|
* wizard-json and models/custom-wizard, models and serializes
|
|
|
|
* data on the client. Normally when adding an attribute, you
|
|
|
|
* just need to add it to the schema, for the rest of the
|
|
|
|
* modeling and serialization to work.
|
|
|
|
*/
|
|
|
|
|
2020-04-16 04:04:27 +02:00
|
|
|
const field = {
|
|
|
|
basic: {
|
|
|
|
id: null,
|
|
|
|
label: null,
|
|
|
|
image: null,
|
|
|
|
description: null,
|
|
|
|
required: null,
|
|
|
|
key: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
type: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
types: {},
|
2021-03-28 11:06:49 +02:00
|
|
|
mapped: ["prefill", "content"],
|
|
|
|
advanced: ["property", "key"],
|
|
|
|
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,
|
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",
|
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;
|
|
|
|
}
|
|
|
|
|
2020-04-16 04:04:27 +02:00
|
|
|
if (Discourse.SiteSettings.wizard_apis_enabled) {
|
|
|
|
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-03-28 11:06:49 +02:00
|
|
|
export function setWizardDefaults(obj, itemType, opts = {}) {
|
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;
|