Class: Avo::Fields::TrixField::EditComponent

Inherits:
EditComponent show all
Defined in:
app/components/avo/fields/trix_field/edit_component.rb

Constant Summary

Constants included from Concerns::FindAssociationField

Concerns::FindAssociationField::ASSOCIATIONS

Instance Attribute Summary collapse

Attributes inherited from EditComponent

#compact, #field, #form, #index, #kwargs, #multiple, #stacked, #view

Instance Method Summary collapse

Methods inherited from EditComponent

#classes, #disabled?, #field_wrapper_args, #render?

Methods included from ResourcesHelper

#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table

Methods inherited from BaseComponent

#component_name, #has_with_trial

Methods included from Concerns::FindAssociationField

#find_association_field

Constructor Details

#initialize(**args) ⇒ EditComponent

Returns a new instance of EditComponent.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/components/avo/fields/trix_field/edit_component.rb', line 6

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)

  @input_id = if @resource_name.present?
    "#{@field.type}_#{@resource_name}_#{@field.id}"
  elsif form.present?
    "#{@field.type}_#{form.index}_#{@field.id}"
  end
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'app/components/avo/fields/trix_field/edit_component.rb', line 4

def resource
  @resource
end

Instance Method Details

#dataObject

The controller element should have a unique_selector attribute. It’s used to identify the specific editor for the media library to delegate the attach event to.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/components/avo/fields/trix_field/edit_component.rb', line 22

def data
  values = {
    resource_name: @resource_name,
    resource_id: @resource_id,
    unique_selector: ".#{@input_id}", # mandatory
    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" }

  {
    controller: "trix-field",
    trix_field_target: "controller",
    action: "insert-attachment->trix-field#insertAttachment",
    **values,
  }
end