Class: Decidim::Proposals::ProposalForm
- Inherits:
-
ProposalWizardCreateStepForm
- Object
- Form
- ProposalWizardCreateStepForm
- Decidim::Proposals::ProposalForm
- 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
Instance Method Summary collapse
- #address ⇒ Object
-
#category ⇒ Object
Finds the Category from the category_id.
- #component_automatic_hashtags ⇒ Object
- #component_suggested_hashtags ⇒ Object
- #extra_hashtags ⇒ Object
- #geocoded? ⇒ Boolean
- #geocoding_enabled? ⇒ Boolean
- #has_address? ⇒ Boolean
- #map_model(model) ⇒ Object
-
#scope ⇒ Object
Finds the Scope from the given scope_id, uses participatory space scope if missing.
-
#scope_id ⇒ Object
Scope identifier.
- #suggested_hashtag_checked?(hashtag) ⇒ Boolean
- #suggested_hashtags ⇒ Object
Instance Method Details
#address ⇒ Object
71 72 73 74 75 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 71 def address return unless has_address super end |
#category ⇒ Object
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_hashtags ⇒ Object
100 101 102 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 100 def @component_automatic_hashtags ||= ordered_hashtag_list(current_component.current_settings.) end |
#component_suggested_hashtags ⇒ Object
104 105 106 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 104 def @component_suggested_hashtags ||= ordered_hashtag_list(current_component.current_settings.) end |
#extra_hashtags ⇒ Object
87 88 89 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 87 def @extra_hashtags ||= ( + ).uniq end |
#geocoded? ⇒ Boolean
83 84 85 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 83 def geocoded? latitude.present? && longitude.present? end |
#geocoding_enabled? ⇒ 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
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)..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 |
#scope ⇒ Object
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_id ⇒ Object
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
96 97 98 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 96 def suggested_hashtag_checked?(hashtag) .member?(hashtag) end |
#suggested_hashtags ⇒ Object
91 92 93 94 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 91 def = Array(@suggested_hashtags&.map(&:downcase)).to_set .select { |hashtag| .member?(hashtag.downcase) } end |