From 75d4fcaab5aa7009fe8071e406e31c2180413730 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 9 Nov 2017 10:50:48 +0800 Subject: [PATCH] Fix start step && add dropdown none --- .../templates/components/wizard-custom-field.hbs | 5 +++++ .../templates/components/wizard-field-dropdown.hbs | 7 +++++++ .../wizard/templates/components/wizard-step.hbs | 14 +++++++++++--- assets/stylesheets/wizard/wizard_custom.scss | 5 +++++ config/locales/client.en.yml | 2 ++ lib/builder.rb | 2 ++ lib/wizard.rb | 3 ++- lib/wizard_edits.rb | 8 ++++++++ 8 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index 5e15075c..38a23f26 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -96,5 +96,10 @@ {{wizard-custom-input inputs=field.choices}} {{/if}} + +
+ {{i18n 'admin.wizard.field.dropdown_none'}} +
+ {{input name="dropdown_none" value=field.dropdown_none placeholder=(i18n 'admin.wizard.field.dropdown_none_placeholder')}} {{/if}} diff --git a/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs b/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs new file mode 100644 index 00000000..0b7d55c0 --- /dev/null +++ b/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs @@ -0,0 +1,7 @@ +{{combo-box elementId=field.id + class=fieldClass + value=field.value + content=field.choices + none=field.dropdown_none + nameProperty="label" + tabindex="9"}} diff --git a/assets/javascripts/wizard/templates/components/wizard-step.hbs b/assets/javascripts/wizard/templates/components/wizard-step.hbs index 746fdc6c..de068ca9 100644 --- a/assets/javascripts/wizard/templates/components/wizard-step.hbs +++ b/assets/javascripts/wizard/templates/components/wizard-step.hbs @@ -38,14 +38,22 @@ {{#if showNextButton}} {{/if}} {{#if showDoneButton}} {{/if}} diff --git a/assets/stylesheets/wizard/wizard_custom.scss b/assets/stylesheets/wizard/wizard_custom.scss index da64792d..8b891d13 100644 --- a/assets/stylesheets/wizard/wizard_custom.scss +++ b/assets/stylesheets/wizard/wizard_custom.scss @@ -68,6 +68,11 @@ .combo-box ul { padding: 0; } + + .wizard-buttons > a, .wizard-buttons > button { + display: inline-block; + vertical-align: middle; + } } .step-message { diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index ee27889f..42d12b62 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -60,6 +60,8 @@ en: header: "Fields" label: "Label" description: "Description" + dropdown_none: "None" + dropdown_none_placeholder: "Translation Key" choices_label: "Dropdown Choices" choices_type: "Choose a type" choices_translation: "Translation" diff --git a/lib/builder.rb b/lib/builder.rb index 6f74e53f..49a3e62c 100644 --- a/lib/builder.rb +++ b/lib/builder.rb @@ -80,6 +80,8 @@ class CustomWizard::Builder field = step.add_field(params) if f['type'] === 'dropdown' + field.dropdown_none = f['dropdown_none'] if f['dropdown_none'] + if f['choices'] && f['choices'].length > 0 f['choices'].each do |c| field.add_choice(c['value'], label: c['label']) diff --git a/lib/wizard.rb b/lib/wizard.rb index cc1db24f..2e32d38a 100644 --- a/lib/wizard.rb +++ b/lib/wizard.rb @@ -58,7 +58,8 @@ class CustomWizard::Wizard context: @id, subject: @steps.map(&:id) ).order("created_at").last.subject - @steps.find { |s| s.id == step_id } + last_index = @steps.index { |s| s.id == step_id } + @steps[last_index + 1] else @first_step end diff --git a/lib/wizard_edits.rb b/lib/wizard_edits.rb index 7b327b92..d9b8b58b 100644 --- a/lib/wizard_edits.rb +++ b/lib/wizard_edits.rb @@ -25,6 +25,7 @@ end ::Wizard::Field.class_eval do attr_reader :label, :description, :key, :min_length + attr_accessor :dropdown_none def initialize(attrs) attrs = attrs || {} @@ -38,6 +39,7 @@ end @min_length = attrs[:min_length] @value = attrs[:value] @choices = [] + @dropdown_none = attrs[:dropdown_none] end end @@ -102,6 +104,8 @@ end end ::WizardFieldSerializer.class_eval do + attributes :dropdown_none + def label return object.label if object.label I18n.t("#{object.key || i18n_key}.label", default: '') @@ -115,4 +119,8 @@ end def placeholder I18n.t("#{object.key || i18n_key}.placeholder", default: '') end + + def dropdown_none + object.dropdown_none + end end