Class: Decidim::Forms::Admin::DisplayConditionForm

Inherits:
Decidim::Form show all
Includes:
TranslatableAttributes
Defined in:
decidim-forms/app/forms/decidim/forms/admin/display_condition_form.rb

Overview

This class holds a Form to update questionnaire questions 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 AttributeObject::Form

ensure_hash, from_model, from_params, hash_from, infer_model_name, #map_model, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #valid?, #with_context

Methods included from AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#answer_optionObject

Finds the Answer Option from the given decidim_answer_option_id

Returns a Decidim::Forms::AnswerOption


71
72
73
# File 'decidim-forms/app/forms/decidim/forms/admin/display_condition_form.rb', line 71

def answer_option
  @answer_option ||= AnswerOption.find_by(id: decidim_answer_option_id)
end

#answer_optionsObject


35
36
37
38
39
# File 'decidim-forms/app/forms/decidim/forms/admin/display_condition_form.rb', line 35

def answer_options
  return [] if condition_question.blank?

  condition_question.answer_options
end

#condition_questionObject

Finds the Condition Question from the given decidim_condition_question_id

Returns a Decidim::Forms::Question


64
65
66
# File 'decidim-forms/app/forms/decidim/forms/admin/display_condition_form.rb', line 64

def condition_question
  @condition_question ||= Question.find_by(id: decidim_condition_question_id)
end

#questionObject

Finds the Question from the given decidim_question_id

Returns a Decidim::Forms::Question


57
58
59
# File 'decidim-forms/app/forms/decidim/forms/admin/display_condition_form.rb', line 57

def question
  @question ||= Question.find_by(id: decidim_question_id)
end

#questions_for_select(questionnaire, id) ⇒ Object


41
42
43
44
45
46
47
48
49
50
51
52
# File 'decidim-forms/app/forms/decidim/forms/admin/display_condition_form.rb', line 41

def questions_for_select(questionnaire, id)
  questionnaire.questions.map do |question|
    [
      question.translated_body,
      question.id,
      {
        "disabled" => (question.question_type == "sorting" || question.id == id),
        "data-type" => question.question_type
      }
    ]
  end
end

#to_paramObject


29
30
31
32
33
# File 'decidim-forms/app/forms/decidim/forms/admin/display_condition_form.rb', line 29

def to_param
  return id if id.present?

  "questionnaire-display-condition-id"
end