diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index acb976c72..c206021ef 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -1232,20 +1232,35 @@ function reportHandsonTableConverter() { }); } + function reCheckContinueButton() { + if (dropdownSelector.getValues('#projectSelector').length > 0 + && dropdownSelector.getValues('#templateSelector').length > 0) { + $('.continue-button').attr('disabled', false); + } else { + $('.continue-button').attr('disabled', true); + } + } + function initDropdowns() { dropdownSelector.init('#projectSelector', { singleSelect: true, closeOnSelect: true, noEmptyOption: true, selectAppearance: 'simple', - onChange: function() { + onSelect: function() { let projectContents = $('#new-report-step-2').find('.project-contents'); let loadedProjectId = parseInt(projectContents.attr('data-project-id'), 10); let projectId = parseInt(dropdownSelector.getValues('#projectSelector'), 10); if (!Number.isNaN(loadedProjectId) && loadedProjectId !== projectId) { $('#projectReportWarningModal').modal('show'); } - $('.continue-button').attr('disabled', false); + if (dropdownSelector.getValues('#projectSelector').length > 0) { + dropdownSelector.enableSelector('#templateSelector'); + } else { + dropdownSelector.selectValues('#templateSelector', ''); + dropdownSelector.disableSelector('#templateSelector'); + } + reCheckContinueButton(); } }); @@ -1255,9 +1270,15 @@ function reportHandsonTableConverter() { noEmptyOption: true, selectAppearance: 'simple', disableSearch: true, - onChange: function() { + onSelect: function() { + if (dropdownSelector.getValues('#templateSelector').length === 0) { + $('.report-template-values-container').html('').addClass('hidden'); + reCheckContinueButton(); + return; + } + let filledFieldsCount = $('.report-template-values-container') - .find('input.sci-input-field, textarea.sci-input-field').filter(function () { + .find('input.sci-input-field, textarea.sci-input-field').filter(function() { return !!this.value; }).length; @@ -1266,8 +1287,13 @@ function reportHandsonTableConverter() { } else { $('#templateReportWarningModal').modal('show'); } + reCheckContinueButton(); } }); + + if (dropdownSelector.getValues('#templateSelector').length > 0) { + loadTemplate(); + } } function loadTemplate() { @@ -1279,6 +1305,7 @@ function reportHandsonTableConverter() { $('#templateSelector').data('selected-template', template); $.get($('#templateSelector').data('valuesEditorPath'), params, function(result) { + $('.report-template-values-container').removeClass('hidden'); $('.report-template-values-container').html(result.html); $('.report-template-value-dropdown').each(function() { dropdownSelector.init($(this), { diff --git a/app/assets/javascripts/sitewide/dropdown_selector.js b/app/assets/javascripts/sitewide/dropdown_selector.js index ceb45ff66..a4198abae 100644 --- a/app/assets/javascripts/sitewide/dropdown_selector.js +++ b/app/assets/javascripts/sitewide/dropdown_selector.js @@ -145,7 +145,9 @@ var dropdownSelector = (function() { function disableEnableDropdown(selector, container, mode) { var searchFieldValue = container.find('.search-field'); if (mode) { - updateCurrentData(container, []); + if ($(selector).data('ajax-url')) { + updateCurrentData(container, []); + } updateTags(selector, container, { skipChange: true }); searchFieldValue.attr('placeholder', selector.data('disable-placeholder') || ''); container.addClass('disabled').removeClass('open') diff --git a/app/models/report.rb b/app/models/report.rb index c58b6ab26..3ade38cf6 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -35,7 +35,6 @@ class Report < ApplicationRecord dependent: :delete_all DEFAULT_SETTINGS = { - template: 'scinote_template', all_tasks: true, task: { protocol: { diff --git a/app/views/reports/wizard/_first_step.html.erb b/app/views/reports/wizard/_first_step.html.erb index a602c0a53..1dcc0617f 100644 --- a/app/views/reports/wizard/_first_step.html.erb +++ b/app/views/reports/wizard/_first_step.html.erb @@ -1,5 +1,5 @@
<%= render partial: 'reports/wizard/project_template_selector', locals: {report: report} %>
-
+
diff --git a/app/views/reports/wizard/_project_template_selector.html.erb b/app/views/reports/wizard/_project_template_selector.html.erb index 39c842b4d..a0003ebbc 100644 --- a/app/views/reports/wizard/_project_template_selector.html.erb +++ b/app/views/reports/wizard/_project_template_selector.html.erb @@ -6,16 +6,20 @@
<%= label_tag :projectSelector, t('projects.reports.wizard.first_step.select_project') %> - <%= select_tag :projectSelector, options_from_collection_for_select(@visible_projects, :id, :name, report.project_id), data: { placeholder: t('projects.reports.wizard.first_step.select_project') } %> + <%= select_tag :projectSelector, + options_from_collection_for_select(@visible_projects, :id, :name, report.project_id), + prompt: t('projects.reports.wizard.first_step.select_project') %>
<%= label_tag :templateSelector, t('projects.reports.wizard.first_step.select_template') %> <%= select_tag :templateSelector, options_for_select(@templates.invert, report.settings[:template]), + prompt: t('projects.reports.wizard.first_step.select_template'), data: { + disable_on_load: report.settings[:template].blank?, placeholder: t('projects.reports.wizard.first_step.select_template'), - selected_template: report.settings[:template] || @templates.first[0], + selected_template: report.settings[:template], values_editor_path: reports_new_template_values_path(report_id: report.id) } %>