Sha256: 8544ca5f0574b0b34b32c761cf59cbd016557f8a01f9a7dfd82eb8df89ff8471

Contents?: true

Size: 1.42 KB

Versions: 5

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Hyrax
  module Forms
    ##
    # Represents a lease for edit through a work. That is, this form can
    # be used to wrap a Work in order to capture state changes related only to
    # its lease, ignoring the work's other fields.
    #
    # @note this supports the edit functionality of
    #   +LeasesControllerBehavior+.
    class WorkLeaseForm < Hyrax::ChangeSet
      property :lease, form: Hyrax::Forms::Lease, populator: :lease_populator, prepopulator: :lease_populator
      property :lease_history, virtual: true, prepopulator: proc { |_opts| self.lease_history = model.lease&.lease_history }
      property :lease_expiration_date, virtual: true, prepopulator: proc { |_opts| self.lease_expiration_date = model.lease&.lease_expiration_date }
      property :visibility_after_lease, virtual: true, prepopulator: proc { |_opts| self.visibility_after_lease = model.lease&.visibility_after_lease }
      property :visibility_during_lease, virtual: true, prepopulator: proc { |_opts| self.visibility_during_lease = model.lease&.visibility_during_lease }

      def lease_populator(**)
        self.lease = Hyrax::LeaseManager.lease_for(resource: model)
      end

      ##
      # @return [String]
      def human_readable_type
        model.to_model.human_readable_type
      end

      ##
      # @return [ActiveModel::Name]
      def model_name
        model.to_model.model_name
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/forms/hyrax/forms/work_lease_form.rb
hyrax-5.0.0 app/forms/hyrax/forms/work_lease_form.rb
hyrax-5.0.0.rc3 app/forms/hyrax/forms/work_lease_form.rb
hyrax-5.0.0.rc2 app/forms/hyrax/forms/work_lease_form.rb
hyrax-5.0.0.rc1 app/forms/hyrax/forms/work_lease_form.rb