Sha256: eac3f07bbeead5175fd15fa09ea56c52ad4a631ea31a469adb625704c6ba6dd5

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Decidim
  module TermCustomizer
    module Admin
      # A form object to be used when admin users wants to destroy multiple
      # translations at once.
      class TranslationsDestroyForm < Decidim::Form
        mimic :translations_destroy

        delegate :translation_set, to: :context, prefix: false, allow_nil: true

        attribute :translation_ids, Array
        validates :translation_set, :translations, presence: true

        # Translations for all locales corresponding the translations passed
        # to the form.
        def translations
          return [] unless translation_set

          @translations ||= translation_set.translations.where(
            key: translation_keys
          ).order(:id)
        end

        # Only the translations passed with the IDs (current locale).
        def translations_current
          return [] unless translation_set

          @translations_current ||= translation_set.translations.where(
            id: translation_ids.uniq
          ).order(:id)
        end

        private

        # Because we want to delete all locales for the translations to be
        # deleted, find the corresponding keys for the translation IDs passed
        # from the UI (current locale).
        def translation_keys
          @translation_keys ||= translations_current.map(&:key).uniq
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-term_customizer-0.23.0 app/forms/decidim/term_customizer/admin/translations_destroy_form.rb
decidim-term_customizer-0.22.0 app/forms/decidim/term_customizer/admin/translations_destroy_form.rb
decidim-term_customizer-0.21.0 app/forms/decidim/term_customizer/admin/translations_destroy_form.rb
decidim-term_customizer-0.20.0 app/forms/decidim/term_customizer/admin/translations_destroy_form.rb
decidim-term_customizer-0.19.1 app/forms/decidim/term_customizer/admin/translations_destroy_form.rb
decidim-term_customizer-0.19.0 app/forms/decidim/term_customizer/admin/translations_destroy_form.rb
decidim-term_customizer-0.18.0 app/forms/decidim/term_customizer/admin/translations_destroy_form.rb
decidim-term_customizer-0.17.1 app/forms/decidim/term_customizer/admin/translations_destroy_form.rb