diff --git a/assets/javascripts/discourse/lib/wizard-json.js.es6 b/assets/javascripts/discourse/lib/wizard-json.js.es6 index d03f8c97..d56cb35c 100644 --- a/assets/javascripts/discourse/lib/wizard-json.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-json.js.es6 @@ -1,6 +1,7 @@ import { properties, mappedProperties, + advancedProperties, camelCase, snakeCase } from '../lib/wizard'; @@ -205,28 +206,20 @@ function buildObject(json, type) { return EmberObject.create(params); } -function isAdvancedWizard(property, value) { +function wizardHasAdvanced(property, value) { if (property === 'save_submissions' && value == false) return true; if (property === 'restart_on_revisit' && value == true) return true; return false; } -function isAdvancedStep(property, value) { - return mapped(property, 'step') && present(value); +function stepHasAdvanced(property, value) { + return advancedProperties.step[property] && present(value); } -function isAdvancedField(params) { - if (present(params.property)) return true; - if (present(params.prefill)) return true; - if (present(params.content)) return true; - return false; -} - -function isAdvancedAction(params) { - if (present(params.code)) return true; - if (present(params.custom_fields)) return true; - if (present(params.skip_redirect)) return true; - return false; +function hasAdvanced(params, type) { + return Object.keys(params).some(p => { + return advancedProperties[type].indexOf(p) > -1 && present(params[p]); + }); } function buildProperties(json) { @@ -242,7 +235,7 @@ function buildProperties(json) { properties.wizard.forEach((p) => { props[p] = json[p]; - if (isAdvancedWizard(p, json[p])) { + if (wizardHasAdvanced(p, json[p])) { props.showAdvanced = true; } }); @@ -256,7 +249,7 @@ function buildProperties(json) { properties.step.forEach((p) => { stepParams[p] = stepJson[p]; - if (isAdvancedStep(p, stepJson[p])) { + if (stepHasAdvanced(p, stepJson[p])) { stepParams.showAdvanced = true; } }); @@ -266,8 +259,8 @@ function buildProperties(json) { if (present(stepJson.fields)) { stepJson.fields.forEach((f) => { let params = buildObject(f, 'field'); - - if (isAdvancedField(params)) { + + if (hasAdvanced(params, 'field')) { params.showAdvanced = true; } @@ -281,7 +274,7 @@ function buildProperties(json) { stepJson.actions.forEach((a) => { let params = buildObject(a, 'action'); - if (isAdvancedAction(params)) { + if (hasAdvanced(params, 'action')) { params.showAdvanced = true; } diff --git a/assets/javascripts/discourse/lib/wizard.js.es6 b/assets/javascripts/discourse/lib/wizard.js.es6 index 8d448625..1ec21516 100644 --- a/assets/javascripts/discourse/lib/wizard.js.es6 +++ b/assets/javascripts/discourse/lib/wizard.js.es6 @@ -140,6 +140,24 @@ const mappedProperties = { ] } +const advancedProperties = { + step: [ + 'required_data', + 'permitted_params' + ], + field: [ + 'property', + 'prefill', + 'content' + ], + action: [ + 'code', + 'custom_fields', + 'skip_redirect', + 'required' + ] +} + const actionTypes = [ 'create_topic', 'update_profile', @@ -162,5 +180,6 @@ export { wizardProperties, mappedProperties, profileFields, + advancedProperties, actionTypes }; \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index 5ffe275e..6c61eea5 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -9,10 +9,21 @@
- + +
+ +
+ {{i18n 'admin.wizard.field.required_label'}} + {{input type='checkbox' checked=field.required}} +
+
+ +
+
+
- {{input name="key" value=field.key placeholderKey="admin.wizard.translation_placeholder"}} + {{textarea name="description" value=field.description}}
@@ -30,15 +41,6 @@ -
-
- -
-
- {{textarea name="description" value=field.description}} -
-
-
@@ -55,17 +57,6 @@
-
-
- -
- -
- {{i18n 'admin.wizard.field.required_label'}} - {{input type='checkbox' checked=field.required}} -
-
- {{#if isInput}}
@@ -142,6 +133,7 @@ {{#if field.showAdvanced}}
+ {{#if isCategory}}
@@ -183,6 +175,16 @@
{{/if}} + +
+
+ +
+
+ {{input name="key" value=field.key placeholderKey="admin.wizard.translation_placeholder"}} +
+
+
{{/if}} {{/if}} diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs index 4d56893d..76841409 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs @@ -9,18 +9,6 @@
-
-
- -
-
- {{input - name="key" - value=step.key - placeholderKey="admin.wizard.translation_placeholder"}} -
-
-
@@ -89,6 +77,18 @@
+
+
+ +
+
+ {{input + name="key" + value=step.key + placeholderKey="admin.wizard.translation_placeholder"}} +
+
+ {{/if}}