Class: Decidim::Forms::ResponseQuestionnaire
- Includes:
- MultipleAttachmentsMethods
- Defined in:
- decidim-forms/app/commands/decidim/forms/response_questionnaire.rb
Overview
This command is executed when the user responds a Questionnaire.
Instance Attribute Summary collapse
-
#allow_editing_responses ⇒ Object
readonly
Returns the value of attribute allow_editing_responses.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#questionnaire ⇒ Object
readonly
Returns the value of attribute questionnaire.
Instance Method Summary collapse
-
#call ⇒ Object
Responds a questionnaire if it is valid.
-
#initialize(form, questionnaire, allow_editing_responses: false) ⇒ ResponseQuestionnaire
constructor
Initializes a ResponseQuestionnaire Command.
Methods inherited from Command
call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events
Constructor Details
#initialize(form, questionnaire, allow_editing_responses: false) ⇒ ResponseQuestionnaire
Initializes a ResponseQuestionnaire Command.
form - The form from which to get the data. questionnaire - The current instance of the questionnaire to be responded. allow_editing_responses - Flag that ensures a form can or cannot be editable after the questionnaire’s responses have been provided.
15 16 17 18 19 |
# File 'decidim-forms/app/commands/decidim/forms/response_questionnaire.rb', line 15 def initialize(form, questionnaire, allow_editing_responses: false) @form = form @questionnaire = questionnaire @allow_editing_responses = allow_editing_responses end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Decidim::Command
Instance Attribute Details
#allow_editing_responses ⇒ Object (readonly)
Returns the value of attribute allow_editing_responses.
40 41 42 |
# File 'decidim-forms/app/commands/decidim/forms/response_questionnaire.rb', line 40 def allow_editing_responses @allow_editing_responses end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
40 41 42 |
# File 'decidim-forms/app/commands/decidim/forms/response_questionnaire.rb', line 40 def form @form end |
#questionnaire ⇒ Object (readonly)
Returns the value of attribute questionnaire.
40 41 42 |
# File 'decidim-forms/app/commands/decidim/forms/response_questionnaire.rb', line 40 def questionnaire @questionnaire end |
Instance Method Details
#call ⇒ Object
Responds a questionnaire if it is valid
Broadcasts :ok if successful, :invalid otherwise.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'decidim-forms/app/commands/decidim/forms/response_questionnaire.rb', line 24 def call return broadcast(:invalid) if @form.invalid? || (user_already_responded? && !allow_editing_responses) with_events do clear_responses! if allow_editing_responses response_questionnaire end if @errors broadcast(:invalid) else broadcast(:ok) end end |