Sha256: 23657018c26ee7b49529049dacca6a2a8097ba932f17122bddc4caf51e8c97af

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

class Avo::Fields::TrixField::EditComponent < Avo::Fields::EditComponent
  attr_reader :resource

  def initialize(**args)
    @resource = args[:resource]
    @resource_id = args[:resource_id] || @resource&.record&.to_param
    @resource_name = args[:resource_name] || @resource&.singular_route_key

    super(**args)
  end

  def trix_id
    if @resource_name.present?
      "trix_#{@resource_name}_#{@field.id}"
    elsif form.present?
      "trix_#{form.index}_#{@field.id}"
    end
  end

  def data_values
    {
      resource_name: @resource_name,
      resource_id: @resource_id,
      attachments_disabled: @field.attachments_disabled,
      attachment_key: @field.attachment_key,
      hide_attachment_filename: @field.hide_attachment_filename,
      hide_attachment_filesize: @field.hide_attachment_filesize,
      hide_attachment_url: @field.hide_attachment_url,
      is_action_text: @field.is_action_text?,
      upload_warning: t("avo.you_cant_upload_new_resource"),
      attachment_disable_warning: t("avo.this_field_has_attachments_disabled"),
      attachment_key_warning: t("avo.you_havent_set_attachment_key")
    }.transform_keys { |key| "trix_field_#{key}_value" }
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
avo-3.15.1 app/components/avo/fields/trix_field/edit_component.rb
avo-3.15.0 app/components/avo/fields/trix_field/edit_component.rb
avo-3.14.5 app/components/avo/fields/trix_field/edit_component.rb
avo-3.14.4 app/components/avo/fields/trix_field/edit_component.rb
avo-3.14.3 app/components/avo/fields/trix_field/edit_component.rb
avo-3.14.2 app/components/avo/fields/trix_field/edit_component.rb
avo-3.14.1 app/components/avo/fields/trix_field/edit_component.rb
avo-3.14.0 app/components/avo/fields/trix_field/edit_component.rb