2019-12-12 15:43:11 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-04-13 22:17:22 +10:00
|
|
|
class CustomWizard::FieldSerializer < ::WizardFieldSerializer
|
2019-12-06 20:05:19 +11:00
|
|
|
|
2020-04-06 18:36:38 +10:00
|
|
|
attributes :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,
|
2021-01-30 23:16:04 +05:30
|
|
|
:validations,
|
2021-01-19 12:17:54 +05:30
|
|
|
:max_length,
|
2021-01-20 13:07:44 +05:30
|
|
|
:char_counter,
|
2021-01-19 18:50:37 +11:00
|
|
|
:number
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def description
|
|
|
|
return object.description if object.description.present?
|
|
|
|
I18n.t("#{object.key || i18n_key}.description", default: '', base_url: Discourse.base_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def image
|
|
|
|
object.image
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_image?
|
|
|
|
object.image.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def placeholder
|
|
|
|
I18n.t("#{object.key || i18n_key}.placeholder", default: '')
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_types
|
|
|
|
object.file_types
|
|
|
|
end
|
|
|
|
|
2020-07-16 13:26:56 +10:00
|
|
|
def format
|
|
|
|
object.format
|
|
|
|
end
|
|
|
|
|
2019-12-05 19:05:21 +11:00
|
|
|
def limit
|
|
|
|
object.limit
|
|
|
|
end
|
|
|
|
|
|
|
|
def property
|
|
|
|
object.property
|
|
|
|
end
|
2020-03-24 20:35:46 +11:00
|
|
|
|
2020-03-30 17:16:03 +11:00
|
|
|
def content
|
|
|
|
object.content
|
2020-03-24 20:35:46 +11:00
|
|
|
end
|
2020-04-07 17:54:30 +10:00
|
|
|
|
|
|
|
def include_choices?
|
|
|
|
object.choices.present?
|
|
|
|
end
|
2021-01-12 16:16:24 +05:30
|
|
|
|
2021-01-30 23:16:04 +05:30
|
|
|
def validations
|
|
|
|
validations = {}
|
|
|
|
object.validations&.each do |name, props|
|
|
|
|
next unless props["status"]
|
|
|
|
validations[props["position"]] ||= {}
|
|
|
|
validations[props["position"]][name] = props.merge CustomWizard::RealtimeValidation.types[name.to_sym]
|
|
|
|
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-01-20 13:07:44 +05:30
|
|
|
|
2021-01-19 18:50:37 +11:00
|
|
|
def number
|
|
|
|
object.number
|
|
|
|
end
|
2019-12-05 19:05:21 +11:00
|
|
|
end
|