Class: Decidim::Proposals::ProposalForm

Inherits:
ProposalWizardCreateStepForm show all
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

#categoryObject

Finds the Category from the category_id.

Returns a Decidim::Category



38
39
40
# File 'app/forms/decidim/proposals/proposal_form.rb', line 38

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

#component_automatic_hashtagsObject



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

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

#component_suggested_hashtagsObject



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

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

#extra_hashtagsObject



60
61
62
# File 'app/forms/decidim/proposals/proposal_form.rb', line 60

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

#has_address?Boolean

Returns:

  • (Boolean)


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

def has_address?
  current_component.settings.geocoding_enabled? && has_address
end

#map_model(model) ⇒ Object



29
30
31
32
33
# File 'app/forms/decidim/proposals/proposal_form.rb', line 29

def map_model(model)
  super

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

#scopeObject

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

Returns a Decidim::Scope



45
46
47
# File 'app/forms/decidim/proposals/proposal_form.rb', line 45

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

#scope_idObject

Scope identifier

Returns the scope identifier related to the proposal



52
53
54
# File 'app/forms/decidim/proposals/proposal_form.rb', line 52

def scope_id
  @scope_id || scope&.id
end

#suggested_hashtag_checked?(hashtag) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/forms/decidim/proposals/proposal_form.rb', line 69

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

#suggested_hashtagsObject



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

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