Add locale step

This commit is contained in:
Robin Ward
2016-09-07 18:04:01 -04:00
parent 3f6e3b9aff
commit c94e6f1b96
25 changed files with 746 additions and 90 deletions

View File

@@ -0,0 +1,26 @@
class WizardFieldChoiceSerializer < ApplicationSerializer
attributes :id, :label, :data
def id
object.id
end
def label
return object.label if object.label.present?
# Try getting one from a translation
field = object.field
step = field.step
I18n.t("wizard.step.#{step.id}.fields.#{field.id}.options.#{id}", default: id)
end
def data
result = object.data.dup
result.delete(:id)
result
end
def include_data?
object.data.present?
end
end

View File

@@ -1,6 +1,7 @@
class WizardFieldSerializer < ApplicationSerializer
attributes :id, :type, :required, :value, :label, :placeholder, :description, :options
attributes :id, :type, :required, :value, :label, :placeholder, :description
has_many :choices, serializer: WizardFieldChoiceSerializer, embed: :objects
def id
object.id
@@ -50,24 +51,4 @@ class WizardFieldSerializer < ApplicationSerializer
description.present?
end
def options
object.options.map do |o|
result = {id: o, label: I18n.t("#{i18n_key}.options.#{o}")}
data = object.option_data[o]
if data.present?
as_json = data.dup
as_json.delete(:id)
result[:data] = as_json
end
result
end
end
def include_options?
object.options.present?
end
end