Class: Decidim::Forms::Admin::UpdateQuestionnaire

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(form, questionnaire, user) ⇒ UpdateQuestionnaire

Initializes a UpdateQuestionnaire Command.

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



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

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

Instance Method Details

#callObject

Updates the questionnaire if valid.

Broadcasts :ok if successful, :invalid otherwise.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/commands/decidim/forms/admin/update_questionnaire.rb', line 22

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

  Decidim.traceability.perform_action!("update",
                                       @questionnaire,
                                       @user) do
    Decidim::Forms::Questionnaire.transaction do
      if @questionnaire.questions_editable?
        update_questionnaire_questions
        delete_answers unless @questionnaire.published?
      end

      update_questionnaire
    end
  end

  broadcast(:ok)
end