2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-25 13:14:56 -04:00
|
|
|
class WizardFieldSerializer < ApplicationSerializer
|
2022-08-14 20:22:07 -04:00
|
|
|
attributes :id,
|
|
|
|
:type,
|
|
|
|
:required,
|
|
|
|
:value,
|
|
|
|
:label,
|
|
|
|
:placeholder,
|
|
|
|
:description,
|
|
|
|
:extra_description,
|
|
|
|
:icon,
|
|
|
|
:disabled,
|
|
|
|
:show_in_sidebar
|
2016-09-07 18:04:01 -04:00
|
|
|
has_many :choices, serializer: WizardFieldChoiceSerializer, embed: :objects
|
2016-08-25 13:14:56 -04: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-07 11:59:42 -05: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-25 13:14:56 -04:00
|
|
|
def label
|
2018-11-07 11:59:42 -05:00
|
|
|
translate("label")
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def include_label?
|
|
|
|
label.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def placeholder
|
2018-11-07 11:59:42 -05:00
|
|
|
translate("placeholder")
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def include_placeholder?
|
|
|
|
placeholder.present?
|
|
|
|
end
|
2016-08-31 13:35:49 -04:00
|
|
|
|
|
|
|
def description
|
2018-11-07 11:59:42 -05:00
|
|
|
translate("description", base_path: Discourse.base_path)
|
2016-08-31 13:35:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def include_description?
|
|
|
|
description.present?
|
|
|
|
end
|
|
|
|
|
2020-11-09 15:14:57 -05:00
|
|
|
def extra_description
|
|
|
|
translate("extra_description", base_path: Discourse.base_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_extra_description?
|
|
|
|
extra_description.present?
|
|
|
|
end
|
|
|
|
|
2022-07-26 21:23:01 -04:00
|
|
|
def icon
|
|
|
|
object.icon
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_icon?
|
|
|
|
object.icon.present?
|
|
|
|
end
|
|
|
|
|
2022-08-14 20:22:07 -04:00
|
|
|
def disabled
|
|
|
|
object.disabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_disabled?
|
|
|
|
object.disabled
|
|
|
|
end
|
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
def show_in_sidebar
|
|
|
|
object.show_in_sidebar
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_show_in_sidebar?
|
|
|
|
object.show_in_sidebar.present?
|
|
|
|
end
|
|
|
|
|
2022-06-06 03:22:44 -04:00
|
|
|
def include_choices?
|
|
|
|
object.type == "dropdown" || object.type == "radio"
|
|
|
|
end
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|