2019-12-12 05:43:11 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-04-20 19:58:19 +02:00
|
|
|
class CustomWizard::FieldSerializer < ::ApplicationSerializer
|
|
|
|
|
|
|
|
attributes :id,
|
|
|
|
:index,
|
|
|
|
:type,
|
|
|
|
:required,
|
|
|
|
:value,
|
|
|
|
:label,
|
|
|
|
:placeholder,
|
|
|
|
:description,
|
|
|
|
:image,
|
2019-12-12 05:43:11 +01:00
|
|
|
:file_types,
|
2020-07-16 05:26:56 +02:00
|
|
|
:format,
|
2019-12-12 05:43:11 +01:00
|
|
|
:limit,
|
2020-03-24 10:35:46 +01:00
|
|
|
:property,
|
2021-01-12 11:46:24 +01:00
|
|
|
:content,
|
2021-01-30 18:46:04 +01:00
|
|
|
:validations,
|
2021-01-19 07:47:54 +01:00
|
|
|
:max_length,
|
2021-07-12 13:35:05 +02:00
|
|
|
:char_counter,
|
|
|
|
:preview_template
|
2021-04-20 19:58:19 +02: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
|
|
|
|
|
2019-12-05 09:05:21 +01:00
|
|
|
def label
|
2021-09-14 05:33:16 +02:00
|
|
|
I18n.t("#{i18n_key}.label", default: object.label, base_url: Discourse.base_url)
|
2019-12-05 09:05:21 +01:00
|
|
|
end
|
|
|
|
|
2021-04-20 19:58:19 +02:00
|
|
|
def include_label?
|
|
|
|
label.present?
|
|
|
|
end
|
|
|
|
|
2019-12-05 09:05:21 +01:00
|
|
|
def description
|
2021-09-14 05:33:16 +02:00
|
|
|
I18n.t("#{i18n_key}.description", default: object.description, base_url: Discourse.base_url)
|
2019-12-05 09:05:21 +01:00
|
|
|
end
|
|
|
|
|
2021-04-20 19:58:19 +02:00
|
|
|
def include_description?
|
|
|
|
description.present?
|
|
|
|
end
|
|
|
|
|
2021-09-14 05:33:16 +02:00
|
|
|
def placeholder
|
|
|
|
I18n.t("#{i18n_key}.placeholder", default: object.placeholder)
|
2019-12-05 09:05:21 +01:00
|
|
|
end
|
|
|
|
|
2021-09-14 05:33:16 +02:00
|
|
|
def include_placeholder?
|
|
|
|
placeholder.present?
|
2019-12-05 09:05:21 +01:00
|
|
|
end
|
|
|
|
|
2021-09-14 05:33:16 +02:00
|
|
|
def image
|
|
|
|
object.image
|
2019-12-05 09:05:21 +01:00
|
|
|
end
|
|
|
|
|
2021-09-14 05:33:16 +02:00
|
|
|
def include_image?
|
|
|
|
object.image.present?
|
2021-04-20 19:58:19 +02:00
|
|
|
end
|
|
|
|
|
2019-12-05 09:05:21 +01:00
|
|
|
def file_types
|
|
|
|
object.file_types
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-07-16 05:26:56 +02:00
|
|
|
def format
|
|
|
|
object.format
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2019-12-05 09:05:21 +01:00
|
|
|
def limit
|
|
|
|
object.limit
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2019-12-05 09:05:21 +01:00
|
|
|
def property
|
|
|
|
object.property
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-03-30 08:16:03 +02:00
|
|
|
def content
|
|
|
|
object.content
|
2020-03-24 10:35:46 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2021-01-30 18:46:04 +01:00
|
|
|
def validations
|
|
|
|
validations = {}
|
2021-02-16 01:43:00 +01:00
|
|
|
object.validations&.each do |type, props|
|
2021-01-30 18:46:04 +01:00
|
|
|
next unless props["status"]
|
|
|
|
validations[props["position"]] ||= {}
|
2021-02-16 01:43:00 +01:00
|
|
|
validations[props["position"]][type] = props.merge CustomWizard::RealtimeValidation.types[type.to_sym]
|
2021-01-30 18:46:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
validations
|
|
|
|
end
|
|
|
|
|
2021-01-19 07:47:54 +01:00
|
|
|
def max_length
|
|
|
|
object.max_length
|
|
|
|
end
|
|
|
|
|
2021-01-12 11:46:24 +01:00
|
|
|
def char_counter
|
|
|
|
object.char_counter
|
|
|
|
end
|
2021-07-12 13:35:05 +02:00
|
|
|
|
|
|
|
def preview_template
|
|
|
|
object.preview_template
|
|
|
|
end
|
2021-09-14 05:33:16 +02:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def i18n_key
|
|
|
|
@i18n_key ||= "#{object.step.wizard.id}.#{object.step.id}.#{object.id}".underscore
|
|
|
|
end
|
|
|
|
|
|
|
|
def subscribed?
|
|
|
|
@subscribed ||= CustomWizard::Pro.subscribed?
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
end
|