Class: Decidim::Surveys::Admin::UpdateSurveySettings

Inherits:
Forms::Admin::UpdateQuestionnaire show all
Defined in:
decidim-surveys/app/commands/decidim/surveys/admin/update_survey_settings.rb

Overview

This command is executed when the user changes a Survey Settings (also known as their attributes) from the admin panel.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form, survey, user) ⇒ UpdateSurveySettings

Initializes a UpdateSurveySettings Command.

form - The form from which to get the data. survey - The current instance of the survey to be updated. user - The user doing the update



14
15
16
17
18
# File 'decidim-surveys/app/commands/decidim/surveys/admin/update_survey_settings.rb', line 14

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

Dynamic Method Handling

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

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



20
21
22
# File 'decidim-surveys/app/commands/decidim/surveys/admin/update_survey_settings.rb', line 20

def form
  @form
end

#surveyObject (readonly)

Returns the value of attribute survey.



20
21
22
# File 'decidim-surveys/app/commands/decidim/surveys/admin/update_survey_settings.rb', line 20

def survey
  @survey
end

#userObject (readonly)

Returns the value of attribute user.



20
21
22
# File 'decidim-surveys/app/commands/decidim/surveys/admin/update_survey_settings.rb', line 20

def user
  @user
end

Instance Method Details

#callObject

Updates the survey questionnaire if valid.

Broadcasts :ok if successful, :invalid otherwise.



25
26
27
28
29
30
31
32
33
34
35
# File 'decidim-surveys/app/commands/decidim/surveys/admin/update_survey_settings.rb', line 25

def call
  Decidim.traceability.perform_action!("update", survey, user) do
    transaction do
      update_survey_settings
    end
  rescue ActiveRecord::RecordInvalid
    broadcast(:invalid)
  end

  broadcast(:ok)
end