Browse Source

Fix start step && add dropdown none

Angus McLeod 7 years ago
parent
commit
75d4fcaab5

+ 5 - 0
assets/javascripts/discourse/templates/components/wizard-custom-field.hbs

@@ -96,5 +96,10 @@
       </div>
       {{wizard-custom-input inputs=field.choices}}
     {{/if}}
+
+    <div class="wizard-header small">
+      {{i18n 'admin.wizard.field.dropdown_none'}}
+    </div>
+    {{input name="dropdown_none" value=field.dropdown_none placeholder=(i18n 'admin.wizard.field.dropdown_none_placeholder')}}
   </div>
 {{/if}}

+ 7 - 0
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"}}

+ 11 - 3
assets/javascripts/wizard/templates/components/wizard-step.hbs

@@ -38,14 +38,22 @@
 
     {{#if showNextButton}}
       <button class='wizard-btn next primary' {{action "nextStep"}} disabled={{saving}} tabindex="10">
-        {{i18n "wizard.next"}}
-        {{d-icon "chevron-right"}}
+        {{#if saving}}
+          {{loading-spinner size='small'}}
+        {{else}}
+          {{i18n "wizard.next"}}
+          {{d-icon "chevron-right"}}
+        {{/if}}
       </button>
     {{/if}}
 
     {{#if showDoneButton}}
       <button class='wizard-btn done' {{action "done"}} disabled={{saving}} tabindex="10">
-        {{i18n "wizard.done"}}
+        {{#if saving}}
+          {{loading-spinner size='small'}}
+        {{else}}
+          {{i18n "wizard.done"}}
+        {{/if}}
       </button>
     {{/if}}
   </div>

+ 5 - 0
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 {

+ 2 - 0
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"

+ 2 - 0
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'])

+ 2 - 1
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

+ 8 - 0
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