Skip to content

Commit

Permalink
disable file upload submit button until a file has been selected
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Oct 15, 2024
1 parent f64c5f4 commit 14d2521
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 24 deletions.
6 changes: 6 additions & 0 deletions app/assets/javascripts/theses.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
});
3 changes: 3 additions & 0 deletions app/assets/stylesheets/bootstrap_and_overrides.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,7 @@ form.thesis-form {
.form-check {
clear: both;
}
}
.navbar {
margin-bottom: 1rem;
}
4 changes: 1 addition & 3 deletions app/views/documents/_document.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
<div class="col-12 col-md-1 p-3">
<div class="d-flex align-items-center">
<div class="flex-shrink-0">
<%= link_to_unless_current edit_student_thesis_document_path(@student, @thesis, document) do %>
<i class="fa fa-file fa-2x me-2 text-warning"></i>
<% end %>
<i class="fa fa-file fa-2x me-2 text-warning"></i>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/documents/_file_upload_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
</div>
</div>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/documents/_form.html.erb
Original file line number Diff line number Diff line change
@@ -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| %>

<h2 class="fs-6">
<% if @document.usage == 'thesis' && !@document.supplemental %>
Expand Down Expand Up @@ -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' %>
Expand Down
9 changes: 6 additions & 3 deletions app/views/documents/edit.js.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
$('#file_upload_modal_container').remove();
$('body').append('<div id="file_upload_modal_container"></div>');
$('#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');
}
});
9 changes: 6 additions & 3 deletions app/views/documents/new.js.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
$('#file_upload_modal_container').remove();
$('body').append('<div id="file_upload_modal_container"></div>');
$('#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');
}
});
18 changes: 11 additions & 7 deletions app/views/student_view/process/review.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,27 @@

<div class="licence-box my-5 mt-3 bg-light p-3" >
<h4 title="LAC Supplementary Licence File Upload">Library and Archives Canada Licence</h4>
<hr class="text-primary border-3">

<% if AppSettings.student_review_lac_licence_instructions.present? %>
<p><%= raw(AppSettings.student_review_lac_licence_instructions) %></p>
<% end %>
<% if @licence_documents.count == 0 %>
<!-- show nothing -->
<div class="small text-secondary">
<%= raw(AppSettings.student_review_lac_licence_instructions) %>
</div>
<% end %>

<hr class="text-primary border-3">

<% @licence_documents.each do | document | %>
<%= render partial: document %>
<% end %>
<br/>

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

<div class="bg-secondary-subtle p-2 fw-bold">
<%= f.input :lac_licence_agreement, as: :boolean, input_html: {class: ""}, label: "I agree to and I have signed LAC Form" %>
</div>
Expand Down
11 changes: 6 additions & 5 deletions app/views/theses/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,16 @@
<h5>Primary Thesis File</h5>
<% if @primary_documents.count == 0 %>
<p>There are no primary thesis files.</p>

<% 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 %>
</div>

<div class="bg-light-subtle mt-3 p-3">
Expand Down

0 comments on commit 14d2521

Please sign in to comment.