Module: Decidim::Proposals::CollaborativeDraftHelper

Included in:
ApplicationHelper
Defined in:
decidim-proposals/app/helpers/decidim/proposals/collaborative_draft_helper.rb

Overview

Custom helpers, scoped to the collaborative_draft resource.

Instance Method Summary collapse

Instance Method Details

#accept_request_button_labelObject



33
34
35
# File 'decidim-proposals/app/helpers/decidim/proposals/collaborative_draft_helper.rb', line 33

def accept_request_button_label
  t("accept_request", scope: "decidim.proposals.collaborative_drafts.requests.collaboration_requests")
end

#collaborative_drafts_filter_sectionsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'decidim-proposals/app/helpers/decidim/proposals/collaborative_draft_helper.rb', line 41

def collaborative_drafts_filter_sections
  @collaborative_drafts_filter_sections ||= begin
    items = [{
      method: :with_any_state,
      collection: filter_collaborative_drafts_state_values,
      label: t("decidim.proposals.collaborative_drafts.filters.state"),
      id: "state"
    }]
    current_component.available_taxonomy_filters.each do |taxonomy_filter|
      items.append(method: "with_any_taxonomies[#{taxonomy_filter.root_taxonomy_id}]",
                   collection: filter_taxonomy_values_for(taxonomy_filter),
                   label: decidim_sanitize_translated(taxonomy_filter.name),
                   id: "taxonomy-#{taxonomy_filter.root_taxonomy_id}")
    end
    if linked_classes_for(Decidim::Proposals::CollaborativeDraft).any?
      items.append(
        method: :related_to,
        collection: linked_classes_filter_values_for(Decidim::Proposals::CollaborativeDraft),
        label: t("decidim.proposals.collaborative_drafts.filters.related_to"),
        id: "related_to",
        type: :radio_buttons
      )
    end
    items.reject { |item| item[:collection].blank? }
  end
end

#collaborative_drafts_state_class(type) ⇒ Object



24
25
26
27
28
29
30
31
# File 'decidim-proposals/app/helpers/decidim/proposals/collaborative_draft_helper.rb', line 24

def collaborative_drafts_state_class(type)
  case type
  when "withdrawn"
    "alert"
  when "open", "published"
    "success"
  end
end

#filter_collaborative_drafts_state_valuesObject



8
9
10
11
12
13
14
15
16
17
18
# File 'decidim-proposals/app/helpers/decidim/proposals/collaborative_draft_helper.rb', line 8

def filter_collaborative_drafts_state_values
  scope = "decidim.proposals.collaborative_drafts.filters"
  Decidim::CheckBoxesTreeHelper::TreeNode.new(
    Decidim::CheckBoxesTreeHelper::TreePoint.new("", t("all", scope:)),
    [
      Decidim::CheckBoxesTreeHelper::TreePoint.new("open", t("open", scope:)),
      Decidim::CheckBoxesTreeHelper::TreePoint.new("withdrawn", t("withdrawn", scope:)),
      Decidim::CheckBoxesTreeHelper::TreePoint.new("published", t("published", scope:))
    ]
  )
end

#humanize_collaborative_draft_state(state) ⇒ Object



20
21
22
# File 'decidim-proposals/app/helpers/decidim/proposals/collaborative_draft_helper.rb', line 20

def humanize_collaborative_draft_state(state)
  I18n.t(state, scope: "decidim.proposals.collaborative_drafts.states", default: :open)
end

#reject_request_button_labelObject



37
38
39
# File 'decidim-proposals/app/helpers/decidim/proposals/collaborative_draft_helper.rb', line 37

def reject_request_button_label
  t("reject_request", scope: "decidim.proposals.collaborative_drafts.requests.collaboration_requests")
end