Class: Crm::AttachmentsComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Crm::AttachmentsComponent
- Defined in:
- app/components/crm/attachments_component.rb
Overview
ViewComponent: renders the attachments block — a card (or unwrapped action
row) with upload/publication buttons and the Turbo Frame listing a context
object's uploads, driven by the crm-attachments Stimulus controller.
Instance Attribute Summary collapse
-
#attach_url ⇒ String
readonly
Endpoint URL the Stimulus controller POSTs uploads to.
-
#category_options_for_select ⇒ Array<Array(String, String)>?
readonly
Label/value pairs for the category dropdown.
-
#context_object ⇒ ActiveRecord::Base
readonly
Record whose uploads are listed and attached to.
-
#disable_delete ⇒ Boolean
readonly
Whether delete controls are disabled on each upload.
-
#multiple_files_allowed ⇒ Boolean
readonly
Whether the file input accepts multiple files.
-
#parent_form_id ⇒ String?
readonly
DOM id of a parent form uploads should be associated with.
-
#skip_publications ⇒ Boolean
readonly
Whether to hide the "Publication" picker button.
-
#small_buttons ⇒ Object
readonly
Returns the value of attribute small_buttons.
-
#template_options_for_select ⇒ Array<Array(String, String)>?
readonly
Label/value pairs for the template dropdown.
-
#wrapped ⇒ Boolean
readonly
Whether to render the full card chrome (header + body).
Instance Method Summary collapse
-
#action_button_class(variant = 'danger') ⇒ String
Header actions default to btn-sm; the activity form opts out so these and its result submit buttons share one default-sized row.
-
#attachments_container_id ⇒ String
DOM id of the container div holding the upload cards.
-
#context_class_name ⇒ String
Class name of the context object, or the explicit override.
-
#context_object_id ⇒ Integer
Id of the context object (0 when unset, e.g. unpersisted records).
-
#controller_path ⇒ String
Controller path for publication links, derived from the context object's class when not given explicitly.
-
#frame_id ⇒ String
DOM id of the Turbo Frame wrapping the uploads list.
-
#initialize(context_object:, attach_url:, wrapped: true, skip_publications: false, multiple_files_allowed: true, template_options_for_select: nil, category_options_for_select: nil, disable_delete: false, context_class_name: nil, controller_path: nil, parent_form_id: nil, small_buttons: true) ⇒ AttachmentsComponent
constructor
A new instance of AttachmentsComponent.
-
#modal_id ⇒ String
DOM id of the publication-picker modal.
Constructor Details
#initialize(context_object:, attach_url:, wrapped: true, skip_publications: false, multiple_files_allowed: true, template_options_for_select: nil, category_options_for_select: nil, disable_delete: false, context_class_name: nil, controller_path: nil, parent_form_id: nil, small_buttons: true) ⇒ AttachmentsComponent
Returns a new instance of AttachmentsComponent.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/components/crm/attachments_component.rb', line 43 def initialize(context_object:, attach_url:, wrapped: true, skip_publications: false, multiple_files_allowed: true, template_options_for_select: nil, category_options_for_select: nil, disable_delete: false, context_class_name: nil, controller_path: nil, parent_form_id: nil, small_buttons: true) super() @context_object = context_object @attach_url = attach_url @wrapped = wrapped @skip_publications = skip_publications @multiple_files_allowed = multiple_files_allowed @template_options_for_select = @category_options_for_select = @disable_delete = disable_delete @explicit_context_class_name = context_class_name || context_object.class.name @controller_path = controller_path @parent_form_id = parent_form_id @small_buttons = end |
Instance Attribute Details
#attach_url ⇒ String (readonly)
Returns endpoint URL the Stimulus controller POSTs uploads to.
27 28 29 |
# File 'app/components/crm/attachments_component.rb', line 27 attr_reader :context_object, :wrapped, :skip_publications, :multiple_files_allowed, :template_options_for_select, :category_options_for_select, :disable_delete, :attach_url, :parent_form_id, :small_buttons |
#category_options_for_select ⇒ Array<Array(String, String)>? (readonly)
Returns label/value pairs for the category dropdown.
27 28 29 |
# File 'app/components/crm/attachments_component.rb', line 27 attr_reader :context_object, :wrapped, :skip_publications, :multiple_files_allowed, :template_options_for_select, :category_options_for_select, :disable_delete, :attach_url, :parent_form_id, :small_buttons |
#context_object ⇒ ActiveRecord::Base (readonly)
Returns record whose uploads are listed and attached to.
27 28 29 |
# File 'app/components/crm/attachments_component.rb', line 27 def context_object @context_object end |
#disable_delete ⇒ Boolean (readonly)
Returns whether delete controls are disabled on each upload.
27 28 29 |
# File 'app/components/crm/attachments_component.rb', line 27 attr_reader :context_object, :wrapped, :skip_publications, :multiple_files_allowed, :template_options_for_select, :category_options_for_select, :disable_delete, :attach_url, :parent_form_id, :small_buttons |
#multiple_files_allowed ⇒ Boolean (readonly)
Returns whether the file input accepts multiple files.
27 28 29 |
# File 'app/components/crm/attachments_component.rb', line 27 attr_reader :context_object, :wrapped, :skip_publications, :multiple_files_allowed, :template_options_for_select, :category_options_for_select, :disable_delete, :attach_url, :parent_form_id, :small_buttons |
#parent_form_id ⇒ String? (readonly)
Returns DOM id of a parent form uploads should be associated with.
27 28 29 |
# File 'app/components/crm/attachments_component.rb', line 27 attr_reader :context_object, :wrapped, :skip_publications, :multiple_files_allowed, :template_options_for_select, :category_options_for_select, :disable_delete, :attach_url, :parent_form_id, :small_buttons |
#skip_publications ⇒ Boolean (readonly)
Returns whether to hide the "Publication" picker button.
27 28 29 |
# File 'app/components/crm/attachments_component.rb', line 27 attr_reader :context_object, :wrapped, :skip_publications, :multiple_files_allowed, :template_options_for_select, :category_options_for_select, :disable_delete, :attach_url, :parent_form_id, :small_buttons |
#small_buttons ⇒ Object (readonly)
Returns the value of attribute small_buttons.
27 28 29 |
# File 'app/components/crm/attachments_component.rb', line 27 attr_reader :context_object, :wrapped, :skip_publications, :multiple_files_allowed, :template_options_for_select, :category_options_for_select, :disable_delete, :attach_url, :parent_form_id, :small_buttons |
#template_options_for_select ⇒ Array<Array(String, String)>? (readonly)
Returns label/value pairs for the template dropdown.
27 28 29 |
# File 'app/components/crm/attachments_component.rb', line 27 attr_reader :context_object, :wrapped, :skip_publications, :multiple_files_allowed, :template_options_for_select, :category_options_for_select, :disable_delete, :attach_url, :parent_form_id, :small_buttons |
#wrapped ⇒ Boolean (readonly)
Returns whether to render the full card chrome (header + body).
27 28 29 |
# File 'app/components/crm/attachments_component.rb', line 27 attr_reader :context_object, :wrapped, :skip_publications, :multiple_files_allowed, :template_options_for_select, :category_options_for_select, :disable_delete, :attach_url, :parent_form_id, :small_buttons |
Instance Method Details
#action_button_class(variant = 'danger') ⇒ String
Header actions default to btn-sm; the activity form opts out so these and
its result submit buttons share one default-sized row.
74 75 76 |
# File 'app/components/crm/attachments_component.rb', line 74 def (variant = 'danger') ['btn', ('btn-sm' if ), "btn-outline-#{variant}"].compact.join(' ') end |
#attachments_container_id ⇒ String
Returns DOM id of the container div holding the upload cards.
105 106 107 |
# File 'app/components/crm/attachments_component.rb', line 105 def "attachments-#{context_object_id}" end |
#context_class_name ⇒ String
Returns class name of the context object, or the explicit override.
84 85 86 |
# File 'app/components/crm/attachments_component.rb', line 84 def context_class_name @explicit_context_class_name end |
#context_object_id ⇒ Integer
Returns id of the context object (0 when unset, e.g. unpersisted records).
79 80 81 |
# File 'app/components/crm/attachments_component.rb', line 79 def context_object_id context_object.try(:id).to_i end |
#controller_path ⇒ String
Returns controller path for publication links, derived from the
context object's class when not given explicitly.
90 91 92 |
# File 'app/components/crm/attachments_component.rb', line 90 def controller_path @controller_path || context_object.class.name.tableize end |
#frame_id ⇒ String
Returns DOM id of the Turbo Frame wrapping the uploads list.
100 101 102 |
# File 'app/components/crm/attachments_component.rb', line 100 def frame_id "attachments-frame-#{context_object_id}" end |
#modal_id ⇒ String
Returns DOM id of the publication-picker modal.
95 96 97 |
# File 'app/components/crm/attachments_component.rb', line 95 def modal_id "publication-picker-modal-#{context_object_id}" end |