Sha256: a1679b3bbefb33e548503ac11798e57dcce86fc28fcc9bd9147c591f4683c97e

Contents?: true

Size: 909 Bytes

Versions: 3

Compression:

Stored size: 909 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Templates
    # A command with all the business logic when duplicating a proposal's answer template
    module Admin
      class CopyProposalAnswerTemplate < Decidim::Command
        def initialize(template)
          @template = template
        end

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

          Template.transaction do
            copy_template
          end

          broadcast(:ok, @copied_template)
        end

        def copy_template
          @copied_template = Template.create!(
            organization: @template.organization,
            name: @template.name,
            description: @template.description,
            target: :proposal_answer,
            field_values: @template.field_values,
            templatable: @template.templatable
          )
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-reporting_proposals-0.5.2 app/commands/decidim/templates/admin/copy_proposal_answer_template.rb
decidim-reporting_proposals-0.5.1 app/commands/decidim/templates/admin/copy_proposal_answer_template.rb
decidim-reporting_proposals-0.5.0 app/commands/decidim/templates/admin/copy_proposal_answer_template.rb