Module: Decidim::AttachmentsHelper

Overview

A Helper to render and link to resources.

Constant Summary

Constants included from IconHelper

IconHelper::DEFAULT_RESOURCE_TYPE_ICONS

Instance Method Summary collapse

Methods included from IconHelper

#component_icon, #manifest_icon, #resource_icon, #resource_type_icon, #resource_type_icon_key, #text_with_resource_icon

Methods included from LayoutHelper

#_icon_classes, #apple_favicon, #application_path, #current_user_unread_data, #extended_navigation_bar, #external_icon, #favicon, #icon, #legacy_favicon, #organization_colors, #role

Methods included from TooltipHelper

#with_tooltip

Methods included from ModalHelper

#decidim_modal

Instance Method Details

#attachment_title(attachment) ⇒ Object

Renders the attachment’s title. Checks if the attachment’s title is translated or not and use the correct render method.

attachment - An Attachment object

Returns String.



46
47
48
# File 'decidim-core/app/helpers/decidim/attachments_helper.rb', line 46

def attachment_title(attachment)
  attachment.title.is_a?(Hash) ? translated_attribute(attachment.title) : attachment.title
end

#attachments_for(attached_to) ⇒ Object

Renders a the attachments of a model that includes the HasAttachments concern.

attached_to - The model to render the attachments from.



12
13
14
15
16
# File 'decidim-core/app/helpers/decidim/attachments_helper.rb', line 12

def attachments_for(attached_to)
  return unless attached_to.is_a?(Decidim::HasAttachments)

  cell "decidim/tab_panels", attachments_tab_panel_items(attached_to)
end

#attachments_tab_panel_items(attached_to) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'decidim-core/app/helpers/decidim/attachments_helper.rb', line 18

def attachments_tab_panel_items(attached_to)
  [
    {
      enabled: attached_to.photos.any?,
      id: "images",
      text: t("decidim.application.photos.photos"),
      icon: resource_type_icon_key("images"),
      method: :cell,
      args: ["decidim/images_panel", attached_to]
    },
    {
      enabled: attached_to.documents.any?,
      id: "documents",
      text: t("decidim.application.documents.documents"),
      icon: resource_type_icon_key("documents"),
      method: :cell,
      args: ["decidim/documents_panel", attached_to]
    }
  ]
end