discourse/app/serializers/wizard_field_serializer.rb

80 lines
1.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-08-25 12:14:56 -05:00
class WizardFieldSerializer < ApplicationSerializer
attributes :id, :type, :required, :value, :label, :placeholder, :description, :extra_description, :show_in_sidebar
2016-09-07 17:04:01 -05:00
has_many :choices, serializer: WizardFieldChoiceSerializer, embed: :objects
2016-08-25 12:14:56 -05:00
def id
object.id
end
def type
object.type
end
def required
object.required
end
def value
object.value
end
def include_value?
object.value.present?
end
def i18n_key
@i18n_key ||= "wizard.step.#{object.step.id}.fields.#{object.id}".underscore
end
def translate(sub_key, vars = nil)
key = "#{i18n_key}.#{sub_key}"
return nil unless I18n.exists?(key)
vars.nil? ? I18n.t(key) : I18n.t(key, vars)
end
2016-08-25 12:14:56 -05:00
def label
translate("label")
2016-08-25 12:14:56 -05:00
end
def include_label?
label.present?
end
def placeholder
translate("placeholder")
2016-08-25 12:14:56 -05:00
end
def include_placeholder?
placeholder.present?
end
def description
translate("description", base_path: Discourse.base_path)
end
def include_description?
description.present?
end
def extra_description
translate("extra_description", base_path: Discourse.base_path)
end
def include_extra_description?
extra_description.present?
end
def show_in_sidebar
object.show_in_sidebar
end
def include_show_in_sidebar?
object.show_in_sidebar.present?
end
2016-08-25 12:14:56 -05:00
end