Sha256: 512abf85fd19f640c420582e44f12af520bbc4d4cc89b837c4f9b7afc36dc1ae

Contents?: true

Size: 1.21 KB

Versions: 13

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

class Admin::Tramway::Event::ParticipantFormFieldForm < ::Tramway::Core::ExtendedApplicationForm
  properties :title, :description, :field_type, :options, :position, :list_field, :presence_field
  association :event

  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

  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

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

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

  def options
    model.options&.to_json
  end

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
tramway-event-1.11.2 app/forms/admin/tramway/event/participant_form_field_form.rb
tramway-event-1.11.1 app/forms/admin/tramway/event/participant_form_field_form.rb
tramway-event-1.11.0.1 app/forms/admin/tramway/event/participant_form_field_form.rb
tramway-event-1.11 app/forms/admin/tramway/event/participant_form_field_form.rb
tramway-event-1.10.2 app/forms/admin/tramway/event/participant_form_field_form.rb
tramway-event-1.10.1 app/forms/admin/tramway/event/participant_form_field_form.rb
tramway-event-1.10.0.2 app/forms/admin/tramway/event/participant_form_field_form.rb
tramway-event-1.10.0.1 app/forms/admin/tramway/event/participant_form_field_form.rb
tramway-event-1.10 app/forms/admin/tramway/event/participant_form_field_form.rb
tramway-event-1.9.31.2 app/forms/admin/tramway/event/participant_form_field_form.rb
tramway-event-1.9.31.1 app/forms/admin/tramway/event/participant_form_field_form.rb
tramway-event-1.9.31 app/forms/admin/tramway/event/participant_form_field_form.rb
tramway-event-1.9.30 app/forms/admin/tramway/event/participant_form_field_form.rb