Class: Decidim::Proposals::ProposalForm

Inherits:
Form
  • Object
show all
Includes:
AttachmentAttributes, HasTaxonomyFormAttributes, HasUploadValidations, 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

#component_automatic_hashtagsObject



81
82
83
# File 'app/forms/decidim/proposals/proposal_form.rb', line 81

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

#component_suggested_hashtagsObject



85
86
87
# File 'app/forms/decidim/proposals/proposal_form.rb', line 85

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

#extra_hashtagsObject



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

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

#geocoded?Boolean

Returns:

  • (Boolean)


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

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

#geocoding_enabled?Boolean

Returns:

  • (Boolean)


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

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

#has_address?Boolean

Returns:

  • (Boolean)


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

def has_address?
  geocoding_enabled? && address.present?
end

#map_model(model) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'app/forms/decidim/proposals/proposal_form.rb', line 40

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

  presenter = ProposalPresenter.new(model)
  self.body = presenter.editor_body(all_locales: body.is_a?(Hash))

  self.user_group_id = model.user_groups.first&.id
  self.documents = model.attachments
end

#participatory_space_manifestObject



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

def participatory_space_manifest
  @participatory_space_manifest ||= current_component.participatory_space.manifest.name
end

#suggested_hashtag_checked?(hashtag) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#suggested_hashtagsObject



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

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