From 14d2521c9ed9f0623ab20959fa4d4d12a7dcd6ca Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Tue, 15 Oct 2024 19:10:15 -0400 Subject: [PATCH] disable file upload submit button until a file has been selected --- app/assets/javascripts/theses.js | 6 ++++++ .../bootstrap_and_overrides.css.scss | 3 +++ app/views/documents/_document.html.erb | 4 +--- .../documents/_file_upload_modal.html.erb | 2 +- app/views/documents/_form.html.erb | 4 ++-- app/views/documents/edit.js.erb | 9 ++++++--- app/views/documents/new.js.erb | 9 ++++++--- app/views/student_view/process/review.html.erb | 18 +++++++++++------- app/views/theses/show.html.erb | 11 ++++++----- 9 files changed, 42 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/theses.js b/app/assets/javascripts/theses.js index 532562b..39761da 100644 --- a/app/assets/javascripts/theses.js +++ b/app/assets/javascripts/theses.js @@ -37,4 +37,10 @@ $(document).ready(function () { source: committee_member_names_list }); }); + + $('form.file-upload input.file').change ( function() { + if ($(this).val()) { + $(this).parents('form:first').find('input:submit').removeAttr('disabled'); + } + }); }); diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.scss b/app/assets/stylesheets/bootstrap_and_overrides.css.scss index 3ab2c4b..735b372 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.scss +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.scss @@ -147,4 +147,7 @@ form.thesis-form { .form-check { clear: both; } +} +.navbar { + margin-bottom: 1rem; } \ No newline at end of file diff --git a/app/views/documents/_document.html.erb b/app/views/documents/_document.html.erb index 2648b25..72414c7 100644 --- a/app/views/documents/_document.html.erb +++ b/app/views/documents/_document.html.erb @@ -2,9 +2,7 @@
- <%= link_to_unless_current edit_student_thesis_document_path(@student, @thesis, document) do %> - - <% end %> +
diff --git a/app/views/documents/_file_upload_modal.html.erb b/app/views/documents/_file_upload_modal.html.erb index ef01d44..ecb8f19 100644 --- a/app/views/documents/_file_upload_modal.html.erb +++ b/app/views/documents/_file_upload_modal.html.erb @@ -12,4 +12,4 @@ - + \ No newline at end of file diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb index b3e3c97..4e58a12 100644 --- a/app/views/documents/_form.html.erb +++ b/app/views/documents/_form.html.erb @@ -1,4 +1,4 @@ -<%= simple_form_for [@student, @thesis, @document], authenticity_token: true, html: { multipart: true } do |f| %> +<%= simple_form_for [@student, @thesis, @document], authenticity_token: true, html: { multipart: true, class: "file-upload" } do |f| %>

<% if @document.usage == 'thesis' && !@document.supplemental %> @@ -41,7 +41,7 @@ <%= f.hidden_field :usage, value: @document.usage %> <%= f.hidden_field :supplemental, value: @document.supplemental %> - <%= f.button :submit, "Upload", class: "btn btn-primary" %> + <%= f.button :submit, "Upload", class: "btn btn-primary file-upload", disabled: true %> <% if (defined? modal).nil? || !modal %> <% if current_user.role == User::STUDENT && @document.usage == 'licence' %> diff --git a/app/views/documents/edit.js.erb b/app/views/documents/edit.js.erb index 373c8a5..97b1239 100644 --- a/app/views/documents/edit.js.erb +++ b/app/views/documents/edit.js.erb @@ -1,6 +1,9 @@ $('#file_upload_modal_container').remove(); $('body').append('
'); $('#file_upload_modal_container').append('<%= j render "file_upload_modal" %>'); -new bootstrap.Modal(document.getElementById('file_upload_modal'), { - backdrop: 'static' -}).show(); +new bootstrap.Modal(document.getElementById('file_upload_modal')).show(); +$('form.file-upload input.file').change ( function() { + if ($(this).val()) { + $(this).parents('form:first').find('input:submit').removeAttr('disabled'); + } +}); \ No newline at end of file diff --git a/app/views/documents/new.js.erb b/app/views/documents/new.js.erb index 373c8a5..97b1239 100644 --- a/app/views/documents/new.js.erb +++ b/app/views/documents/new.js.erb @@ -1,6 +1,9 @@ $('#file_upload_modal_container').remove(); $('body').append('
'); $('#file_upload_modal_container').append('<%= j render "file_upload_modal" %>'); -new bootstrap.Modal(document.getElementById('file_upload_modal'), { - backdrop: 'static' -}).show(); +new bootstrap.Modal(document.getElementById('file_upload_modal')).show(); +$('form.file-upload input.file').change ( function() { + if ($(this).val()) { + $(this).parents('form:first').find('input:submit').removeAttr('disabled'); + } +}); \ No newline at end of file diff --git a/app/views/student_view/process/review.html.erb b/app/views/student_view/process/review.html.erb index 1f46231..7e5d27e 100644 --- a/app/views/student_view/process/review.html.erb +++ b/app/views/student_view/process/review.html.erb @@ -39,23 +39,27 @@

Library and Archives Canada Licence

-
+ <% if AppSettings.student_review_lac_licence_instructions.present? %> -

<%= raw(AppSettings.student_review_lac_licence_instructions) %>

- <% end %> - <% if @licence_documents.count == 0 %> - +
+ <%= raw(AppSettings.student_review_lac_licence_instructions) %> +
<% end %> + +
<% @licence_documents.each do | document | %> <%= render partial: document %> <% end %> -
+ <% unless block_thesis_changes?(@thesis) %> +

<%= link_to new_student_thesis_document_path(@student, @thesis, usage: 'licence', supplemental: true), class: "btn btn-primary", remote: true do %> Upload Licence Files + <% end %> +

<% end %> - <% end %> +
<%= f.input :lac_licence_agreement, as: :boolean, input_html: {class: ""}, label: "I agree to and I have signed LAC Form" %>
diff --git a/app/views/theses/show.html.erb b/app/views/theses/show.html.erb index 65e09be..ca0bcd6 100644 --- a/app/views/theses/show.html.erb +++ b/app/views/theses/show.html.erb @@ -101,15 +101,16 @@
Primary Thesis File
<% if @primary_documents.count == 0 %>

There are no primary thesis files.

+ + <% unless block_thesis_changes?(@thesis) %> + <%= link_to new_student_thesis_document_path(@student, @thesis, usage: 'thesis', supplemental: false), class: "btn btn-primary", remote: true do %> + Upload Primary Thesis Files + <% end %> + <% end %> <% end %> <% @primary_documents.each do | document | %> <%= render partial: document %> <% end %> - <% unless block_thesis_changes?(@thesis) %> - <%= link_to new_student_thesis_document_path(@student, @thesis, usage: 'thesis', supplemental: false), class: "btn btn-primary", remote: true do %> - Upload Primary Thesis Files - <% end %> - <% end %>