diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index d0a7e107a..ce87cca6c 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -1099,6 +1099,18 @@ function reportHandsonTableConverter() { return checked.length === all.length; } + function validateGenerateButtons() { + var validName = ($('.report-name').val().length >= GLOBAL_CONSTANTS.NAME_MIN_LENGTH); + var validContent = Object.keys(getReportData().project_content.experiments).length > 0; + if (validName && validContent) { + $('.generate-button').prop('disabled', false); + $(' #saveAsNewReport, #UpdateReport').removeClass('disabled'); + } else { + $('.generate-button').prop('disabled', true); + $(' #saveAsNewReport, #UpdateReport').addClass('disabled'); + } + } + $('.continue-button').on('click', function() { nextStep(); }); @@ -1132,6 +1144,11 @@ function reportHandsonTableConverter() { $('.protocol-steps-checkbox').prop('checked', allCheckboxesSelected($('.report-protocol-settings'))); $('.all-results-checkbox').prop('checked', allCheckboxesSelected($('.report-result-settings'))); $('.select-all-task-contents').prop('checked', allCheckboxesSelected($('.report-task-settings'))); + validateGenerateButtons(); + }); + + $('.report-name').on('change', function() { + validateGenerateButtons(); }); } diff --git a/app/views/reports/new.html.erb b/app/views/reports/new.html.erb index 9766afaf3..fac4aae82 100644 --- a/app/views/reports/new.html.erb +++ b/app/views/reports/new.html.erb @@ -4,7 +4,7 @@ " value="<%= @report.name %>"> - @@ -65,13 +65,13 @@ <% else %> - <% end %> @@ -87,6 +87,33 @@ + + <% if @edit %> <%= render partial: 'report_edit_warning_modal' %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 0bebc67e8..dc542b63a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -620,6 +620,12 @@ en: here: "here" no_columns: "You do not have File columns in selected Inventory. Add a File column to selected Inventory or select another Inventory containing File columns." nothing_selected: "Nothing selected" + exit_modal: + title_new: "Report will be lost" + title_edit: "Changes will be lost" + description_new: "You’re about to cancel the process of generating a report. This will cause all selections and possible entered data to be lost." + description_edit: "You’re about to cancel the process of generating an edited report. This will cause all changes to be lost." + description_2: "Do you want to continue?" generate_PDF: generated_on: "Report generated by SciNote on: %{timestamp}" renderers: @@ -2444,6 +2450,9 @@ en: close: "Close" create: 'Create' change: "Change" + # In order to use the strings 'yes' and 'no' as keys, you need to wrap them with quotes + 'yes': "Yes" + 'no': "No" leaving_unsaved_warning: "You have made some changes, are you sure you want to leave this page?" no_comments: "No comments!" more_comments: "More comments"