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
- #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
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
#address ⇒ Object
78 79 80 81 82 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 78 def address return unless has_address super end |
#category ⇒ Object
Finds the Category from the category_id.
Returns a Decidim::Category
56 57 58 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 56 def category @category ||= categories.find_by(id: category_id) end |
#component_automatic_hashtags ⇒ Object
107 108 109 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 107 def @component_automatic_hashtags ||= ordered_hashtag_list(current_component.current_settings.) end |
#component_suggested_hashtags ⇒ Object
111 112 113 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 111 def @component_suggested_hashtags ||= ordered_hashtag_list(current_component.current_settings.) end |
#extra_hashtags ⇒ Object
94 95 96 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 94 def @extra_hashtags ||= ( + ).uniq end |
#geocoded? ⇒ Boolean
90 91 92 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 90 def geocoded? latitude.present? && longitude.present? end |
#geocoding_enabled? ⇒ Boolean
74 75 76 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 74 def geocoding_enabled? Decidim::Map.available?(:geocoding) && current_component.settings.geocoding_enabled? end |
#has_address? ⇒ Boolean
84 85 86 87 88 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 84 def has_address? return unless has_address geocoding_enabled? && address.present? end |
#map_model(model) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 34 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? # Proposals have the "photos" field reserved for the proposal card image # so we don't want to show all photos there. Instead, only show the # first photo. self.photos = [model.photo].compact.select { |p| p.weight.zero? } self.documents = model. - photos end |
#scope ⇒ Object
Finds the Scope from the given scope_id, uses participatory space scope if missing.
Returns a Decidim::Scope
63 64 65 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 63 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
70 71 72 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 70 def scope_id super || scope&.id end |
#suggested_hashtag_checked?(hashtag) ⇒ Boolean
103 104 105 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 103 def suggested_hashtag_checked?(hashtag) .member?(hashtag) end |
#suggested_hashtags ⇒ Object
98 99 100 101 |
# File 'decidim-proposals/app/forms/decidim/proposals/proposal_form.rb', line 98 def = super.map(&:downcase).to_set .select { |hashtag| .member?(hashtag.downcase) } end |