Sha256: 1b4dc96443de6a7282dae51e0715fd8de65ab2463a1eaca5a4170cab25f7dc2f
Contents?: true
Size: 1.51 KB
Versions: 19
Compression:
Stored size: 1.51 KB
Contents
# frozen_string_literal: true module Decidim module Templates # A command with all the business logic when duplicating a questionnaire template module Admin class CopyQuestionnaireTemplate < Rectify::Command include Decidim::Templates::Admin::QuestionnaireCopier # Public: Initializes the command. # # template - A template we want to duplicate def initialize(template) @template = template end # 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. 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 private attr_reader :form def copy_template @copied_template = Template.create!( organization: @template.organization, name: @template.name, description: @template.description ) @resource = Decidim::Forms::Questionnaire.create!( @template.templatable.dup.attributes.merge( questionnaire_for: @copied_template ) ) @copied_template.update!(templatable: @resource) end end end end end
Version data entries
19 entries across 19 versions & 1 rubygems