Class: Decidim::Templates::Admin::CopyQuestionnaireTemplate

Inherits:
Rectify::Command
  • Object
show all
Defined in:
decidim-templates/app/commands/decidim/templates/admin/copy_questionnaire_template.rb

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ CopyQuestionnaireTemplate

Public: Initializes the command.

template - A template we want to duplicate


11
12
13
# File 'decidim-templates/app/commands/decidim/templates/admin/copy_questionnaire_template.rb', line 11

def initialize(template)
  @template = template
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form wasn't valid and we couldn't proceed.

Returns nothing.


21
22
23
24
25
26
27
28
29
30
# File 'decidim-templates/app/commands/decidim/templates/admin/copy_questionnaire_template.rb', line 21

def call
  return broadcast(:invalid) unless @template.valid?

  Template.transaction do
    copy_template
    copy_questionnaire_questions(@template.templatable, @copied_template.templatable)
  end

  broadcast(:ok, @copied_template)
end