Class: Decidim::Templates::Admin::ApplyQuestionnaireTemplate
- Inherits:
-
Command
- Object
- Command
- Decidim::Templates::Admin::ApplyQuestionnaireTemplate
- Includes:
- QuestionnaireCopier
- Defined in:
- app/commands/decidim/templates/admin/apply_questionnaire_template.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(questionnaire, template) ⇒ ApplyQuestionnaireTemplate
constructor
Public: Initializes the command.
Methods included from QuestionnaireCopier
#copy_question_display_conditions, #copy_questionnaire_answer_options, #copy_questionnaire_matrix_rows, #copy_questionnaire_questions, #find_answer_option_by_body, #find_question_by_position
Constructor Details
#initialize(questionnaire, template) ⇒ ApplyQuestionnaireTemplate
Public: Initializes the command.
template - The template we want to apply questionnaire - The questionnaire we want to use the template
14 15 16 17 |
# File 'app/commands/decidim/templates/admin/apply_questionnaire_template.rb', line 14 def initialize(questionnaire, template) @questionnaire = questionnaire @template = template end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if the form was not valid and we could not proceed.
Returns nothing.
25 26 27 28 29 30 31 32 33 34 |
# File 'app/commands/decidim/templates/admin/apply_questionnaire_template.rb', line 25 def call return broadcast(:invalid) unless @template && @template.valid? Template.transaction do apply_template copy_questionnaire_questions(@template.templatable, @questionnaire) end broadcast(:ok, @questionnaire) end |