Class: Decidim::Proposals::ProposalForm
- Inherits:
-
ProposalWizardCreateStepForm
- Object
- AttributeObject::Form
- Form
- ProposalWizardCreateStepForm
- Decidim::Proposals::ProposalForm
- Defined in:
- decidim-proposals/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
Constant Summary
Constants included from AttributeObject::TypeMap
AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal
Instance Attribute Summary
Attributes inherited from AttributeObject::Form
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
Methods included from HasUploadValidations
#attached_uploader, #maximum_avatar_size, #maximum_upload_size
Methods included from TranslatableAttributes
Methods inherited from AttributeObject::Form
ensure_hash, from_model, from_params, hash_from, infer_model_name, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #to_param, #valid?, #with_context
Methods included from AttributeObject::Model
#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h
Instance Method Details
#category ⇒ Object
Finds the Category from the category_id.
Returns a Decidim::Category
50 51 52 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 50 def category @category ||= categories.find_by(id: category_id) end |
#component_automatic_hashtags ⇒ Object
93 94 95 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 93 def @component_automatic_hashtags ||= ordered_hashtag_list(current_component.current_settings.) end |
#component_suggested_hashtags ⇒ Object
97 98 99 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 97 def @component_suggested_hashtags ||= ordered_hashtag_list(current_component.current_settings.) end |
#extra_hashtags ⇒ Object
80 81 82 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 80 def @extra_hashtags ||= ( + ).uniq end |
#geocoded? ⇒ Boolean
76 77 78 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 76 def geocoded? latitude.present? && longitude.present? end |
#geocoding_enabled? ⇒ Boolean
68 69 70 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 68 def geocoding_enabled? Decidim::Map.available?(:geocoding) && current_component.settings.geocoding_enabled? end |
#has_address? ⇒ Boolean
72 73 74 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 72 def has_address? geocoding_enabled? && address.present? end |
#map_model(model) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 31 def map_model(model) super 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)) # 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
57 58 59 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 57 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
64 65 66 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 64 def scope_id super || scope&.id end |
#suggested_hashtag_checked?(hashtag) ⇒ Boolean
89 90 91 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 89 def suggested_hashtag_checked?(hashtag) .member?(hashtag) end |
#suggested_hashtags ⇒ Object
84 85 86 87 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 84 def = super.to_set(&:downcase) .select { |hashtag| .member?(hashtag.downcase) } end |