Sha256: 47dfd22d5e79712cc9cbcf65c251ff6d1065f07f5c8a8fea2567ae102c8d7180

Contents?: true

Size: 1.34 KB

Versions: 52

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A form object used to create attachments in a participatory process.
    #
    class AttachmentForm < Form
      include TranslatableAttributes

      attribute :file
      translatable_attribute :title, String
      translatable_attribute :description, String
      attribute :weight, Integer, default: 0
      attribute :attachment_collection_id, Integer

      mimic :attachment

      validates :file, presence: true, unless: :persisted?
      validates :file, passthru: { to: Decidim::Attachment }
      validates :title, :description, translatable_presence: true
      validates :attachment_collection, presence: true, if: ->(form) { form.attachment_collection_id.present? }
      validates :attachment_collection_id, inclusion: { in: :attachment_collection_ids }, allow_blank: true

      delegate :attached_to, to: :context, prefix: false

      alias organization current_organization

      def attachment_collections
        @attachment_collections ||= attached_to.attachment_collections
      end

      def attachment_collection
        @attachment_collection ||= attachment_collections.find_by(id: attachment_collection_id)
      end

      private

      def attachment_collection_ids
        @attachment_collection_ids ||= attachment_collections.pluck(:id)
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
decidim-admin-0.28.4 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.27.9 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.28.3 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.27.8 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.28.2 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.27.7 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.28.1 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.27.6 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.26.10 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.26.9 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.28.0 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.27.5 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.28.0.rc5 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.28.0.rc4 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.26.8 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.27.4 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.27.3 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.26.7 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.26.5 app/forms/decidim/admin/attachment_form.rb
decidim-admin-0.27.2 app/forms/decidim/admin/attachment_form.rb