Class: Admin::Tramway::Event::ParticipantFormFieldForm

Inherits:
Tramway::Core::ExtendedApplicationForm
  • Object
show all
Defined in:
app/forms/admin/tramway/event/participant_form_field_form.rb

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ ParticipantFormFieldForm

Returns a new instance of ParticipantFormFieldForm.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 7

def initialize(object)
  super(object).tap do
    form_properties event: :association,
                    title: :string,
                    description: :string,
                    field_type: :default,
                    options: :text,
                    list_field: :boolean,
                    presence_field: :boolean,
                    position: :numeric
  end
end

Instance Method Details

#list_fieldObject



29
30
31
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 29

def list_field
  model.options&.dig('list_field') == 'true'
end

#optionsObject



37
38
39
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 37

def options
  model.options&.to_json
end

#options=(value) ⇒ Object



41
42
43
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 41

def options=(value)
  super value == '' ? value : JSON.parse(value)
end

#presence_fieldObject



33
34
35
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 33

def presence_field
  model.options&.dig('validations', 'presence') == 'true'
end

#submit(params) ⇒ Object



20
21
22
23
24
25
26
27
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 20

def submit(params)
  super(params).tap do
    model.options = {} if model.options == ''
    model.options&.merge! list_field: (params[:list_field] == '1').to_s
    model.options&.deep_merge! validations: { presence: (params[:presence_field] == '1').to_s }
    model.save
  end
end