Class: Decidim::Proposals::Admin::ProposalBaseForm

Inherits:
Form
  • Object
show all
Includes:
ApplicationHelper, AttachmentAttributes, HasTaxonomyFormAttributes, TranslatableAttributes
Defined in:
app/forms/decidim/proposals/admin/proposal_base_form.rb

Overview

A form object to be used when admin users want to create a proposal.

Direct Known Subclasses

ParticipatoryTextProposalForm, ProposalForm

Instance Method Summary collapse

Instance Method Details

#authorObject



65
66
67
68
69
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 65

def author
  return current_organization unless created_in_meeting?

  meeting_as_author
end

#component_automatic_hashtagsObject



84
85
86
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 84

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

#component_suggested_hashtagsObject



88
89
90
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 88

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

#extra_hashtagsObject



71
72
73
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 71

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

#geocoded?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 50

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

#geocoding_enabled?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 42

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

#has_address?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 46

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

#map_model(model) ⇒ Object



31
32
33
34
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 31

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

#meeting_as_authorObject

Return the meeting as author



61
62
63
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 61

def meeting_as_author
  @meeting_as_author ||= meetings.find_by(id: meeting_id)
end

#meetingsObject

Finds the Meetings of the current participatory space



55
56
57
58
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 55

def meetings
  @meetings ||= Decidim.find_resource_manifest(:meetings).try(:resource_scope, current_component)
                  &.published&.order(title: :asc)
end

#participatory_space_manifestObject



38
39
40
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 38

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

#suggested_hashtag_checked?(hashtag) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 80

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

#suggested_hashtagsObject



75
76
77
78
# File 'app/forms/decidim/proposals/admin/proposal_base_form.rb', line 75

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