Class: Hyrax::Forms::ResourceBatchEditForm

Inherits:
ResourceForm show all
Includes:
ContainedInWorksBehavior, DepositAgreementBehavior, LeaseabilityBehavior, PermissionBehavior
Defined in:
app/forms/hyrax/forms/resource_batch_edit_form.rb

Constant Summary

Constants included from ContainedInWorksBehavior

ContainedInWorksBehavior::InWorksPrepopulator

Constants inherited from ResourceForm

Hyrax::Forms::ResourceForm::LockKeyPrepopulator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PermissionBehavior

included, #permission_populator

Methods included from LeaseabilityBehavior

#embargo_populator, included, #lease_populator, #visibility_populator

Methods included from DepositAgreementBehavior

included

Methods included from ContainedInWorksBehavior

included

Methods inherited from ResourceForm

#[]=, #display_additional_fields?, for, #model_class, #primary_terms, required_fields, required_fields=, #secondary_terms

Methods inherited from ChangeSet

for

Constructor Details

#initialize(model, _current_ability, batch_document_ids) ⇒ ResourceBatchEditForm

Returns a new instance of ResourceBatchEditForm.

Parameters:

  • model (Hyrax::Work)

    the model backing the form

  • current_ability (Ability)

    the user authorization model

  • batch_document_ids (Array<String>)

    a list of document ids in the batch



25
26
27
28
29
30
31
32
33
34
# File 'app/forms/hyrax/forms/resource_batch_edit_form.rb', line 25

def initialize(model, _current_ability, batch_document_ids)
  @names = []
  @batch_document_ids = batch_document_ids
  if @batch_document_ids.present?
    combined_fields = model_attributes(model, initialize_combined_fields)
    super(resource: model.class.new(combined_fields))
  else
    super(resource: model)
  end
end

Instance Attribute Details

#batch_document_idsObject (readonly)

Returns the value of attribute batch_document_ids.



51
52
53
# File 'app/forms/hyrax/forms/resource_batch_edit_form.rb', line 51

def batch_document_ids
  @batch_document_ids
end

#namesObject

Contains a list of titles of all the works in the batch



20
21
22
# File 'app/forms/hyrax/forms/resource_batch_edit_form.rb', line 20

def names
  @names
end

Class Method Details

.additional_permitted_paramsObject

Returns a list of parameters other than those terms for the form rubocop:disable Metrics/MethodLength



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/forms/hyrax/forms/resource_batch_edit_form.rb', line 60

def self.additional_permitted_params
  [{ permissions_attributes: [:type, :name, :access, :id, :_destroy] },
   :on_behalf_of,
   :version,
   :add_works_to_collection,
   :visibility_during_embargo,
   :embargo_release_date,
   :visibility_after_embargo,
   :visibility_during_lease,
   :lease_expiration_date,
   :visibility_after_lease,
   :visibility,
   { based_near_attributes: [:id, :_destroy] }]
end

.build_permitted_paramsObject

Returns a list of parameters we accept from the form



54
55
56
# File 'app/forms/hyrax/forms/resource_batch_edit_form.rb', line 54

def self.build_permitted_params
  terms_permitted_params + additional_permitted_params
end

.termsObject



40
41
42
43
44
45
46
47
48
49
# File 'app/forms/hyrax/forms/resource_batch_edit_form.rb', line 40

def self.terms
  return Hyrax::Forms::BatchEditForm.terms if model_class < ActiveFedora::Base

  terms_primary = definitions.select { |_, definition| definition[:primary] }
                             .keys.map(&:to_sym)
  terms_secondary = definitions.select { |_, definition| definition[:display] && !definition[:primary] }
                               .keys.map(&:to_sym)

  (terms_primary + terms_secondary) - terms_excluded
end

.terms_permitted_paramsObject

Returns a list of permitted parameters for the terms

Parameters:



79
80
81
82
83
84
85
86
87
# File 'app/forms/hyrax/forms/resource_batch_edit_form.rb', line 79

def self.terms_permitted_params
  [].tap do |params|
    terms.each do |term|
      h = {}
      h[term] = []
      params << h
    end
  end
end

Instance Method Details

#column_for_attribute(name) ⇒ Symbol

Note:

Added for ActiveModel compatibility.

Parameters:

  • name (Symbol)

Returns:

  • (Symbol)


92
93
94
# File 'app/forms/hyrax/forms/resource_batch_edit_form.rb', line 92

def column_for_attribute(name)
  name
end

#termsObject



36
37
38
# File 'app/forms/hyrax/forms/resource_batch_edit_form.rb', line 36

def terms
  self.class.terms
end