Class: Crm::UploadWrapperComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/crm/upload_wrapper_component.rb

Overview

ViewComponent: renders the upload wrapper block.

Wraps a single upload in a grid column and renders its
UploadCardComponent.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(upload:, context_object:, context_class: nil, controller_path: nil, disable_delete: false, parent_form_id: nil) ⇒ UploadWrapperComponent

Returns a new instance of UploadWrapperComponent.

Parameters:

  • upload (Upload)

    the upload to render

  • context_object (Object)

    the record the upload belongs to

  • context_class (Class, nil) (defaults to: nil)

    class used to build upload URLs;
    defaults to the class of +context_object+

  • controller_path (String, nil) (defaults to: nil)

    controller path for upload URLs;
    defaults to the tableized class name of +context_object+

  • disable_delete (Boolean) (defaults to: false)

    hide the delete control when +true+

  • parent_form_id (String, nil) (defaults to: nil)

    DOM id of the parent form, when the
    upload is part of one



25
26
27
28
29
30
31
32
33
# File 'app/components/crm/upload_wrapper_component.rb', line 25

def initialize(upload:, context_object:, context_class: nil, controller_path: nil, disable_delete: false, parent_form_id: nil)
  super()
  @upload = upload
  @context_object = context_object
  @context_class = context_class || context_object.class
  @controller_path = controller_path || context_object.class.name.tableize
  @disable_delete = disable_delete
  @parent_form_id = parent_form_id
end

Instance Attribute Details

#context_classUpload, ... (readonly)

Returns:

  • (Upload)

    the upload being rendered

  • (Object)

    the record the upload belongs to

  • (Class)

    class used to build upload URLs

  • (String)

    controller path used to build upload URLs

  • (Boolean)

    whether the delete control is hidden

  • (String, nil)

    DOM id of the parent form, when the upload is part of one



14
15
16
# File 'app/components/crm/upload_wrapper_component.rb', line 14

def context_class
  @context_class
end

#context_objectUpload, ... (readonly)

Returns:

  • (Upload)

    the upload being rendered

  • (Object)

    the record the upload belongs to

  • (Class)

    class used to build upload URLs

  • (String)

    controller path used to build upload URLs

  • (Boolean)

    whether the delete control is hidden

  • (String, nil)

    DOM id of the parent form, when the upload is part of one



14
15
16
# File 'app/components/crm/upload_wrapper_component.rb', line 14

def context_object
  @context_object
end

#controller_pathUpload, ... (readonly)

Returns:

  • (Upload)

    the upload being rendered

  • (Object)

    the record the upload belongs to

  • (Class)

    class used to build upload URLs

  • (String)

    controller path used to build upload URLs

  • (Boolean)

    whether the delete control is hidden

  • (String, nil)

    DOM id of the parent form, when the upload is part of one



14
15
16
# File 'app/components/crm/upload_wrapper_component.rb', line 14

def controller_path
  @controller_path
end

#disable_deleteUpload, ... (readonly)

Returns:

  • (Upload)

    the upload being rendered

  • (Object)

    the record the upload belongs to

  • (Class)

    class used to build upload URLs

  • (String)

    controller path used to build upload URLs

  • (Boolean)

    whether the delete control is hidden

  • (String, nil)

    DOM id of the parent form, when the upload is part of one



14
15
16
# File 'app/components/crm/upload_wrapper_component.rb', line 14

def disable_delete
  @disable_delete
end

#parent_form_idUpload, ... (readonly)

Returns:

  • (Upload)

    the upload being rendered

  • (Object)

    the record the upload belongs to

  • (Class)

    class used to build upload URLs

  • (String)

    controller path used to build upload URLs

  • (Boolean)

    whether the delete control is hidden

  • (String, nil)

    DOM id of the parent form, when the upload is part of one



14
15
16
# File 'app/components/crm/upload_wrapper_component.rb', line 14

def parent_form_id
  @parent_form_id
end

#uploadUpload, ... (readonly)

Returns:

  • (Upload)

    the upload being rendered

  • (Object)

    the record the upload belongs to

  • (Class)

    class used to build upload URLs

  • (String)

    controller path used to build upload URLs

  • (Boolean)

    whether the delete control is hidden

  • (String, nil)

    DOM id of the parent form, when the upload is part of one



14
15
16
# File 'app/components/crm/upload_wrapper_component.rb', line 14

def upload
  @upload
end