Class: Decidim::Meetings::Admin::MeetingForm

Inherits:
Form
  • Object
show all
Includes:
TranslatableAttributes
Defined in:
decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb

Overview

This class holds a Form to create/update translatable meetings from Decidim's admin panel.

Instance Method Summary collapse

Methods included from TranslatableAttributes

#default_locale?

Instance Method Details

#categoryObject


92
93
94
95
96
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 92

def category
  return unless current_component

  @category ||= categories.find_by(id: decidim_category_id)
end

#clean_type_of_meetingObject


126
127
128
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 126

def clean_type_of_meeting
  type_of_meeting.presence
end

#decidim_scope_idObject

Scope identifier

Returns the scope identifier related to the meeting


88
89
90
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 88

def decidim_scope_id
  @decidim_scope_id || scope&.id
end

#geocoded?Boolean

Returns:

  • (Boolean)

110
111
112
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 110

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

#geocoding_enabled?Boolean

Returns:

  • (Boolean)

98
99
100
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 98

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

#has_address?Boolean

Returns:

  • (Boolean)

102
103
104
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 102

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

#hybrid_meeting?Boolean

Returns:

  • (Boolean)

122
123
124
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 122

def hybrid_meeting?
  type_of_meeting == "hybrid"
end

#in_person_meeting?Boolean

Returns:

  • (Boolean)

118
119
120
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 118

def in_person_meeting?
  type_of_meeting == "in_person"
end

#map_model(model) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
66
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 55

def map_model(model)
  self.services = model.services.map do |service|
    MeetingServiceForm.from_model(service)
  end

  self.decidim_category_id = model.categorization.decidim_category_id if model.categorization
  presenter = MeetingPresenter.new(model)

  self.title = presenter.title(all_locales: title.is_a?(Hash))
  self.description = presenter.description(all_locales: description.is_a?(Hash))
  self.type_of_meeting = model.type_of_meeting
end

#needs_address?Boolean

Returns:

  • (Boolean)

106
107
108
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 106

def needs_address?
  in_person_meeting? || hybrid_meeting?
end

#number_of_servicesObject


72
73
74
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 72

def number_of_services
  services.size
end

#on_different_platform?Boolean

Returns:

  • (Boolean)

143
144
145
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 143

def on_different_platform?
  registration_type == "on_different_platform"
end

#on_this_platform?Boolean

Returns:

  • (Boolean)

139
140
141
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 139

def on_this_platform?
  registration_type == "on_this_platform"
end

#online_meeting?Boolean

Returns:

  • (Boolean)

114
115
116
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 114

def online_meeting?
  type_of_meeting == "online"
end

#registration_type_selectObject


147
148
149
150
151
152
153
154
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 147

def registration_type_select
  Decidim::Meetings::Meeting::REGISTRATION_TYPE.map do |type|
    [
      I18n.t("registration_type.#{type}", scope: "decidim.meetings"),
      type
    ]
  end
end

#scopeObject

Finds the Scope from the given decidim_scope_id, uses component scope if missing.

Returns a Decidim::Scope


81
82
83
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 81

def scope
  @scope ||= @decidim_scope_id ? current_component.scopes.find_by(id: @decidim_scope_id) : current_component.scope
end

#services_to_persistObject


68
69
70
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 68

def services_to_persist
  services.reject(&:deleted)
end

#type_of_meeting_selectObject


130
131
132
133
134
135
136
137
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 130

def type_of_meeting_select
  Decidim::Meetings::Meeting::TYPE_OF_MEETING.map do |type|
    [
      I18n.t("type_of_meeting.#{type}", scope: "decidim.meetings"),
      type
    ]
  end
end