From 2178a7b0a42cc35f2f32b3fbdf7acca0362ee0f4 Mon Sep 17 00:00:00 2001
From: Alex Arnaud <alex.arnaud@biblibre.com>
Date: Fri, 21 Apr 2017 14:18:52 +0000
Subject: [PATCH] Bug 17282 - Fix QA comments - Add a loading message, -
 prevent JS error when report fails, - fix (bootstrap 3 ?) displaying problems

---
 koha-tmpl/intranet-tmpl/prog/css/staff-global.css  |   4 +
 koha-tmpl/intranet-tmpl/prog/en/includes/chart.inc |   4 +-
 .../en/modules/reports/guided_reports_start.tt     | 115 +++++++++++----------
 3 files changed, 68 insertions(+), 55 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css
index fc5a854..38b048c 100644
--- a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css
+++ b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css
@@ -3001,3 +3001,7 @@ fieldset.rows + fieldset.action {
 .yui-u .rows li p label.widelabel {
     width: auto;
 }
+
+div#makechart ol li {
+    list-style: none;
+}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/chart.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/chart.inc
index c0fa2a6..ceec7a3 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/chart.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/chart.inc
@@ -1,7 +1,7 @@
 <div id="makechart">
     [% supposed_x = header_row.shift.cell %]
 
-    <fieldset class="rows">
+    <fieldset>
         <legend>Draw a chart</legend>
         <ol>
             <li>
@@ -80,7 +80,7 @@
             </li>
 
             <li>
-                <button id="draw-chart"  class="btn">Draw</button>
+                <button id="draw-chart" class="btn btn-default">Draw</button>
             </li>
         </ol>
     </fieldset>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt
index 4a917ea..77f090e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt
@@ -900,68 +900,77 @@ canned reports and writing custom SQL reports.</p>
         $('#download-chart').hide();
         var chart;
 
-        $('#draw-chart').click(function() {
-            var x_elements = $('select[name="x"]').val();
-            var y_elements = [];
-            var groups = [];
-            var lines = [];
-            var options = {};
-
-            //var headers = [% header_row.json %];
-            headers = [% header_row.json %];
-            var results = [% results.json %]
-
-            if ($('input[name="chart-exclude-last"]').prop('checked')) {
-                results.splice(-1, 1);
-            }
 
-            $('select[name="y"]').each(function( index ) {
-                y_elements.push( $(this).val() );
-            });
-            $('select[name="group"]').each(function( index ) {
-                groups.push( $(this).val() );
-            });
-            $('.column-line').each(function( index ) {
-                if ($(this).prop('checked')) {
-                    lines.push( $(this).attr('name') );
-                }
-            });
+        [% UNLESS (errors) %]
+            $('#draw-chart').click(function() {
 
-            // Remove deleted columns from headers and results.
-            var deleted_indexes = [];
-            var kept_headers = [];
-            $.each(headers, function(index, value) {
-                if (value.cell != x_elements && $.inArray(value.cell, y_elements) === -1) {
-                    // This header is neither a x element nor in y elements. Don't need it.
-                    deleted_indexes.push(index);
-                }
-                else {
-                    kept_headers.push({cell: value.cell});
+                var btn_text = $("#draw-chart").html();
+                $("#draw-chart").html(_('Loading...'));
+
+                var x_elements = $('select[name="x"]').val();
+                var y_elements = [];
+                var groups = [];
+                var lines = [];
+                var options = {};
+
+                //var headers = [% header_row.json %];
+                headers = [% header_row.json %];
+                var results = [% results.json %]
+
+                if ($('input[name="chart-exclude-last"]').prop('checked')) {
+                    results.splice(-1, 1);
                 }
-            });
 
-            // Remove coresponding cells.
-            var kept_results = [];
-            $.each(results, function(index, value) {
-                var line = {};
-                line['cells'] = [];
-                $.each(value.cells, function(i, val) {
-                    if ($.inArray(i, deleted_indexes) === -1) {
-                        line['cells'].push({cell: val.cell});
+                $('select[name="y"]').each(function( index ) {
+                    y_elements.push( $(this).val() );
+                });
+                $('select[name="group"]').each(function( index ) {
+                    groups.push( $(this).val() );
+                });
+                $('.column-line').each(function( index ) {
+                    if ($(this).prop('checked')) {
+                        lines.push( $(this).attr('name') );
+                    }
+                });
+
+                // Remove deleted columns from headers and results.
+                var deleted_indexes = [];
+                var kept_headers = [];
+                $.each(headers, function(index, value) {
+                    if (value.cell != x_elements && $.inArray(value.cell, y_elements) === -1) {
+                        // This header is neither a x element nor in y elements. Don't need it.
+                        deleted_indexes.push(index);
+                    }
+                    else {
+                        kept_headers.push({cell: value.cell});
                     }
                 });
-                kept_results.push(line);
-            });
 
-            options.type = $('select[name="chart-type"]').val();
-            options.horizontal = $('input[name="column-horizontal"]').prop('checked');
-            options.lines = lines;
+                // Remove coresponding cells.
+                var kept_results = [];
+                $.each(results, function(index, value) {
+                    var line = {};
+                    line['cells'] = [];
+                    $.each(value.cells, function(i, val) {
+                        if ($.inArray(i, deleted_indexes) === -1) {
+                            line['cells'].push({cell: val.cell});
+                        }
+                    });
+                    kept_results.push(line);
+                });
 
+                options.type = $('select[name="chart-type"]').val();
+                options.horizontal = $('input[name="column-horizontal"]').prop('checked');
+                options.lines = lines;
 
-            chart = create_chart(kept_headers, kept_results, x_elements, y_elements, groups, options);
-            $('#chart').prepend('<div style="font-size: 1rem; text-align: center;">' + "[% name %]" + '</div>');
-            $('#download-chart').show();
-        });
+
+                chart = create_chart(kept_headers, kept_results, x_elements, y_elements, groups, options);
+                $('#chart').prepend('<div style="font-size: 1rem; text-align: center;">' + "[% name %]" + '</div>');
+                $('#download-chart').show();
+                $("#draw-chart").html(_(btn_text));
+                $("html, body").animate({ scrollTop: $(document).height() }, "slow");
+            });
+        [% END %]
     });
 </script>
 <h1>[% name %]</h1>
-- 
2.7.4