Sha256: bd23e865006347847889b25721bc9db4e4e92a4f92b944215a5baef24654fe71

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Decidim
  module Accountability
    module Admin
      # This command is executed when the user changes TemplateTexts from the admin
      # panel.
      class UpdateTemplateTexts < Rectify::Command
        # Initializes an UpdateResult Command.
        #
        # form - The form from which to get the data.
        # template_texts - The current instance of the template_texts to be updated.
        def initialize(form, template_texts)
          @form = form
          @template_texts = template_texts
        end

        # Updates the result if valid.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          return broadcast(:invalid) if form.invalid?

          transaction do
            update_template_texts
          end

          broadcast(:ok)
        end

        private

        attr_reader :template_texts, :form

        def update_template_texts
          template_texts.update_attributes!(
            intro: @form.intro,
            categories_label: @form.categories_label,
            subcategories_label: @form.subcategories_label,
            heading_parent_level_results: @form.heading_parent_level_results,
            heading_leaf_level_results: @form.heading_leaf_level_results,
          )
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-accountability-0.1.2 app/commands/decidim/accountability/admin/update_template_texts.rb
decidim-accountability-0.1.1 app/commands/decidim/accountability/admin/update_template_texts.rb
decidim-accountability-0.1.0 app/commands/decidim/accountability/admin/update_template_texts.rb