Class: Hyrax::Forms::WorkForm Abstract
- Inherits:
-
Object
- Object
- Hyrax::Forms::WorkForm
- Includes:
- HydraEditor::Form, HydraEditor::Form::Permissions
- Defined in:
- app/forms/hyrax/forms/work_form.rb
Overview
Direct Known Subclasses
Instance Attribute Summary collapse
-
#current_ability ⇒ Object
Returns the value of attribute current_ability.
Class Method Summary collapse
-
.build_permitted_params ⇒ Array
This describes the parameters we are expecting to receive from the client.
-
.sanitize_params(form_params) ⇒ Object
Sanitize the parameters coming from the form.
Instance Method Summary collapse
-
#[](key) ⇒ Object
The value of the form field.
-
#agreement_accepted? ⇒ Boolean
(also: #agreement_accepted)
Whether the deposit agreement has already been accepted.
-
#display_additional_fields? ⇒ Boolean
Do not display additional fields if there are no secondary terms.
-
#find_child_work ⇒ NilClass
backs the child work search element.
-
#initialize(model, current_ability, controller) ⇒ WorkForm
constructor
A new instance of WorkForm.
-
#initialize_field(key) ⇒ Object
The value for some fields should not be set to the defaults ([”]) because it should be an empty array instead.
-
#member_of_collections ⇒ Object
when the add_works_to_collection parameter is set, they mean to create a new work and add it to that collection.
- #member_of_collections_json ⇒ Object
-
#primary_terms ⇒ Enumerable<Symbol>
Fields that are automatically drawn on the page above the fold.
-
#secondary_terms ⇒ Enumerable<Symbol>
Fields that are automatically drawn on the page below the fold.
-
#select_files ⇒ Hash
The possible values for the representative_id dropdown.
-
#version ⇒ String
An etag representing the current version of this form.
-
#work_members ⇒ Array
A list of works that are members of the primary work on this form.
- #work_members_json ⇒ Object
Constructor Details
#initialize(model, current_ability, controller) ⇒ WorkForm
Returns a new instance of WorkForm.
36 37 38 39 40 |
# File 'app/forms/hyrax/forms/work_form.rb', line 36 def initialize(model, current_ability, controller) @current_ability = current_ability @controller = controller super(model) end |
Instance Attribute Details
#current_ability ⇒ Object
Returns the value of attribute current_ability.
8 9 10 |
# File 'app/forms/hyrax/forms/work_form.rb', line 8 def current_ability @current_ability end |
Class Method Details
.build_permitted_params ⇒ Array
This describes the parameters we are expecting to receive from the client
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/forms/hyrax/forms/work_form.rb', line 169 def self.build_permitted_params super + [ :on_behalf_of, :version, :add_works_to_collection, { based_near_attributes: [:id, :_destroy], member_of_collections_attributes: [:id, :_destroy], work_members_attributes: [:id, :_destroy] }, { file_set: [:visibility, :visibility_during_embargo, :embargo_release_date, :visibility_after_embargo, :visibility_during_lease, :lease_expiration_date, :visibility_after_lease, :uploaded_file_id] } ] end |
.sanitize_params(form_params) ⇒ Object
Sanitize the parameters coming from the form. This ensures that the client doesn’t send us any more parameters than we expect. In particular we are discarding any access grant parameters for works that are going into a mediated deposit workflow.
160 161 162 163 164 165 |
# File 'app/forms/hyrax/forms/work_form.rb', line 160 def self.sanitize_params(form_params) admin_set_id = Array(form_params[:admin_set_id]).first return super if admin_set_id && workflow_for(admin_set_id: admin_set_id).allows_access_grant? = permitted_params.reject { |arg| arg.respond_to?(:key?) && arg.key?(:permissions_attributes) } form_params.permit(*) end |
Instance Method Details
#[](key) ⇒ Object
Returns the value of the form field.
104 105 106 107 |
# File 'app/forms/hyrax/forms/work_form.rb', line 104 def [](key) return model.member_of_collection_ids if key == :member_of_collection_ids super end |
#agreement_accepted? ⇒ Boolean Also known as: agreement_accepted
Returns whether the deposit agreement has already been accepted.
45 46 47 |
# File 'app/forms/hyrax/forms/work_form.rb', line 45 def agreement_accepted? !model.new_record? end |
#display_additional_fields? ⇒ Boolean
Do not display additional fields if there are no secondary terms
147 148 149 |
# File 'app/forms/hyrax/forms/work_form.rb', line 147 def display_additional_fields? secondary_terms.any? end |
#find_child_work ⇒ NilClass
backs the child work search element
66 |
# File 'app/forms/hyrax/forms/work_form.rb', line 66 def find_child_work; end |
#initialize_field(key) ⇒ Object
The value for some fields should not be set to the defaults ([”]) because it should be an empty array instead
90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/forms/hyrax/forms/work_form.rb', line 90 def initialize_field(key) return if [:embargo_release_date, :lease_expiration_date].include?(key) # rubocop:disable Lint/AssignmentInCondition if class_name = model_class.properties[key.to_s].try(:class_name) # Initialize linked properties such as based_near self[key] += [class_name.new] else super end # rubocop:enable Lint/AssignmentInCondition end |
#member_of_collections ⇒ Object
when the add_works_to_collection parameter is set, they mean to create a new work and add it to that collection.
53 54 55 56 57 |
# File 'app/forms/hyrax/forms/work_form.rb', line 53 def member_of_collections base = model.member_of_collections return base unless @controller.params[:add_works_to_collection] base + [::Collection.find(@controller.params[:add_works_to_collection])] end |
#member_of_collections_json ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'app/forms/hyrax/forms/work_form.rb', line 68 def member_of_collections_json member_of_collections.map do |coll| { id: coll.id, label: coll.to_s, path: @controller.url_for(coll) } end.to_json end |
#primary_terms ⇒ Enumerable<Symbol>
Fields that are automatically drawn on the page above the fold
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/forms/hyrax/forms/work_form.rb', line 119 def primary_terms primary = (required_fields & terms) (required_fields - primary).each do |missing| Hyrax.logger.warn("The form field #{missing} is configured as a " \ 'required field, but not as a term. This can lead ' \ 'to unexpected behavior. Did you forget to add it ' \ "to `#{self.class}#terms`?") end primary end |
#secondary_terms ⇒ Enumerable<Symbol>
Fields that are automatically drawn on the page below the fold
136 137 138 139 140 141 142 143 |
# File 'app/forms/hyrax/forms/work_form.rb', line 136 def secondary_terms terms - primary_terms - [:files, :visibility_during_embargo, :embargo_release_date, :visibility_after_embargo, :visibility_during_lease, :lease_expiration_date, :visibility_after_lease, :visibility, :thumbnail_id, :representative_id, :rendering_ids, :ordered_member_ids, :member_of_collection_ids, :in_works_ids, :admin_set_id] end |
#select_files ⇒ Hash
The possible values for the representative_id dropdown
111 112 113 |
# File 'app/forms/hyrax/forms/work_form.rb', line 111 def select_files Hash[file_presenters.map { |file| [file.to_s, file.id] }] end |
#version ⇒ String
Returns an etag representing the current version of this form.
60 61 62 |
# File 'app/forms/hyrax/forms/work_form.rb', line 60 def version model.etag end |
#work_members ⇒ Array
Returns a list of works that are members of the primary work on this form.
152 153 154 |
# File 'app/forms/hyrax/forms/work_form.rb', line 152 def work_members model.works end |
#work_members_json ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'app/forms/hyrax/forms/work_form.rb', line 78 def work_members_json work_members.map do |child| { id: child.id, label: child.to_s, path: @controller.url_for(child) } end.to_json end |