Module: Decidim::EnhancedTextwork::ParagraphsHelper

Defined in:
app/helpers/decidim/enhanced_textwork/paragraphs_helper.rb

Overview

Simple helpers to handle markup variations for paragraphs

Instance Method Summary collapse

Instance Method Details

#filter_paragraphs_state_valuesObject



38
39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/decidim/enhanced_textwork/paragraphs_helper.rb', line 38

def filter_paragraphs_state_values
  Decidim::CheckBoxesTreeHelper::TreeNode.new(
    Decidim::CheckBoxesTreeHelper::TreePoint.new("", t("decidim.enhanced_textwork.application_helper.filter_state_values.all")),
    [
      Decidim::CheckBoxesTreeHelper::TreePoint.new("accepted", t("decidim.enhanced_textwork.application_helper.filter_state_values.accepted")),
      Decidim::CheckBoxesTreeHelper::TreePoint.new("evaluating", t("decidim.enhanced_textwork.application_helper.filter_state_values.evaluating")),
      Decidim::CheckBoxesTreeHelper::TreePoint.new("state_not_published", t("decidim.enhanced_textwork.application_helper.filter_state_values.not_answered")),
      Decidim::CheckBoxesTreeHelper::TreePoint.new("rejected", t("decidim.enhanced_textwork.application_helper.filter_state_values.rejected"))
    ]
  )
end

#paragraph_has_costs?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
# File 'app/helpers/decidim/enhanced_textwork/paragraphs_helper.rb', line 50

def paragraph_has_costs?
  @paragraph.cost.present? &&
    translated_attribute(@paragraph.cost_report).present? &&
    translated_attribute(@paragraph.execution_period).present?
end

#paragraph_reason_callout_announcementObject



7
8
9
10
11
12
# File 'app/helpers/decidim/enhanced_textwork/paragraphs_helper.rb', line 7

def paragraph_reason_callout_announcement
  {
    title: paragraph_reason_callout_title,
    body: decidim_sanitize(translated_attribute(@paragraph.answer))
  }
end

#paragraph_reason_callout_classObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/decidim/enhanced_textwork/paragraphs_helper.rb', line 14

def paragraph_reason_callout_class
  case @paragraph.state
  when "accepted"
    "success"
  when "evaluating"
    "warning"
  when "rejected"
    "alert"
  else
    ""
  end
end

#paragraph_reason_callout_titleObject



27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/decidim/enhanced_textwork/paragraphs_helper.rb', line 27

def paragraph_reason_callout_title
  i18n_key = case @paragraph.state
             when "evaluating"
               "paragraph_in_evaluation_reason"
             else
               "paragraph_#{@paragraph.state}_reason"
             end

  t(i18n_key, scope: "decidim.enhanced_textwork.paragraphs.show")
end

#resource_version(resource, options = {}) ⇒ Object



56
57
58
59
60
# File 'app/helpers/decidim/enhanced_textwork/paragraphs_helper.rb', line 56

def resource_version(resource, options = {})
  return unless resource.respond_to?(:amendable?) && resource.amendable?

  super
end