Sha256: 62e954ff15046f2430eb41b446cdfb390850c7cc0703e096922ada58f50320cb

Contents?: true

Size: 1.2 KB

Versions: 15

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Decidim
  module Templates
    module Admin
      class CreateTemplate < Decidim::Command
        # Initializes the command.
        #
        # form - The source for this generic Template.
        def initialize(form)
          @form = form
        end

        # 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.
        def call
          return broadcast(:invalid) unless @form.valid?

          @template = Decidim.traceability.create!(
            Template,
            @form.current_user,
            name: @form.name,
            description: @form.description,
            organization: @form.current_organization,
            field_values:,
            target:
          )

          assign_template!

          broadcast(:ok, @template)
        end

        protected

        def assign_template!
          @template.update!(templatable: @form.current_organization)
        end

        def field_values
          {}
        end

        def target
          raise "Not implemented"
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decidim-templates-0.29.2 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.28.5 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.29.1 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.28.4 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.29.0 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.28.3 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.29.0.rc4 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.29.0.rc3 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.29.0.rc2 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.29.0.rc1 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.28.2 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.28.1 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.28.0 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.28.0.rc5 app/commands/decidim/templates/admin/create_template.rb
decidim-templates-0.28.0.rc4 app/commands/decidim/templates/admin/create_template.rb