From 671efa12639e20d6d98ef366f572487f04f001e3 Mon Sep 17 00:00:00 2001
From: jazairi <16103405+jazairi@users.noreply.github.com>
Date: Fri, 6 Dec 2024 16:08:30 -0500
Subject: [PATCH] Make requested changes to the copyright and license fields
Why these changes are being introduced:
Stakeholders have requested that we preselect the 'author' copyright
value, and make the license field conditionally required when
that copyright value is selected.
Relevant ticket(s):
* [ETD-627](https://mitlibraries.atlassian.net/browse/ETD-627)
How this addresses that need:
This adds the `selected` property to the desired option in
the copyright field. It also updates the `conditionalLicenseField`
function to toggle the `required` property on the license field when
it is shown or hidden.
Side effects of this change:
* Past experience has made me wary of toggling the `required` prop
in this way. However, it is generally reliable under a single
binary condition (either the 'Author' copyright value is selected,
or it isn't). I haven't noticed any issues in click-testing.
* `selected` is tied to a value, so in this case we are preselecting
the first option. This corresponds to 'Author' in both staging and
prod, but it would be better to make an explicit association. If
the data were to change order somehow, the wrong copyright holder
could be preselected.
---
app/assets/javascripts/student_thesis_form.js | 2 ++
app/models/thesis.rb | 1 +
app/views/thesis/edit.html.erb | 6 ++++--
app/views/thesis/new.html.erb | 6 ++++--
4 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/app/assets/javascripts/student_thesis_form.js b/app/assets/javascripts/student_thesis_form.js
index a8c7ee64..14b60de1 100644
--- a/app/assets/javascripts/student_thesis_form.js
+++ b/app/assets/javascripts/student_thesis_form.js
@@ -6,9 +6,11 @@ function conditionalLicenseField() {
var value = $("select#thesis_copyright_id option:selected").text();
if ('I hold copyright' == value) {
$("div.thesis_license").show();
+ $("select#thesis_license_id").prop('required', true);
} else {
$("div.thesis_license").hide();
$("select#thesis_license_id")[0].value = "";
+ $("select#thesis_license_id").prop('required', false);
}
};
diff --git a/app/models/thesis.rb b/app/models/thesis.rb
index a8cac6fc..1c2ee202 100644
--- a/app/models/thesis.rb
+++ b/app/models/thesis.rb
@@ -62,6 +62,7 @@ class Thesis < ApplicationRecord
VALIDATION_MSGS = {
copyright: 'Required - Please identify the copyright holder.',
+ license: 'Required - Please identify the license type.',
graduation_year: 'Required - Please input your year of graduation.',
graduation_month: 'Required - Please select your month of graduation.',
departments: 'Required - Please select your primary department.',
diff --git a/app/views/thesis/edit.html.erb b/app/views/thesis/edit.html.erb
index e69ee040..3ff4b419 100644
--- a/app/views/thesis/edit.html.erb
+++ b/app/views/thesis/edit.html.erb
@@ -126,6 +126,7 @@
<%= f.association :copyright, as: :select,
+ selected: @thesis.copyright.present? ? @thesis.copyright.id : 2,
required: true,
collection: Copyright.display_to_author,
validate: { present: true },
@@ -142,12 +143,13 @@
<%= f.association :license, as: :select,
include_hidden: false,
- label: 'License (if you retain copyright)',
+ label: 'License (if you retain copyright) *',
label_method: :display_description,
label_html: { class: 'col1q' },
wrapper_html: { class: 'field-row select layout-1q3q layout-band' },
input_html: { class: 'field field-select col3q', multiple: false,
- aria: { describedby: 'thesis_license-hint' } },
+ aria: { describedby: 'thesis_license-hint' },
+ data: { msg: Thesis::VALIDATION_MSGS[:license] } },
hint: 'Not sure what to select? Learn more about Creative Commons licenses.'.html_safe,
hint_html: { class: 'col3q', id: 'thesis_license-hint' } %>
diff --git a/app/views/thesis/new.html.erb b/app/views/thesis/new.html.erb
index e91eba50..32f23d3b 100644
--- a/app/views/thesis/new.html.erb
+++ b/app/views/thesis/new.html.erb
@@ -124,6 +124,7 @@
<%= f.association :copyright, as: :select,
+ selected: 2,
required: true,
collection: Copyright.display_to_author,
validate: { presence: true },
@@ -140,12 +141,13 @@
<%= f.association :license, as: :select,
include_hidden: false,
- label: 'License (if you retain copyright)',
+ label: 'License (if you retain copyright) *',
label_method: :display_description,
label_html: { class: 'col1q' },
wrapper_html: { class: 'field-row select layout-1q3q layout-band' },
input_html: { class: 'field field-select col3q', multiple: false,
- aria: { describedby: 'thesis_license-hint' } },
+ aria: { describedby: 'thesis_license-hint' },
+ data: { msg: Thesis::VALIDATION_MSGS[:license] } },
hint: 'Not sure what to select? Learn more about Creative Commons licenses.'.html_safe,
hint_html: { class: 'col3q', id: 'thesis_license-hint' } %>