Class: Decidim::Forms::Admin::UpdateQuestions

Inherits:
Command
  • Object
show all
Defined in:
decidim-forms/app/commands/decidim/forms/admin/update_questions.rb

Overview

This command is executed when the user changes a Questionnaire questions from the admin panel.

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(form, questionnaire) ⇒ UpdateQuestions

Initializes a UpdateQuestions Command.

form - The form from which to get the data. questionnaire - The current instance of the questionnaire questions to be updated.



13
14
15
16
# File 'decidim-forms/app/commands/decidim/forms/admin/update_questions.rb', line 13

def initialize(form, questionnaire)
  @form = form
  @questionnaire = questionnaire
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Updates the questionnaire if valid.

Broadcasts :ok if successful, :invalid otherwise.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'decidim-forms/app/commands/decidim/forms/admin/update_questions.rb', line 21

def call
  return broadcast(:invalid) if @form.invalid?

  Decidim.traceability.perform_action!("update",
                                       @questionnaire,
                                       @form.current_user) do
    Decidim::Forms::Questionnaire.transaction do
      update_questionnaire_questions if @questionnaire.questions_editable?
    end
  end

  broadcast(:ok)
end