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

Inherits:
BaseMeetingForm 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.

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 included from TranslatableAttributes

#default_locale?

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


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

def category
  return unless current_component

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

#clean_type_of_meetingObject


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

def clean_type_of_meeting
  type_of_meeting.presence
end

#decidim_scope_idObject

Scope identifier

Returns the scope identifier related to the meeting


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

def decidim_scope_id
  super || scope&.id
end

#embeddable_meeting_urlObject


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

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


104
105
106
107
108
109
110
111
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 104

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


113
114
115
116
117
118
119
120
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 113

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

#map_model(model) ⇒ Object


52
53
54
55
56
57
58
59
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 52

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
  self.type_of_meeting = model.type_of_meeting
end

#number_of_servicesObject


65
66
67
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 65

def number_of_services
  services.size
end

#on_different_platform?Boolean

Returns:


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

def on_different_platform?
  registration_type == "on_different_platform"
end

#on_this_platform?Boolean

Returns:


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

def on_this_platform?
  registration_type == "on_this_platform"
end

#registration_type_selectObject


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

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


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

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

#services_to_persistObject


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

def services_to_persist
  services.reject(&:deleted)
end

#type_of_meeting_selectObject


95
96
97
98
99
100
101
102
# File 'decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb', line 95

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