Class: Decidim::TermCustomizer::Admin::TranslationSetSubjectForm

Inherits:
Form
  • Object
show all
Defined in:
app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb

Instance Method Summary collapse

Instance Method Details

#componentObject



40
41
42
43
44
45
46
# File 'app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb', line 40

def component
  return unless component_form
  return unless subject
  return unless subject.respond_to?(:components)

  subject.components.find_by(id: component_form.component_id)
end

#component_formObject



54
55
56
57
58
# File 'app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb', line 54

def component_form
  @component_form ||= component_model.find do |cm|
    cm.subject_id == subject_id
  end
end

#manifestObject



48
49
50
51
52
# File 'app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb', line 48

def manifest
  @manifest ||= Decidim.participatory_space_manifests.find do |m|
    m.name == subject_manifest.to_sym
  end
end

#map_model(model) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb', line 11

def map_model(model)
  component = model if model.is_a?(Decidim::Component)
  subject = if component
              model.participatory_space
            else
              model
            end

  self.subject_manifest = Decidim.participatory_space_manifests.find do |m|
    m.model_class_name == subject.class.name
  end.try(:name)
  self.subject_id = subject.id

  return unless component

  self.component_model = [
    TermCustomizer::Admin::TranslationSetSubjectComponentForm.from_params(
      subject_id: subject.id,
      component_id: component.id
    )
  ]
end

#subjectObject



34
35
36
37
38
# File 'app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb', line 34

def subject
  return unless manifest

  @subject ||= manifest.model_class_name.constantize.find_by(id: subject_id)
end