diff --git a/app/assets/javascripts/reports/reports_datatable.js b/app/assets/javascripts/reports/reports_datatable.js index 2aee35cf1..2d604cf39 100644 --- a/app/assets/javascripts/reports/reports_datatable.js +++ b/app/assets/javascripts/reports/reports_datatable.js @@ -116,6 +116,7 @@ .attr('data-generate-pdf-path', data.generate_pdf) .attr('data-generate-docx-path', data.generate_docx) .attr('data-retry-count', 0) + .attr('data-save-to-inventory-path', data.save_to_inventory) .attr('data-id', data['0']); if (data['3'].processing || data['4'].processing) { $(row).addClass('processing'); @@ -291,6 +292,26 @@ }); } + function initSaveReportPDFToInventory() { + $('#savePdfToInventoryButton').click(function(ev) { + ev.preventDefault(); + ev.stopPropagation(); + + let id = CHECKED_REPORTS[0]; + let row = $(`.report-row[data-id='${id}']`); + let url = row.attr('data-save-to-inventory-path'); + $.get(url, function(result) { + let modal = $(result.html); + $('#content-reports-index').append(modal); + modal.modal('show'); + // Remove modal when it gets closed + modal.on('hidden.bs.modal', function() { + $(this).remove(); + }); + }); + }); + } + function initDeleteReports() { $('#delete-reports-btn').click(function() { if (CHECKED_REPORTS.length > 0) { @@ -308,5 +329,6 @@ initGeneratePDFReport(); initGenerateDocxReport(); initEditReport(); + initSaveReportPDFToInventory(); initDeleteReports(); }()); diff --git a/app/assets/javascripts/reports/save_pdf_to_inventory.js b/app/assets/javascripts/reports/save_pdf_to_inventory.js new file mode 100644 index 000000000..bb5968fb0 --- /dev/null +++ b/app/assets/javascripts/reports/save_pdf_to_inventory.js @@ -0,0 +1,282 @@ +/* globals I18n animateSpinner HelperModule */ + +(function() { + 'use strict'; + + var INVENTORY_PICKER; + var COLUMN_PICKER; + var ITEM_PICKER; + var SELECTED_IDS = { + repository_id: null, + respository_column_id: null, + repository_item_id: null + }; + + function clearErrors() { + var $columnsAlertSection = $('#save-PDF-to-inventory-column-warnings'); + var $itemsAlertSection = $('#save-PDF-to-inventory-warnings'); + $itemsAlertSection.empty(); + $columnsAlertSection.empty(); + } + + function toggleHasFileErrorMessage(value) { + var element = $('#selectInventoryItem [value="' + value + '"]'); + var $alertSection = $('#save-PDF-to-inventory-warnings'); + $alertSection.empty(); + if (element.data('hasfile')) { + $alertSection.append( + `