diff --git a/app/assets/javascripts/reports/reports_datatable.js b/app/assets/javascripts/reports/reports_datatable.js index 2d604cf39..c51ab7ae3 100644 --- a/app/assets/javascripts/reports/reports_datatable.js +++ b/app/assets/javascripts/reports/reports_datatable.js @@ -1,4 +1,4 @@ -/* global I18n DataTableHelpers animateSpinner HelperModule */ +/* global I18n DataTableHelpers animateSpinner HelperModule Promise */ (function() { 'use strict'; @@ -76,7 +76,7 @@ } if (data.preview_url) { - return ` + return ` ${I18n.t('projects.reports.index.docx')} `; @@ -100,7 +100,7 @@ } if (data.preview_url) { - return ` + return ` ${I18n.t('projects.reports.index.pdf')} `; @@ -247,35 +247,63 @@ }); } - function initGeneratePDFReport() { - $('.generate-pdf').click(function(ev) { + function generateReportRequest(pathAttrName) { + if (CHECKED_REPORTS.length === 1) { + let row = $(".report-row[data-id='" + CHECKED_REPORTS[0] + "']"); + animateSpinner(); + $.post(row.data(pathAttrName), function(response) { + animateSpinner(null, false); + HelperModule.flashAlertMsg(response.message, 'success'); + checkProcessingStatus(row.data('id')); + }); + } + } + + function initUpdatePDFReport() { + $('#updatePdf').click(function(ev) { ev.stopPropagation(); ev.preventDefault(); - animateSpinner(); - if (CHECKED_REPORTS.length === 1) { - let row = $(".report-row[data-id='" + CHECKED_REPORTS[0] + "']"); - $.post(row.data('generate-pdf-path'), function(response) { - animateSpinner(null, false); - HelperModule.flashAlertMsg(response.message, 'success'); - setTimeout(() => { checkProcessingStatus(row.data('id')); }, START_POLLING_INTERVAL); + + new Promise(function(resolve, reject) { + $('#regenerate-report-modal').modal('show'); + $('#regenerate-report-modal .btn-confirm').click(function() { + resolve(); }); - } + $('#regenerate-report-modal').on('hidden.bs.modal', function() { + reject(); + }); + }).then(function() { + $('#regenerate-report-modal').modal('hide'); + generateReportRequest('generate-pdf-path'); + }).catch(function() {}); }); } function initGenerateDocxReport() { - $('.generate-docx').click(function(ev) { + $('#requestDocx').click(function(ev) { ev.stopPropagation(); ev.preventDefault(); - animateSpinner(); - if (CHECKED_REPORTS.length === 1) { - let row = $(".report-row[data-id='" + CHECKED_REPORTS[0] + "']"); - $.post(row.data('generate-docx-path'), function(response) { - animateSpinner(null, false); - HelperModule.flashAlertMsg(response.message, 'success'); - setTimeout(() => { checkProcessingStatus(row.data('id')); }, START_POLLING_INTERVAL); + generateReportRequest('generate-docx-path'); + }); + } + + function initUpdateDocxReport() { + $('#updateDocx').click(function(ev) { + ev.stopPropagation(); + ev.preventDefault(); + + new Promise(function(resolve, reject) { + $('#regenerate-report-modal').modal('show'); + $('#regenerate-report-modal .btn-confirm').click(function() { + resolve(); }); - } + $('#regenerate-report-modal').on('hidden.bs.modal', function() { + reject(); + }); + }).then(function() { + $('#regenerate-report-modal').modal('hide'); + generateReportRequest('generate-docx-path'); + }).catch(function() {}); }); } @@ -326,8 +354,9 @@ } initDatatable(); - initGeneratePDFReport(); + initUpdatePDFReport(); initGenerateDocxReport(); + initUpdateDocxReport(); initEditReport(); initSaveReportPDFToInventory(); initDeleteReports(); diff --git a/app/jobs/reports/docx_job.rb b/app/jobs/reports/docx_job.rb index 8a092a248..e520e03bb 100644 --- a/app/jobs/reports/docx_job.rb +++ b/app/jobs/reports/docx_job.rb @@ -25,7 +25,7 @@ module Reports report_path = Rails.application.routes.url_helpers.reports_path notification = Notification.create( type_of: :deliver, - title: I18n.t('projects.reports.index.generation.completed_notification_title'), + title: I18n.t('projects.reports.index.generation.completed_docx_notification_title'), message: I18n.t('projects.reports.index.generation.completed_notification_message', report_link: "#{sanitize_input(report.name)}", team_name: sanitize_input(report.team.name)) diff --git a/app/jobs/reports/pdf_job.rb b/app/jobs/reports/pdf_job.rb index 4afb11582..897ccea02 100644 --- a/app/jobs/reports/pdf_job.rb +++ b/app/jobs/reports/pdf_job.rb @@ -54,7 +54,7 @@ module Reports report_path = Rails.application.routes.url_helpers.reports_path notification = Notification.create( type_of: :deliver, - title: I18n.t('projects.reports.index.generation.completed_notification_title'), + title: I18n.t('projects.reports.index.generation.completed_pdf_notification_title'), message: I18n.t('projects.reports.index.generation.completed_notification_message', report_link: "#{sanitize_input(report.name)}", team_name: sanitize_input(report.team.name)) diff --git a/app/views/reports/_index_toolbar.html.erb b/app/views/reports/_index_toolbar.html.erb index fd058cec2..b361bb5a9 100644 --- a/app/views/reports/_index_toolbar.html.erb +++ b/app/views/reports/_index_toolbar.html.erb @@ -12,7 +12,7 @@