Class: Decidim::Meetings::MeetingForm

Inherits:
BaseMeetingForm show all
Defined in:
decidim-meetings/app/forms/decidim/meetings/meeting_form.rb

Overview

This class holds a Form to create/update meetings for Participants and UserGroups.

Constant Summary

Constants included from AttributeObject::TypeMap

AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal

Instance Attribute Summary

Attributes inherited from AttributeObject::Form

#context

Instance Method Summary collapse

Methods inherited from BaseMeetingForm

#geocoded?, #geocoding_enabled?, #has_address?, #hybrid_meeting?, #in_person_meeting?, #needs_address?, #online_meeting?

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

#categoryObject


73
74
75
76
77
# File 'decidim-meetings/app/forms/decidim/meetings/meeting_form.rb', line 73

def category
  return unless current_component

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

#clean_type_of_meetingObject


79
80
81
# File 'decidim-meetings/app/forms/decidim/meetings/meeting_form.rb', line 79

def clean_type_of_meeting
  type_of_meeting.presence
end

#decidim_scope_idObject

Scope identifier

Returns the scope identifier related to the meeting


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

def decidim_scope_id
  super || scope&.id
end

#embeddable_meeting_urlObject


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

def embeddable_meeting_url
  if online_meeting_url.present? && %w(embed_in_meeting_page open_in_live_event_page).include?(iframe_embed_type)
    embedder_service = Decidim::Meetings::MeetingIframeEmbedder.new(online_meeting_url)
    errors.add(:iframe_embed_type, :not_embeddable) unless embedder_service.embeddable?
  end
end

#iframe_access_level_selectObject


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

def iframe_access_level_select
  Decidim::Meetings::Meeting.iframe_access_levels.map do |level, _value|
    [
      I18n.t("iframe_access_level.#{level}", scope: "decidim.meetings"),
      level
    ]
  end
end

#iframe_embed_type_selectObject


101
102
103
104
105
106
107
108
# File 'decidim-meetings/app/forms/decidim/meetings/meeting_form.rb', line 101

def iframe_embed_type_select
  Decidim::Meetings::Meeting.participants_iframe_embed_types.map do |type, _value|
    [
      I18n.t("iframe_embed_type.#{type}", scope: "decidim.meetings"),
      type
    ]
  end
end

#map_model(model) ⇒ Object


46
47
48
49
50
51
52
53
54
55
# File 'decidim-meetings/app/forms/decidim/meetings/meeting_form.rb', line 46

def map_model(model)
  self.decidim_category_id = model.categorization.decidim_category_id if model.categorization
  presenter = MeetingEditionPresenter.new(model)
  self.title = presenter.title(all_locales: false)
  self.description = presenter.description(all_locales: false)
  self.location = presenter.location(all_locales: false)
  self.location_hints = presenter.location_hints(all_locales: false)
  self.registration_terms = presenter.registration_terms(all_locales: false)
  self.type_of_meeting = model.type_of_meeting
end

#on_different_platform?Boolean

Returns:


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

def on_different_platform?
  registration_type == "on_different_platform"
end

#on_this_platform?Boolean

Returns:


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

def on_this_platform?
  registration_type == "on_this_platform"
end

#registration_type_selectObject


118
119
120
121
122
123
124
125
# File 'decidim-meetings/app/forms/decidim/meetings/meeting_form.rb', line 118

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

#registrations_enabledObject


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

def registrations_enabled
  on_this_platform?
end

#scopeObject

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

Returns a Decidim::Scope


62
63
64
# File 'decidim-meetings/app/forms/decidim/meetings/meeting_form.rb', line 62

def scope
  @scope ||= @attributes["decidim_scope_id"].value ? current_component.scopes.find_by(id: @attributes["decidim_scope_id"].value) : current_component.scope
end

#type_of_meeting_selectObject


83
84
85
86
87
88
89
90
# File 'decidim-meetings/app/forms/decidim/meetings/meeting_form.rb', line 83

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