Class: Decidim::Proposals::ProposalForm

Inherits:
ProposalWizardCreateStepForm show all
Includes:
AttachmentAttributes, TranslatableAttributes
Defined in:
app/forms/decidim/proposals/proposal_form.rb

Overview

A form object to be used when public users want to create a proposal.

Direct Known Subclasses

CollaborativeDraftForm

Instance Method Summary collapse

Instance Method Details

#addressObject



71
72
73
74
75
# File 'app/forms/decidim/proposals/proposal_form.rb', line 71

def address
  return unless has_address

  super
end

#categoryObject

Finds the Category from the category_id.

Returns a Decidim::Category



49
50
51
# File 'app/forms/decidim/proposals/proposal_form.rb', line 49

def category
  @category ||= categories.find_by(id: category_id)
end

#component_automatic_hashtagsObject



100
101
102
# File 'app/forms/decidim/proposals/proposal_form.rb', line 100

def component_automatic_hashtags
  @component_automatic_hashtags ||= ordered_hashtag_list(current_component.current_settings.automatic_hashtags)
end

#component_suggested_hashtagsObject



104
105
106
# File 'app/forms/decidim/proposals/proposal_form.rb', line 104

def component_suggested_hashtags
  @component_suggested_hashtags ||= ordered_hashtag_list(current_component.current_settings.suggested_hashtags)
end

#extra_hashtagsObject



87
88
89
# File 'app/forms/decidim/proposals/proposal_form.rb', line 87

def extra_hashtags
  @extra_hashtags ||= (component_automatic_hashtags + suggested_hashtags).uniq
end

#geocoded?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/forms/decidim/proposals/proposal_form.rb', line 83

def geocoded?
  latitude.present? && longitude.present?
end

#geocoding_enabled?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/forms/decidim/proposals/proposal_form.rb', line 67

def geocoding_enabled?
  Decidim::Map.available?(:geocoding) && current_component.settings.geocoding_enabled?
end

#has_address?Boolean

Returns:

  • (Boolean)


77
78
79
80
81
# File 'app/forms/decidim/proposals/proposal_form.rb', line 77

def has_address?
  return unless has_address

  geocoding_enabled? && address.present?
end

#map_model(model) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/forms/decidim/proposals/proposal_form.rb', line 33

def map_model(model)
  super

  body = translated_attribute(model.body)
  @suggested_hashtags = Decidim::ContentRenderers::HashtagRenderer.new(body).extra_hashtags.map(&:name).map(&:downcase)

  # The scope attribute is with different key (decidim_scope_id), so it
  # has to be manually mapped.
  self.scope_id = model.scope.id if model.scope

  self.has_address = true if model.address.present?
end

#scopeObject

Finds the Scope from the given scope_id, uses participatory space scope if missing.

Returns a Decidim::Scope



56
57
58
# File 'app/forms/decidim/proposals/proposal_form.rb', line 56

def scope
  @scope ||= @scope_id ? current_component.scopes.find_by(id: @scope_id) : current_component.scope
end

#scope_idObject

Scope identifier

Returns the scope identifier related to the proposal



63
64
65
# File 'app/forms/decidim/proposals/proposal_form.rb', line 63

def scope_id
  @scope_id || scope&.id
end

#suggested_hashtag_checked?(hashtag) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
# File 'app/forms/decidim/proposals/proposal_form.rb', line 96

def suggested_hashtag_checked?(hashtag)
  suggested_hashtags.member?(hashtag)
end

#suggested_hashtagsObject



91
92
93
94
# File 'app/forms/decidim/proposals/proposal_form.rb', line 91

def suggested_hashtags
  downcased_suggested_hashtags = Array(@suggested_hashtags&.map(&:downcase)).to_set
  component_suggested_hashtags.select { |hashtag| downcased_suggested_hashtags.member?(hashtag.downcase) }
end