Sha256: cdb1d33556f5ec1ea43e410749af2dd682eb44f6e2900ce96fca8450c2f4218e

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

module CurationConcerns
  module Forms
    class CollectionEditForm
      include HydraEditor::Form
      self.model_class = ::Collection

      delegate :human_readable_type, :member_ids, to: :model

      self.terms = [:resource_type, :title, :creator, :contributor, :description,
                    :keyword, :rights, :publisher, :date_created, :subject, :language,
                    :representative_id, :thumbnail_id, :identifier, :based_near,
                    :related_url, :visibility]

      # Test to see if the given field is required
      # @param [Symbol] key a field
      # @return [Boolean] is it required or not
      def required?(key)
        model_class.validators_on(key).any? { |v| v.is_a? ActiveModel::Validations::PresenceValidator }
      end

      # @return [Hash] All FileSets in the collection, file.to_s is the key, file.id is the value
      def select_files
        Hash[all_files]
      end

      private

        def all_files
          member_presenters.flat_map(&:file_set_presenters).map { |x| [x.to_s, x.id] }
        end

        def member_presenters
          PresenterFactory.build_presenters(model.member_ids, WorkShowPresenter, nil)
        end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
curation_concerns-1.0.0.beta7 app/forms/curation_concerns/forms/collection_edit_form.rb
curation_concerns-1.0.0.beta6 app/forms/curation_concerns/forms/collection_edit_form.rb
curation_concerns-1.0.0.beta5 app/forms/curation_concerns/forms/collection_edit_form.rb
curation_concerns-1.0.0.beta4 app/forms/curation_concerns/forms/collection_edit_form.rb
curation_concerns-1.0.0.beta3 app/forms/curation_concerns/forms/collection_edit_form.rb
curation_concerns-1.0.0.beta2 app/forms/curation_concerns/forms/collection_edit_form.rb