Module: Decidim::Plans::AttachmentsHelper

Defined in:
app/helpers/decidim/plans/attachments_helper.rb

Instance Method Summary collapse

Instance Method Details

#blank_attachmentObject



10
11
12
# File 'app/helpers/decidim/plans/attachments_helper.rb', line 10

def blank_attachment
  @blank_attachment ||= Plans::AttachmentForm.new
end

#required_tagObject



48
49
50
51
52
53
54
55
56
# File 'app/helpers/decidim/plans/attachments_helper.rb', line 48

def required_tag
  (
    :abbr,
    "*",
    title: I18n.t("required", scope: "forms"),
    data: { tooltip: true, disable_hover: false }, 'aria-haspopup': true,
    class: "label-required"
  ).html_safe
end

#tabs_id_for_attachment(attachment) ⇒ Object



6
7
8
# File 'app/helpers/decidim/plans/attachments_helper.rb', line 6

def tabs_id_for_attachment(attachment)
  "attachment_#{attachment.to_param}"
end

#upload_field(form, attribute) ⇒ Object

A modified version of the Decidim’s own form builder ‘upload` method which is buggy for multiple file fields.

See: Decidim::FormBuilder#upload

form - The form object for which to create the field. attribute - The String/Symbol name of the attribute to build the

field.


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/decidim/plans/attachments_helper.rb', line 23

def upload_field(form, attribute)
  file = form.object.send attribute
  required = file.nil?

  label_content = form.label_for(attribute)
  label_content += required_tag if required
  template = ""
  template += form.label(attribute, label_content)
  template += form.file_field attribute, label: false

  if form.send(:file_is_image?, file)
    template += if file.present?
                   :label, I18n.t("current_image", scope: "decidim.forms")
                else
                   :label, I18n.t("default_image", scope: "decidim.forms")
                end
    template += link_to image_tag(file.url), file.url, target: "_blank"
  elsif form.send(:file_is_present?, file)
    template += label_tag I18n.t("current_file", scope: "decidim.forms")
    template += link_to file.file.filename, file.url, target: "_blank"
  end

  template.html_safe
end