diff --git a/assets/javascripts/discourse/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6 index eef10686..dc3f2c12 100644 --- a/assets/javascripts/discourse/models/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard.js.es6 @@ -78,6 +78,7 @@ const CustomWizard = Discourse.Model.extend({ if (s.banner) step['banner'] = s.banner; if (s.raw_description) step['raw_description'] = s.raw_description; if (s.required_data) step['required_data'] = s.required_data; + if (s.required_data_message) step['required_data_message'] = s.required_data_message; if (s.permitted_params) step['permitted_params'] = s.permitted_params; const fields = s.get('fields'); @@ -245,6 +246,7 @@ CustomWizard.reopenClass({ raw_description: s.raw_description, banner: s.banner, required_data: s.required_data, + required_data_message: s.required_data_message, permitted_params: s.permitted_params, fields, actions, diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs index 0d6eb618..610bf16b 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs @@ -43,7 +43,7 @@ -
+

{{i18n 'admin.wizard.step.required_data.label'}}

@@ -52,6 +52,12 @@ inputKey='admin.wizard.step.required_data.key' valueContent=requiredContent connectorContent=requiredConnectorContent}} + {{#if step.required_data}} +
+ + {{input value=step.required_data_message}} +
+ {{/if}}
diff --git a/assets/javascripts/wizard/controllers/custom-step.js.es6 b/assets/javascripts/wizard/controllers/custom-step.js.es6 index fcfe2688..01f02753 100644 --- a/assets/javascripts/wizard/controllers/custom-step.js.es6 +++ b/assets/javascripts/wizard/controllers/custom-step.js.es6 @@ -21,6 +21,12 @@ export default StepController.extend({ showMessage(message) { this.set('stepMessage', message); + }, + + resetWizard() { + const id = this.get('wizard.id'); + const stepId = this.get('step.id'); + window.location.href = getUrl(`/w/${id}/steps/${stepId}?reset=true`); } } }); diff --git a/assets/javascripts/wizard/routes/custom-step.js.es6 b/assets/javascripts/wizard/routes/custom-step.js.es6 index ae3e2ddf..bba4b49f 100644 --- a/assets/javascripts/wizard/routes/custom-step.js.es6 +++ b/assets/javascripts/wizard/routes/custom-step.js.es6 @@ -24,8 +24,11 @@ export default Ember.Route.extend({ if (!model.permitted) { props['stepMessage'] = { state: 'not-permitted', - text: "You're not allowed to view this step." + text: model.permitted_message || I18n.t('wizard.step_not_permitted') }; + if (model.index > 0) { + props['showReset'] = true; + } } controller.setProperties(props); diff --git a/assets/javascripts/wizard/templates/custom.step.hbs b/assets/javascripts/wizard/templates/custom.step.hbs index b0a39637..cd4bec24 100644 --- a/assets/javascripts/wizard/templates/custom.step.hbs +++ b/assets/javascripts/wizard/templates/custom.step.hbs @@ -1,5 +1,12 @@
- {{stepMessage.text}} +
+ {{stepMessage.text}} +
+ {{#if showReset}} + + {{i18n 'wizard.reset'}} + + {{/if}}
{{#if step.permitted}} {{wizard-step step=step diff --git a/assets/stylesheets/wizard/wizard_custom.scss b/assets/stylesheets/wizard/wizard_custom.scss index b718bf41..db17c350 100644 --- a/assets/stylesheets/wizard/wizard_custom.scss +++ b/assets/stylesheets/wizard/wizard_custom.scss @@ -270,36 +270,35 @@ } .step-message { - position: absolute; - top: 0; - left: 0; - right: 0; - height: 0; - line-height: 0; text-align: center; transition: all .2s; z-index: 2; + padding: 20px; &.success { - height: 60px; - line-height: 60px; background-color: #009900; color: #ffffff; } &.error { - height: 60px; - line-height: 60px; background-color: #e45735; color: #ffffff; } &.not-permitted { - height: 60px; - line-height: 60px; background-color: #e45735; color: #ffffff; } + + .text { + display: inline-block; + } + + .reset-wizard { + margin-top: 20px; + text-decoration: underline; + cursor: pointer; + } } .p-list-box { diff --git a/assets/stylesheets/wizard_custom_admin.scss b/assets/stylesheets/wizard_custom_admin.scss index 0cfb4bb7..1f6d58e6 100644 --- a/assets/stylesheets/wizard_custom_admin.scss +++ b/assets/stylesheets/wizard_custom_admin.scss @@ -222,6 +222,14 @@ } } +.required-data .setting-value { + flex-flow: wrap; + + .custom-inputs { + margin-bottom: 20px; + } +} + .setting .add-custom-input { margin-top: 5px; } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 3c1ce1e0..0aa235d8 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -77,6 +77,7 @@ en: key: 'Submission key' connector: equals: "Equals" + not_permitted_message: "Message shown when required data not present" permitted_params: label: "Permitted Params" key: 'Param' @@ -279,6 +280,8 @@ en: none: "There is no wizard here." return_to_site: "Return to {{siteName}}" requires_login: "You need to be logged in to access the {{name}} wizard." + reset: "Reset this wizard." + step_not_permitted: "You're not allowed to view this step." wizard_composer: show_preview: "Preview Post" diff --git a/lib/builder.rb b/lib/builder.rb index 221a95e3..b6f1c8c8 100644 --- a/lib/builder.rb +++ b/lib/builder.rb @@ -94,8 +94,11 @@ class CustomWizard::Builder step.permitted = @submissions.last[rd['key']] == @submissions.last[rd['value']] end end - - next if !step.permitted + + if !step.permitted + step.permitted_message = step_template['required_data_message'] if step_template['required_data_message'] + next + end end if step_template['fields'] && step_template['fields'].length diff --git a/lib/wizard_edits.rb b/lib/wizard_edits.rb index d8e56ed1..11aa7ed8 100644 --- a/lib/wizard_edits.rb +++ b/lib/wizard_edits.rb @@ -63,7 +63,7 @@ end end class ::Wizard::Step - attr_accessor :title, :description, :key, :permitted + attr_accessor :title, :description, :key, :permitted, :permitted_message end ::WizardSerializer.class_eval do @@ -159,7 +159,7 @@ end end ::WizardStepSerializer.class_eval do - attributes :permitted + attributes :permitted, :permitted_message def title return PrettyText.cook(object.title) if object.title @@ -174,6 +174,10 @@ end def permitted object.permitted end + + def permitted_message + object.permitted_message + end end ::WizardFieldSerializer.class_eval do