diff --git a/app/assets/javascripts/bulkrax/bulkrax.js b/app/assets/javascripts/bulkrax/bulkrax.js index 7720c2a4..dd35979d 100644 --- a/app/assets/javascripts/bulkrax/bulkrax.js +++ b/app/assets/javascripts/bulkrax/bulkrax.js @@ -5,19 +5,55 @@ $(document).on('turbolinks:load ready', function() { $('button#err_toggle').click(function() { $('#error_trace').toggle(); }); + $('button#fm_toggle').click(function() { $('#field_mapping').toggle(); }); + $('#bulkraxItemModal').on('show.bs.modal', function (event) { - var button = $(event.relatedTarget) // Button that triggered the modal - var recipient = button.data('entry-id') // Extract info from data-* attributes - // If necessary, you could initiate an AJAX request here (and then do the updating in a callback). - // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead. - var modal = $(this) + var button = $(event.relatedTarget); // Button that triggered the modal + var recipient = button.data('entry-id'); // Extract info from data-* attributes + + var modal = $(this); modal.find('a').each(function() { - this.href = this.href.replace(/\d+\?/, recipient + '?') - }) - return true - }) - $('#fileupload-bulkrax').hyraxUploader({maxNumberOfFiles: 1}); + this.href = this.href.replace(/\d+\?/, recipient + '?'); + }); + return true; + }); + + // Initialize the uploader + $('.fileupload-bulkrax').hyraxUploader({ maxNumberOfFiles: 1 }); + + // Function to toggle 'required' attribute based on uploaded files + function toggleRequiredAttribute() { + const fileInput = $('#addfiles'); + const uploadedFilesTable = $('.fileupload-bulkrax tbody.files'); + + if (uploadedFilesTable.find('tr.template-download').length > 0) { + // Remove 'required' if there are uploaded files + fileInput.removeAttr('required'); + } else { + // Add 'required' if no uploaded files + fileInput.attr('required', 'required'); + } + } + + // Check the required attribute when a file is added or removed + $('#addfiles').on('change', function() { + toggleRequiredAttribute(); + }); + + // Also check when an upload completes or is canceled + $('.fileupload-bulkrax').on('fileuploadcompleted fileuploaddestroyed', function() { + toggleRequiredAttribute(); + }); + + // Ensure 'required' is only added if there are no files on form reset + $('#file-upload-cancel-btn').on('click', function() { + $('#addfiles').attr('required', 'required'); + $('#addfiles').val(''); // Clear file input to ensure 'required' behavior resets + }); + + // Initial check in case files are already uploaded + toggleRequiredAttribute(); }); diff --git a/app/views/bulkrax/importers/_bagit_fields.html.erb b/app/views/bulkrax/importers/_bagit_fields.html.erb index 962e9070..f52c2022 100644 --- a/app/views/bulkrax/importers/_bagit_fields.html.erb +++ b/app/views/bulkrax/importers/_bagit_fields.html.erb @@ -60,29 +60,4 @@ <%= render 'browse_everything', form: form %> <% end %> - - - - + \ No newline at end of file diff --git a/app/views/bulkrax/importers/_file_uploader.html.erb b/app/views/bulkrax/importers/_file_uploader.html.erb index 809e5c9a..8d1b6575 100644 --- a/app/views/bulkrax/importers/_file_uploader.html.erb +++ b/app/views/bulkrax/importers/_file_uploader.html.erb @@ -1,11 +1,11 @@ -
+
-
-
- - - +
\ No newline at end of file