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
-
#agreement_accepted ⇒ Object
readonly
Returns the value of attribute agreement_accepted.
-
#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.
-
#collections_for_select ⇒ Object
Get a list of collection id/title pairs for the select form.
-
#display_additional_fields? ⇒ Boolean
Do not display additional fields if there are no secondary terms.
-
#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(collection_ids) ⇒ Array
Select collection(s) based on passed-in params and existing memberships.
-
#primary_terms ⇒ Object
Fields that are automatically drawn on the page above the fold.
-
#secondary_terms ⇒ Object
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.
Constructor Details
#initialize(model, current_ability, controller) ⇒ WorkForm
Returns a new instance of WorkForm.
37 38 39 40 41 42 |
# File 'app/forms/hyrax/forms/work_form.rb', line 37 def initialize(model, current_ability, controller) @current_ability = current_ability @agreement_accepted = !model.new_record? @controller = controller super(model) end |
Instance Attribute Details
#agreement_accepted ⇒ Object (readonly)
Returns the value of attribute agreement_accepted.
21 22 23 |
# File 'app/forms/hyrax/forms/work_form.rb', line 21 def agreement_accepted @agreement_accepted end |
#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
129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/forms/hyrax/forms/work_form.rb', line 129 def self.build_permitted_params super + [ :on_behalf_of, :version, :add_works_to_collection, { work_members_attributes: [:id, :_destroy], based_near_attributes: [:id, :_destroy] } ] 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.
118 119 120 121 122 123 124 125 |
# File 'app/forms/hyrax/forms/work_form.rb', line 118 def self.sanitize_params(form_params) admin_set_id = form_params[:admin_set_id] if admin_set_id && workflow_for(admin_set_id: admin_set_id).allows_access_grant? return super end = 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.
65 66 67 68 |
# File 'app/forms/hyrax/forms/work_form.rb', line 65 def [](key) return model.member_of_collection_ids if key == :member_of_collection_ids super end |
#collections_for_select ⇒ Object
Get a list of collection id/title pairs for the select form
103 104 105 106 |
# File 'app/forms/hyrax/forms/work_form.rb', line 103 def collections_for_select service = Hyrax::CollectionsService.new(@controller) CollectionOptionsPresenter.new(service).(:edit) end |
#display_additional_fields? ⇒ Boolean
Do not display additional fields if there are no secondary terms
93 94 95 |
# File 'app/forms/hyrax/forms/work_form.rb', line 93 def display_additional_fields? secondary_terms.any? 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
51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/forms/hyrax/forms/work_form.rb', line 51 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(collection_ids) ⇒ Array
Select collection(s) based on passed-in params and existing memberships.
110 111 112 |
# File 'app/forms/hyrax/forms/work_form.rb', line 110 def member_of_collections(collection_ids) (member_of_collection_ids + Array.wrap(collection_ids)).uniq end |
#primary_terms ⇒ Object
Fields that are automatically drawn on the page above the fold
77 78 79 |
# File 'app/forms/hyrax/forms/work_form.rb', line 77 def primary_terms required_fields end |
#secondary_terms ⇒ Object
Fields that are automatically drawn on the page below the fold
82 83 84 85 86 87 88 89 |
# File 'app/forms/hyrax/forms/work_form.rb', line 82 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, :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
72 73 74 |
# File 'app/forms/hyrax/forms/work_form.rb', line 72 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.
45 46 47 |
# File 'app/forms/hyrax/forms/work_form.rb', line 45 def version model.etag end |
#work_members ⇒ Array
Returns a list of works that are members of the primary work on this form.
98 99 100 |
# File 'app/forms/hyrax/forms/work_form.rb', line 98 def work_members model.works end |