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

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

Overview

This class holds a Form to update questionnaire questions from Decidim’s admin panel.

Instance Method Summary collapse

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 '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 '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 '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 '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 '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 'app/forms/decidim/forms/admin/display_condition_form.rb', line 29

def to_param
  return id if id.present?

  "questionnaire-display-condition-id"
end