2019-12-12 15:43:11 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-04-21 03:58:19 +10:00
|
|
|
class CustomWizard::FieldSerializer < ::ApplicationSerializer
|
|
|
|
|
|
|
|
attributes :id,
|
|
|
|
:index,
|
|
|
|
:type,
|
|
|
|
:required,
|
|
|
|
:value,
|
|
|
|
:label,
|
|
|
|
:placeholder,
|
|
|
|
:description,
|
|
|
|
:image,
|
2019-12-12 15:43:11 +11:00
|
|
|
:file_types,
|
2020-07-16 13:26:56 +10:00
|
|
|
:format,
|
2019-12-12 15:43:11 +11:00
|
|
|
:limit,
|
2020-03-24 20:35:46 +11:00
|
|
|
:property,
|
2021-01-12 16:16:24 +05:30
|
|
|
:content,
|
2022-02-07 11:10:52 +05:30
|
|
|
:tag_groups,
|
2021-01-30 23:16:04 +05:30
|
|
|
:validations,
|
2021-01-19 12:17:54 +05:30
|
|
|
:max_length,
|
2021-07-12 17:05:05 +05:30
|
|
|
:char_counter,
|
|
|
|
:preview_template
|
2021-04-21 03:58:19 +10:00
|
|
|
|
|
|
|
def id
|
|
|
|
object.id
|
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
object.index
|
|
|
|
end
|
|
|
|
|
|
|
|
def type
|
|
|
|
object.type
|
|
|
|
end
|
|
|
|
|
|
|
|
def required
|
|
|
|
object.required
|
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
|
|
|
object.value
|
|
|
|
end
|
|
|
|
|
|
|
|
def i18n_key
|
|
|
|
@i18n_key ||= "wizard.step.#{object.step.id}.fields.#{object.id}".underscore
|
|
|
|
end
|
2021-01-19 18:50:37 +11:00
|
|
|
|
2019-12-05 19:05:21 +11:00
|
|
|
def label
|
|
|
|
return object.label if object.label.present?
|
|
|
|
I18n.t("#{object.key || i18n_key}.label", default: '')
|
|
|
|
end
|
|
|
|
|
2021-04-21 03:58:19 +10:00
|
|
|
def include_label?
|
|
|
|
label.present?
|
|
|
|
end
|
|
|
|
|
2019-12-05 19:05:21 +11:00
|
|
|
def description
|
|
|
|
return object.description if object.description.present?
|
|
|
|
I18n.t("#{object.key || i18n_key}.description", default: '', base_url: Discourse.base_url)
|
|
|
|
end
|
|
|
|
|
2021-04-21 03:58:19 +10:00
|
|
|
def include_description?
|
|
|
|
description.present?
|
|
|
|
end
|
|
|
|
|
2019-12-05 19:05:21 +11:00
|
|
|
def image
|
|
|
|
object.image
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_image?
|
|
|
|
object.image.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def placeholder
|
2021-07-03 15:41:49 +05:30
|
|
|
return object.placeholder if object.placeholder.present?
|
2019-12-05 19:05:21 +11:00
|
|
|
I18n.t("#{object.key || i18n_key}.placeholder", default: '')
|
|
|
|
end
|
|
|
|
|
2021-04-21 03:58:19 +10:00
|
|
|
def include_placeholder?
|
|
|
|
placeholder.present?
|
|
|
|
end
|
|
|
|
|
2019-12-05 19:05:21 +11:00
|
|
|
def file_types
|
|
|
|
object.file_types
|
|
|
|
end
|
2021-03-11 17:30:15 +11:00
|
|
|
|
2020-07-16 13:26:56 +10:00
|
|
|
def format
|
|
|
|
object.format
|
|
|
|
end
|
2021-03-11 17:30:15 +11:00
|
|
|
|
2019-12-05 19:05:21 +11:00
|
|
|
def limit
|
|
|
|
object.limit
|
|
|
|
end
|
2021-03-11 17:30:15 +11:00
|
|
|
|
2019-12-05 19:05:21 +11:00
|
|
|
def property
|
|
|
|
object.property
|
|
|
|
end
|
2021-03-11 17:30:15 +11:00
|
|
|
|
2020-03-30 17:16:03 +11:00
|
|
|
def content
|
|
|
|
object.content
|
2020-03-24 20:35:46 +11:00
|
|
|
end
|
2021-03-11 17:30:15 +11:00
|
|
|
|
2022-02-28 12:34:48 +00:00
|
|
|
def tag_groups
|
2022-02-07 11:10:52 +05:30
|
|
|
object.tag_groups
|
|
|
|
end
|
|
|
|
|
2021-01-30 23:16:04 +05:30
|
|
|
def validations
|
|
|
|
validations = {}
|
2021-02-16 11:43:00 +11:00
|
|
|
object.validations&.each do |type, props|
|
2021-01-30 23:16:04 +05:30
|
|
|
next unless props["status"]
|
|
|
|
validations[props["position"]] ||= {}
|
2021-02-16 11:43:00 +11:00
|
|
|
validations[props["position"]][type] = props.merge CustomWizard::RealtimeValidation.types[type.to_sym]
|
2021-01-30 23:16:04 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
validations
|
|
|
|
end
|
|
|
|
|
2021-01-19 12:17:54 +05:30
|
|
|
def max_length
|
|
|
|
object.max_length
|
|
|
|
end
|
|
|
|
|
2021-01-12 16:16:24 +05:30
|
|
|
def char_counter
|
|
|
|
object.char_counter
|
|
|
|
end
|
2021-07-12 17:05:05 +05:30
|
|
|
|
|
|
|
def preview_template
|
|
|
|
object.preview_template
|
|
|
|
end
|
2021-03-11 17:30:15 +11:00
|
|
|
end
|