Merge pull request #3321 from okriuchykhin/ok_SCI_5724

Fix default empty options for report wizard first page [SCI-5724]
This commit is contained in:
Miha Mencin 2021-05-17 10:28:57 +02:00 committed by GitHub
commit 491dc22294
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 9 deletions

View file

@ -1230,20 +1230,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();
}
});
@ -1253,9 +1268,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;
@ -1264,8 +1285,13 @@ function reportHandsonTableConverter() {
} else {
$('#templateReportWarningModal').modal('show');
}
reCheckContinueButton();
}
});
if (dropdownSelector.getValues('#templateSelector').length > 0) {
loadTemplate();
}
}
function loadTemplate() {
@ -1277,6 +1303,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), {

View file

@ -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')

View file

@ -37,7 +37,6 @@ class Report < ApplicationRecord
dependent: :delete_all
DEFAULT_SETTINGS = {
template: 'scinote_template',
all_tasks: true,
task: {
protocol: {

View file

@ -1,5 +1,5 @@
<div class="project-selector-container">
<%= render partial: 'reports/wizard/project_template_selector', locals: {report: report} %>
</div>
<div class="report-template-values-container">
<div class="report-template-values-container <%= 'hidden' if report.new_record? %>">
</div>

View file

@ -6,16 +6,20 @@
<div class="col-md-6">
<div class='project-selector'>
<%= 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') %>
</div>
<div class='template-selector'>
<%= 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)
} %>
</div>