Class: Decidim::Proposals::ProposalForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Proposals::ProposalForm
- Includes:
- AttachmentAttributes, 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
Instance Method Summary collapse
-
#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
#category ⇒ Object
Finds the Category from the category_id.
Returns a Decidim::Category
65 66 67 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 65 def category @category ||= categories.find_by(id: category_id) end |
#component_automatic_hashtags ⇒ Object
108 109 110 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 108 def @component_automatic_hashtags ||= ordered_hashtag_list(current_component.current_settings.) end |
#component_suggested_hashtags ⇒ Object
112 113 114 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 112 def @component_suggested_hashtags ||= ordered_hashtag_list(current_component.current_settings.) end |
#extra_hashtags ⇒ Object
95 96 97 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 95 def @extra_hashtags ||= ( + ).uniq end |
#geocoded? ⇒ Boolean
91 92 93 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 91 def geocoded? latitude.present? && longitude.present? end |
#geocoding_enabled? ⇒ Boolean
83 84 85 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 83 def geocoding_enabled? Decidim::Map.available?(:geocoding) && current_component.settings.geocoding_enabled? end |
#has_address? ⇒ Boolean
87 88 89 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 87 def has_address? geocoding_enabled? && address.present? end |
#map_model(model) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 44 def map_model(model) self.title = translated_attribute(model.title) self.body = translated_attribute(model.body) @suggested_hashtags = Decidim::ContentRenderers::HashtagRenderer.new(body)..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.category_id = model.categorization.decidim_category_id if model.categorization # 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.documents = model. end |
#scope ⇒ Object
Finds the Scope from the given scope_id, uses participatory space scope if missing.
Returns a Decidim::Scope
72 73 74 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 72 def scope @scope ||= @attributes["scope_id"].value ? current_component.scopes.find_by(id: @attributes["scope_id"].value) : current_component.scope end |
#scope_id ⇒ Object
Scope identifier
Returns the scope identifier related to the proposal
79 80 81 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 79 def scope_id super || scope&.id end |
#suggested_hashtag_checked?(hashtag) ⇒ Boolean
104 105 106 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 104 def suggested_hashtag_checked?(hashtag) .member?(hashtag) end |
#suggested_hashtags ⇒ Object
99 100 101 102 |
# File 'app/forms/decidim/proposals/proposal_form.rb', line 99 def = super.to_set(&:downcase) .select { |hashtag| .member?(hashtag.downcase) } end |