diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 99c02c3..2666ef6 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -24,18 +24,15 @@ $(document).ready(function () { - $('.dropdown-toggle').dropdown(); // disable in browser form validations $('form').find('input').removeAttr('required'); - $('.theses .options a').click(function (e) { e.preventDefault(); $(this).tab('show'); $(".theses .options a").removeClass("active") $(this).addClass("active") }) - -}); +}); \ No newline at end of file diff --git a/app/assets/javascripts/theses.js b/app/assets/javascripts/theses.js index 39761da..532562b 100644 --- a/app/assets/javascripts/theses.js +++ b/app/assets/javascripts/theses.js @@ -37,10 +37,4 @@ $(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/models/document.rb b/app/models/document.rb index f253a3b..b42c78f 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -29,7 +29,31 @@ class Document < ApplicationRecord attribute :usage, default: :thesis + + PRIMARY_FILE_EXT = [ '.pdf' ].freeze + SUPPLEMENTAL_FILE_EXT = ['.pdf', '.doc', '.docx', '.txt', '.html', '.htm', '.odt', '.odp', + '.ods', '.png', '.tif', '.jpg', '.csv', '.xml', '.avi', '.flac', '.wav', '.mp3', '.mp4', '.mov'].freeze + EMBARGO_FILE_EXT = ['.pdf', '.txt', '.html', '.htm', '.odt', '.odp', '.ods'].freeze + LICENCE_FILE_EXT = [ '.pdf' ].freeze + #### ADDITIONAL METHODS + def allowed_extensions + list = PRIMARY_FILE_EXT + + case document_type + when 'primary' + list = PRIMARY_FILE_EXT + when 'supplemental' + list = SUPPLEMENTAL_FILE_EXT + when 'licence' + list = LICENCE_FILE_EXT + when 'embargo' + list = EMBARGO_FILE_EXT + end + + return list + end + def image? file.to_s.include?('.gif') or file.to_s.include?('.png') or file.to_s.include?('.jpg') end @@ -55,15 +79,17 @@ def primary_file_must_be_pdf return if file.filename.downcase.end_with?('.pdf') - errors.add(:file, 'Primary file must be a PDF') + errors.add(:file, "extension #{ext} is not allowed.") end def supplemental_file_must_be_file_types - supplemental_file_types = ['.pdf', '.doc', '.docx', '.txt', '.html', '.htm', '.odt', '.odp', '.ods', '.png', '.tif', '.jpg', '.csv', '.xml', '.avi', '.flac', '.wav', '.mp3', '.mp4', '.mov'] - embargo_file_types = ['.pdf', '.txt', '.html', '.htm', '.odt', '.odp', '.ods'] + supplemental_file_types = SUPPLEMENTAL_FILE_EXT + embargo_file_types = EMBARGO_FILE_EXT return unless file.filename.present? && supplemental + ext = '.' + file.filename.downcase.split('.').pop + if document_type == "licence" return if file.filename.downcase.end_with?('.pdf') elsif document_type == "supplemental" @@ -72,7 +98,7 @@ def supplemental_file_must_be_file_types return if embargo_file_types.include?(File.extname(file.filename.downcase)) end - errors.add(:file, "#{document_type.capitalize} file must be a valid file type") + errors.add(:file, "extension #{ext} is not allowed.") end def document_type diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb index 071ded5..55740f7 100644 --- a/app/views/documents/_form.html.erb +++ b/app/views/documents/_form.html.erb @@ -1,4 +1,5 @@ -<%= simple_form_for [@student, @thesis, @document], authenticity_token: true, html: { multipart: true, class: "file-upload" } do |f| %> +<%= simple_form_for [@student, @thesis, @document], authenticity_token: true, +html: { multipart: true, class: "file-upload" } do |f| %>