[chronojump-server] Fix error in csv export. Now the checkboxes are deselected each time the user redraw the table becas



commit 14c432eef68778dd03d8f05e0f175a2c56328ee5
Author: Marcos Venteo <mventeo gmail com>
Date:   Tue Oct 17 17:10:17 2017 +0200

    Fix error in csv export. Now the checkboxes are deselected each time the user redraw the table becasue of 
a filter option

 chronojumpserver/templates/results.html |   68 +++++++++++++++++++++---------
 1 files changed, 47 insertions(+), 21 deletions(-)
---
diff --git a/chronojumpserver/templates/results.html b/chronojumpserver/templates/results.html
index 0167f2b..67e653c 100755
--- a/chronojumpserver/templates/results.html
+++ b/chronojumpserver/templates/results.html
@@ -272,7 +272,7 @@ $(document).ready(function() {
                                                        var dateStr = formatDateNumber(date.getDate()) + "-" 
+ formatDateNumber(date.getMonth() + 1 ) + "-" +
                                                                date.getFullYear() + " " + 
formatDateNumber(date.getHours() + _offsetHours) + ":"
                                                                + formatDateNumber(date.getMinutes()) + ":00";
-                                                               csv += dateStr + ","
+                                                               csv += dateStr + ";"
                                                                                + data.personName + ";"
                                                                                + data.stationName +";"
                                                                                + data.exerciseName + ";"
@@ -291,7 +291,7 @@ $(document).ready(function() {
                                                var csvData = 'data:text/csv;charset=utf-8,' + "\uFEFF" + 
encodeURI(csv);
                                                // For IE (tested 10+)
                                                //console.log(filename);
-                                               console.log(csv);
+                                               //console.log(csv);
             if (window.navigator.msSaveOrOpenBlob) {
                                                                var blob = new 
Blob([decodeURIComponent(encodeURI(csv))], {
                     type: "text/csv;charset=utf-8;"
@@ -340,7 +340,7 @@ $(document).ready(function() {
                                        data: JSON.stringify(results)
                                  }).done(function(msg){
                                        // Results have been deleted. Refresh table and enable again the 
interval
-                                       console.log(msg);
+                                       //console.log(msg);
                                        $('.btnDeleteResults').addClass('disabled');
                                        table.ajax.reload(enableDeletion, false);
                                        refreshIntervalId = refreshIntervalTrigger();
@@ -396,6 +396,7 @@ $(document).ready(function() {
                          // Hide column if is a selected Player
                          //console.log(val);
                          column.visible(val == '');
+
                        });
 
                  column.data().unique().sort().each(function(d, j) {
@@ -413,6 +414,7 @@ $(document).ready(function() {
                                .search(val ? '^' + val + '$' : '', true, false)
                                .draw();
                          column.visible(val == '');
+
                        });
 
                  column.data().unique().sort().each(function(d, j) {
@@ -430,46 +432,70 @@ $(document).ready(function() {
                                .search(val ? '^' + val + '$' : '', true, false)
                                .draw();
                          column.visible(val == '');
+
                        });
 
                  column.data().unique().sort().each(function(d, j) {
                        select.append('<option value="' + d + '">' + d + '</option>')
+
                  });
+
                }
          });
+               console.log("Enable delection for first time");
                enableDeletion();
        }
   });
 
+       $('#results').on( 'draw.dt', function () {
+    console.log( 'Table redrawn' );
+               deselectAllCheckboxes();
+
+} );
+
   /* Enable the result deletion */
   function enableDeletion() {
          // Called every time a delete checkbox is changed
-         $('.deleteCheckbox').on('change', function() {
+               //alert();
+               console.log("enableDeletion called");
+               $('.deleteCheckbox').on('change', function() {
                  var totalChecked = $('.deleteCheckbox:checked').length;
-                 //console.log(totalChecked);
+                 console.log(totalChecked);
                  if (totalChecked > 0) {
-                       // Disable the refresh interval
-                       if (refreshIntervalId != -1) {
-                         clearInterval(refreshIntervalId);
-                         //console.log("Interval refresh is disabled");
-                         refreshIntervalId = -1;
-                         $('.btnDeleteResults').removeClass('disabled');
-                       }
+                               // Disable the refresh interval
+                               if (refreshIntervalId != -1) {
+                                       console.log("Clear interval Id " + refreshIntervalId);
+                                 clearInterval(refreshIntervalId);
+                                 console.log("Interval refresh is disabled");
+                                 refreshIntervalId = -1;
+                                 $('.btnDeleteResults').removeClass('disabled');
+                               }
+                               console.log("refreshIntervalId = " + refreshIntervalId);
                  } else {
-                       // Enable again the refresh interval
-                       $('.btnDeleteResults').addClass('disabled');
-                       refreshIntervalId = refreshIntervalTrigger();
-                       console.log("Interval refresh is enabled with id " + refreshIntervalId);
+                               // Enable again the refresh interval
+                               $('.btnDeleteResults').addClass('disabled');
+                               refreshIntervalId = refreshIntervalTrigger();
+                               console.log("Interval refresh is enabled with id " + refreshIntervalId);
                  }
          });
   }
 
+       function deselectAllCheckboxes() {
+               //$('.deleteCheckbox').attr("checked", false);
+               $('.deleteCheckbox').prop("checked", false);
+               $('.btnDeleteResults').addClass('disabled');
+               if (refreshIntervalId == -1) {
+                       refreshIntervalId = refreshIntervalTrigger();
+                       console.log("Interval refresh is enabled with id " + refreshIntervalId);
+               }
+       }
+
   function refreshIntervalTrigger() {
-       return setInterval(function() {
-          /* Set the interval for refresh */
-          table.ajax.reload(enableDeletion, false);
-                }, 15000);
-   };
+               return setInterval(function() {
+                  /* Set the interval for refresh */
+                  table.ajax.reload(enableDeletion, false);
+                        }, 15000);
+        };
 
    refreshIntervalId = refreshIntervalTrigger();
    console.log("Interval refresh is enabled with id " + refreshIntervalId);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]