2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-07 18:04:01 -04:00
|
|
|
class WizardFieldChoiceSerializer < ApplicationSerializer
|
2016-09-21 11:22:46 -04:00
|
|
|
attributes :id, :label, :extra_label, :description, :icon, :data
|
2016-09-07 18:04:01 -04:00
|
|
|
|
|
|
|
def id
|
|
|
|
object.id
|
|
|
|
end
|
|
|
|
|
2016-09-09 15:57:44 -04:00
|
|
|
def i18nkey
|
|
|
|
field = object.field
|
|
|
|
step = field.step
|
2024-08-14 08:39:18 -04:00
|
|
|
"wizard.step.#{step.id}.fields.#{field.id}.choices.#{id}".underscore
|
2016-09-09 15:57:44 -04:00
|
|
|
end
|
|
|
|
|
2016-09-07 18:04:01 -04:00
|
|
|
def label
|
|
|
|
return object.label if object.label.present?
|
|
|
|
|
|
|
|
# Try getting one from a translation
|
2016-09-09 15:57:44 -04:00
|
|
|
I18n.t("#{i18nkey}.label", default: id)
|
|
|
|
end
|
|
|
|
|
2016-09-21 11:22:46 -04:00
|
|
|
def extra_label
|
|
|
|
object.extra_label
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_extra_label?
|
|
|
|
object.extra_label.present?
|
|
|
|
end
|
|
|
|
|
2016-09-09 15:57:44 -04:00
|
|
|
def description
|
|
|
|
I18n.t("#{i18nkey}.description", default: "")
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_description?
|
|
|
|
description.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def icon
|
|
|
|
object.icon
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_icon?
|
|
|
|
object.icon.present?
|
2016-09-07 18:04:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
result = object.data.dup
|
|
|
|
result.delete(:id)
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_data?
|
|
|
|
object.data.present?
|
|
|
|
end
|
|
|
|
end
|