Module: Decidim::Initiatives::InitiativeHelper

Includes:
ResourceVersionsHelper, SanitizeHelper
Included in:
CreateInitiativeController, InitiativeMetadataGCell
Defined in:
app/helpers/decidim/initiatives/initiative_helper.rb

Overview

Helper method related to initiative object and its internal state.

Instance Method Summary collapse

Instance Method Details

#authorized_create_modal_button(type, html_options) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 33

def authorized_create_modal_button(type, html_options, &)
  tag = "button"
  html_options ||= {}

  if current_user
    if action_authorized_to("create", permissions_holder: type).ok?
      html_options["data-dialog-open"] = "not-authorized-modal"
    else
      html_options["data-dialog-open"] = "authorizationModal"
      html_options["data-dialog-remote-url"] = authorization_create_modal_initiative_path(type)
    end
  else
    html_options["data-dialog-open"] = "loginModal"
  end

  html_options["onclick"] = "event.preventDefault();"

  send("#{tag}_to", "/", html_options, &)
end

#authorized_vote_modal_button(initiative, html_options) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 53

def authorized_vote_modal_button(initiative, html_options, &)
  return if current_user && action_authorized_to("vote", resource: initiative, permissions_holder: initiative.type).ok?

  tag = "button"
  html_options ||= {}

  if current_user
    html_options["data-dialog-open"] = "authorizationModal"
    html_options["data-dialog-remote-url"] = authorization_sign_modal_initiative_path(initiative)
  else
    html_options["data-dialog-open"] = "loginModal"
  end

  html_options["onclick"] = "event.preventDefault();"

  send("#{tag}_to", "/", html_options, &)
end

#can_edit_custom_signature_end_date?(initiative) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 71

def can_edit_custom_signature_end_date?(initiative)
  return false unless initiative.custom_signature_end_date_enabled?

  initiative.created? || initiative.validating?
end

#hero_background_path(initiative) ⇒ Object



83
84
85
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 83

def hero_background_path(initiative)
  initiative.attachments.find(&:image?)&.url
end

#humanize_admin_state(state) ⇒ Object

Public: The state of an initiative from an administration perspective in a way that a human can understand.

state - String

Returns a String



29
30
31
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 29

def humanize_admin_state(state)
  I18n.t(state, scope: "decidim.initiatives.admin_states", default: :created)
end

#metadata_badge_css_class(initiative) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 10

def (initiative)
  case initiative
  when "accepted", "published"
    "success"
  when "rejected", "discarded"
    "alert"
  when "validating"
    "warning"
  else
    "muted"
  end
end

#render_committee_tooltipObject



77
78
79
80
81
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 77

def render_committee_tooltip
  with_tooltip t("decidim.initiatives.create_initiative.share_committee_link.invite_to_committee_help"), class: "left" do
    icon "file-copy-line"
  end
end