Module: Decidim::Proposals::CollaborativeDraftHelper

Included in:
ApplicationHelper
Defined in:
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 '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 '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_scope: "decidim.proposals.collaborative_drafts.filters",
      id: "state"
    }]
    if current_component.has_subscopes?
      items.append(method: :with_any_scope, collection: filter_scopes_values, label_scope: "decidim.proposals.collaborative_drafts.filters", id: "scope")
    end
    if current_component.categories.any?
      items.append(method: :with_any_category, collection: filter_categories_values, label_scope: "decidim.proposals.collaborative_drafts.filters", id: "category")
    end
    if linked_classes_for(Decidim::Proposals::CollaborativeDraft).any?
      items.append(
        method: :related_to,
        collection: linked_classes_filter_values_for(Decidim::Proposals::CollaborativeDraft),
        label_scope: "decidim.proposals.collaborative_drafts.filters",
        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 '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 '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 '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 '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