Skip to content

Commit 86a8744

Browse files
report builder: ensure at least one section is present (#13443)
* report builder: ensure at least one section is present * report builder: ensure at least one section is present
1 parent 6661035 commit 86a8744

1 file changed

Lines changed: 49 additions & 12 deletions

File tree

dojo/templates/dojo/report_builder.html

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h4 class="pull-left">Report Format</h4>
2323
</div>
2424
<div class="panel-footer">
2525
<div class="clearfix">
26-
<a class="btn btn-success disabled pull-right run_report" href="#">Run</a>
26+
<a class="btn btn-success disabled pull-right run_report" href="#" data-toggle="tooltip" title="Add at least one section from Available Widgets before running." style="pointer-events: auto;">Run</a>
2727
</div>
2828
</div>
2929
</div>
@@ -83,8 +83,19 @@ <h4>Available Widgets</h4>
8383
}
8484
});
8585

86-
if ($('.in-use-widgets ul#sortable2 li').length > 0) {
87-
$('a.run_report').removeClass('disabled');
86+
if ($('.in-use-widgets ul#sortable2 li').not('.report-options').length > 0) {
87+
var $run = $('a.run_report');
88+
$run.removeClass('disabled')
89+
.css('pointer-events', '')
90+
.attr('title', 'Run the report')
91+
.attr('data-original-title', 'Run the report');
92+
}
93+
else {
94+
var $run = $('a.run_report');
95+
$run.addClass('disabled')
96+
.css('pointer-events', 'auto')
97+
.attr('title', 'Add at least one section from "Available Widgets" before running.')
98+
.attr('data-original-title', 'Add at least one section from "Available Widgets" before running.');
8899
}
89100
}
90101

@@ -148,6 +159,13 @@ <h4>Available Widgets</h4>
148159
function runReport(event) {
149160
var valid = true;
150161

162+
// Require at least one content widget (exclude report options)
163+
if ($('.in-use-widgets ul#sortable2 li').not('.report-options').length === 0) {
164+
alert('Please add at least one section from "Available Widgets" before running.');
165+
event.preventDefault();
166+
return;
167+
}
168+
151169
$('.in-use-widgets .form-control').not('#finding-list .form-control')
152170
.not('#endpoint-list .form-control').not('#wysiwyg-content .form-control')
153171
.not('.bs-searchbox .form-control').not('div').each(function () {
@@ -185,8 +203,7 @@ <h4>Available Widgets</h4>
185203

186204
event.preventDefault();
187205
}
188-
{% block report_functions %}
189-
{% endblock %}
206+
// placeholder for report widget scripts injected by Django blocks
190207
$(function () {
191208
$(".available-widgets > ul").sortable({
192209
handle: "div.panel div.panel-heading",
@@ -218,11 +235,21 @@ <h4>Available Widgets</h4>
218235
remove: function (event, ui) {
219236
ui.item.find('[data-toggle="tooltip"]').tooltip('hide');
220237

221-
if ($('.in-use-widgets ul#sortable2 li').length > 0) {
222-
$('a.run_report').removeClass('disabled');
238+
if ($('.in-use-widgets ul#sortable2 li').not('.report-options').length > 0) {
239+
var $run = $('a.run_report');
240+
$run.removeClass('disabled')
241+
.css('pointer-events', '')
242+
.attr('title', 'Run the report')
243+
.attr('data-original-title', 'Run the report')
244+
.tooltip('fixTitle');
223245
}
224246
else {
225-
$('a.run_report').addClass('disabled');
247+
var $run = $('a.run_report');
248+
$run.addClass('disabled')
249+
.css('pointer-events', 'auto')
250+
.attr('title', 'Add at least one section from "Available Widgets" before running.')
251+
.attr('data-original-title', 'Add at least one section from "Available Widgets" before running.')
252+
.tooltip('fixTitle');
226253
}
227254
},
228255
receive: function(event, ui) {
@@ -235,11 +262,21 @@ <h4>Available Widgets</h4>
235262
ui.item.find('[data-toggle="tooltip"]').tooltip();
236263
ui.item.find('[data-toggle="tooltip"]').tooltip('hide');
237264

238-
if ($('.in-use-widgets ul#sortable2 li').length > 0) {
239-
$('a.run_report').removeClass('disabled');
265+
if ($('.in-use-widgets ul#sortable2 li').not('.report-options').length > 0) {
266+
var $run = $('a.run_report');
267+
$run.removeClass('disabled')
268+
.css('pointer-events', '')
269+
.attr('title', 'Run the report')
270+
.attr('data-original-title', 'Run the report')
271+
.tooltip('fixTitle');
240272
}
241273
else {
242-
$('a.run_report').addClass('disabled');
274+
var $run = $('a.run_report');
275+
$run.addClass('disabled')
276+
.css('pointer-events', 'auto')
277+
.attr('title', 'Add at least one section from "Available Widgets" before running.')
278+
.attr('data-original-title', 'Add at least one section from "Available Widgets" before running.')
279+
.tooltip('fixTitle');
243280
}
244281

245282
if (ui.item.attr('class') === 'wysiwyg-content') {
@@ -339,7 +376,7 @@ <h4>Available Widgets</h4>
339376
retrieveReportData("{% url 'report_endpoints' %}" + $a.attr('href'), $a.closest('li.endpoint-list'));
340377
})
341378

342-
$('[data-toggle="tooltip"]').tooltip()
379+
$('[data-toggle="tooltip"]').tooltip({container: 'body', placement: 'top'})
343380

344381
$(document).on('click', '.in-use-widgets .panel-available-widget .panel-heading', function (event) {
345382
$(this).siblings('.panel-body').slideToggle();

0 commit comments

Comments
 (0)