2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-26 01:14:56 +08:00
|
|
|
class WizardFieldSerializer < ApplicationSerializer
|
|
|
|
|
2016-09-08 06:04:01 +08:00
|
|
|
attributes :id, :type, :required, :value, :label, :placeholder, :description
|
|
|
|
has_many :choices, serializer: WizardFieldChoiceSerializer, embed: :objects
|
2016-08-26 01:14:56 +08: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
|
|
|
|
|
2018-11-08 00:59:42 +08:00
|
|
|
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-26 01:14:56 +08:00
|
|
|
def label
|
2018-11-08 00:59:42 +08:00
|
|
|
translate("label")
|
2016-08-26 01:14:56 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def include_label?
|
|
|
|
label.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def placeholder
|
2018-11-08 00:59:42 +08:00
|
|
|
translate("placeholder")
|
2016-08-26 01:14:56 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def include_placeholder?
|
|
|
|
placeholder.present?
|
|
|
|
end
|
2016-09-01 01:35:49 +08:00
|
|
|
|
|
|
|
def description
|
2018-11-08 00:59:42 +08:00
|
|
|
translate("description", base_path: Discourse.base_path)
|
2016-09-01 01:35:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def include_description?
|
|
|
|
description.present?
|
|
|
|
end
|
|
|
|
|
2016-08-26 01:14:56 +08:00
|
|
|
end
|