[chronojump-server] Adding new csv export to sprints and the possibility to remove sprint like results. Now results and



commit b1c6d3687d30d668e362413baf7dc6f8767356b5
Author: Marcos Venteo <mventeo gmail com>
Date:   Tue Oct 17 21:28:59 2017 +0200

    Adding new csv export to sprints and the possibility to remove sprint like results. Now results and 
sprints are ordered by date with the last results in first position. The float numbers in csv export now are 
shown in csv file as number with more decimals.

 chronojumpserver/api.py                 |   12 +
 chronojumpserver/models.py              |    5 +
 chronojumpserver/templates/results.html |  748 +++++++++++++++---------------
 chronojumpserver/templates/sprints.html |  637 ++++++++++++++++-----------
 4 files changed, 771 insertions(+), 631 deletions(-)
---
diff --git a/chronojumpserver/api.py b/chronojumpserver/api.py
index e2509d6..a323772 100755
--- a/chronojumpserver/api.py
+++ b/chronojumpserver/api.py
@@ -313,6 +313,18 @@ def remove_results():
 
     return jsonify(msg="Done")
 
+@app.route('/api/v1/sprints/delete', methods=['GET', 'POST'])
+def remove_sprints():
+    if request.method == "POST":
+        results = request.json
+        for _resultId in results:
+            resultId = int(_resultId)
+            r = ResultSprint.getById(resultId)
+            db_session.delete(r)
+            db_session.commit()
+
+    return jsonify(msg="Done")
+
 @app.route('/api/v1/get_max_velocity')
 def get_max_velocity():
     stationId = request.args.get('station_id', 0)
diff --git a/chronojumpserver/models.py b/chronojumpserver/models.py
index a2744dd..c73cf5e 100755
--- a/chronojumpserver/models.py
+++ b/chronojumpserver/models.py
@@ -452,6 +452,11 @@ class ResultSprint(Base):
         """Representation of the object."""
         return '<ResultSprint %d>' % (self.id)
 
+    @classmethod
+    def getById(cls, object_id):
+        o = cls.query.filter(cls.id == object_id).first()
+        return o
+
 
 
 class User(UserMixin, Base):
diff --git a/chronojumpserver/templates/results.html b/chronojumpserver/templates/results.html
index 67e653c..538ddf6 100755
--- a/chronojumpserver/templates/results.html
+++ b/chronojumpserver/templates/results.html
@@ -15,19 +15,19 @@
 <div id="resultsFilter" class="row">
        <div class="col-sm-6">
                <label class="radio-inline dayfilter" style="margin-top:5px">
-                 <input type="radio" name="filterByDayOptions" id="filterByDay1" value="1" >1d
+                       <input type="radio" name="filterByDayOptions" id="filterByDay1" value="1" >1d
                </label>
                <label class="radio-inline dayfilter" style="margin-top:5px">
-                 <input type="radio" name="filterByDayOptions" id="filterByDay2" value="3">3d
+                       <input type="radio" name="filterByDayOptions" id="filterByDay2" value="3">3d
                </label>
                <label class="radio-inline dayfilter" style="margin-top:5px">
-                 <input type="radio" name="filterByDayOptions" id="filterByDay3" value="7">7d
+                       <input type="radio" name="filterByDayOptions" id="filterByDay3" value="7">7d
                </label>
                <label class="radio-inline dayfilter" style="margin-top:5px">
-                 <input type="radio" name="filterByDayOptions" id="filterByDay4" value="14">14d
+                       <input type="radio" name="filterByDayOptions" id="filterByDay4" value="14">14d
                </label>
                <label class="radio-inline dayfilter" style="margin-top:5px">
-                 <input type="radio" name="filterByDayOptions" id="filterByDay5" value="all" checked>Tots
+                       <input type="radio" name="filterByDayOptions" id="filterByDay5" value="all" 
checked>Tots
                </label>
        </div>
        <div class="col-sm-6">
@@ -68,437 +68,437 @@
 <script src="{{ url_for('assets', filename='DataTables/extensions/Buttons/js/buttons.html5.min.js') 
}}"></script>
 <script>
 /*!
- * Results javascript functions for Chronojump Server
- * Author: Marcos Venteo <mventeo gmail com>
- * version: 1.0
- */
-
- function formatDateNumber(val) {
-        if (val < 10) {
-                return '0' + val;
-        } else {
-                return val;
-        }
- }
+* Results javascript functions for Chronojump Server
+* Author: Marcos Venteo <mventeo gmail com>
+* version: 1.0
+*/
+
+function formatDateNumber(val) {
+       if (val < 10) {
+               return '0' + val;
+       } else {
+               return val;
+       }
+}
 
 $(document).ready(function() {
 
-  var refreshIntervalId;
-
-  var COLUMN_PLAYER = 4;
-  var COLUMN_STATION = 5;
-  var COLUMN_EXERCISE = 6;
-
-  // Initialize datatable with results
-  $("input[name='filterByDayOptions']").on('click', function() {
-       var table = $('#results').DataTable();
-       table.draw();
-  });
-
-  $.fn.dataTable.ext.search.push(
-       function(settings, data, dataIndex) {
-         var filter = $("input[name='filterByDayOptions']:checked").val();
-         var date = Date.parse(data[1]); // use data for the age column
-         var d = new Date();
-         if (filter != "all") {
-               d.setDate(d.getDate() - filter - 1);
-               if (date >= d) {
-                 return true;
-               }
-               return false;
-         } else {
-               return true;
-         }
+       var refreshIntervalId;
+
+       var COLUMN_PLAYER = 4;
+       var COLUMN_STATION = 5;
+       var COLUMN_EXERCISE = 6;
+
+       // Initialize datatable with results
+       $("input[name='filterByDayOptions']").on('click', function() {
+               var table = $('#results').DataTable();
+               table.draw();
+       });
+
+       $.fn.dataTable.ext.search.push(
+               function(settings, data, dataIndex) {
+                       var filter = $("input[name='filterByDayOptions']:checked").val();
+                       var date = Date.parse(data[1]); // use data for the age column
+                       var d = new Date();
+                       if (filter != "all") {
+                               d.setDate(d.getDate() - filter - 1);
+                               if (date >= d) {
+                                       return true;
+                               }
+                               return false;
+                       } else {
+                               return true;
+                       }
 
 
                }
-  );
+       );
 
 
-  /* Create the table for results with Datatables */
-  var table = $('#results').DataTable({
+       /* Create the table for results with Datatables */
+       var table = $('#results').DataTable({
                "select": true,
-       "columns": [{
-               type: "num",
-               title: "id",
-               data: "id",
-               visible: false
-         },
-         {
-               type: "date",
-               data: "dt",
-               visible: false
-         },
-         {
-               type: "html",
-               orderable:false,
-               render: function(value, type, row) {
-                 return '<input class="deleteCheckbox" type="checkbox" data-result-id="' + row.id + '"/>';
-               }
-         },
-         {
-               type: "customdate",
-               title: "Data",
-               data: "dt",
-               render: function(value) {
-
-                 // Compare with today
-                 today = new Date();
-                 // To adjust the hour
-                 var _offsetHours = today.getTimezoneOffset()/60;
-                 var dd = today.getDate();
-                 var mm = today.getMonth();
-                 var yy = today.getFullYear();
-
-                 var dt = new Date(value);
-                 dt.setHours(dt.getHours() + _offsetHours);
-                 var dd2 = dt.getDate();
-                 var mm2 = dt.getMonth();
-                 var yy2 = dt.getFullYear();
-                 var hh = dt.getHours();
-                 var MM = dt.getMinutes();
-                 if (dd == dd2 && mm == mm2 && yy == yy2) {
-                       // Today, show the result hours and minute
-                       return formatDateNumber(hh) + ':' + formatDateNumber(MM);
-                 } else if (yy == yy2) {
-                       // Same year
-                       return dd2 + "/" + (mm2 + 1) + " " + formatDateNumber(hh) + ":" + 
formatDateNumber(MM);
-                 } else {
-                       return dd2 + "/" + (mm2 + 1) + "/" + yy2 + " " + formatDateNumber(hh) + ":" + 
formatDateNumber(MM);
-                 }
+               "columns": [{
+                       type: "num",
+                       title: "id",
+                       data: "id",
+                       visible: false
+               },
+               {
+                       type: "date",
+                       data: "dt",
+                       visible: false
+               },
+               {
+                       type: "html",
+                       orderable:false,
+                       render: function(value, type, row) {
+                               return '<input class="deleteCheckbox" type="checkbox" data-result-id="' + 
row.id + '"/>';
+                       }
+               },
+               {
+                       type: "customdate",
+                       title: "Data",
+                       data: "dt",
+                       render: function(value) {
+
+                               // Compare with today
+                               today = new Date();
+                               // To adjust the hour
+                               var _offsetHours = today.getTimezoneOffset()/60;
+                               var dd = today.getDate();
+                               var mm = today.getMonth();
+                               var yy = today.getFullYear();
+
+                               var dt = new Date(value);
+                               dt.setHours(dt.getHours() + _offsetHours);
+                               var dd2 = dt.getDate();
+                               var mm2 = dt.getMonth();
+                               var yy2 = dt.getFullYear();
+                               var hh = dt.getHours();
+                               var MM = dt.getMinutes();
+                               if (dd == dd2 && mm == mm2 && yy == yy2) {
+                                       // Today, show the result hours and minute
+                                       return formatDateNumber(hh) + ':' + formatDateNumber(MM);
+                               } else if (yy == yy2) {
+                                       // Same year
+                                       return formatDateNumber(dd2) + "/" +formatDateNumber(mm2 + 1) + " " + 
formatDateNumber(hh) + ":" + formatDateNumber(MM);
+                               } else {
+                                       return formatDateNumber(dd2) + "/" + formatDateNumber(mm2 + 1) + "/" 
+ yy2 + " " + formatDateNumber(hh) + ":" + formatDateNumber(MM);
+                               }
 
+                       }
+               },
+               {
+                       type: "html",
+                       data: "personName",
+                       title: "Jugador"
+               },
+               {
+                       type: "html",
+                       data: "stationName",
+                       title: "Estació"
+               },
+               {
+                       type: "html",
+                       data: "exerciseName",
+                       title: "Exercici"
+               },
+               {
+                       type: "html",
+                       data: "laterality",
+                       title: "RL"
+               },
+               {
+                       type: "num",
+                       title: "Càrrega",
+                       data: "resistance",
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       data: "repetitions",
+                       title: "n"
+               },
+               {
+                       type: "num",
+                       data: "lossBySpeed",
+                       title: "Pèrdua"
+               },
+               {
+                       type: "num",
+                       data: "numBySpeed",
+                       title: "rep",
+                       className: 'colResult'
+               },
+               {
+                       type: "num",
+                       data: "rangeBySpeed",
+                       title: "rang",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       title: "Vm",
+                       data: "vmeanBySpeed",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       title: "VM",
+                       data: "vmaxBySpeed",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       title: "Pm",
+                       data: "pmeanBySpeed",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       title: "PM",
+                       data: "pmaxBySpeed",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
                }
-         },
-         {
-               type: "html",
-               data: "personName",
-               title: "Jugador"
-         },
-         {
-               type: "html",
-               data: "stationName",
-               title: "Estació"
-         },
-         {
-               type: "html",
-               data: "exerciseName",
-               title: "Exercici"
-         },
-         {
-               type: "html",
-               data: "laterality",
-               title: "RL"
-         },
-         {
-               type: "num",
-               title: "Càrrega",
-               data: "resistance",
-               render: $.fn.dataTable.render.number('', ',', 2)
-         },
-         {
-               type: "num",
-               data: "repetitions",
-               title: "n"
-         },
-         {
-               type: "num",
-               data: "lossBySpeed",
-               title: "Pèrdua"
-         },
-         {
-               type: "num",
-               data: "numBySpeed",
-               title: "rep",
-               className: 'colResult'
-         },
-         {
-               type: "num",
-               data: "rangeBySpeed",
-               title: "rang",
-               className: 'colResult',
-               render: $.fn.dataTable.render.number('', ',', 2)
-         },
-         {
-               type: "num",
-               title: "Vm",
-               data: "vmeanBySpeed",
-               className: 'colResult',
-               render: $.fn.dataTable.render.number('', ',', 2)
-         },
-         {
-               type: "num",
-               title: "VM",
-               data: "vmaxBySpeed",
-               className: 'colResult',
-               render: $.fn.dataTable.render.number('', ',', 2)
-         },
-         {
-               type: "num",
-               title: "Pm",
-               data: "pmeanBySpeed",
-               className: 'colResult',
-               render: $.fn.dataTable.render.number('', ',', 2)
-         },
-         {
-               type: "num",
-               title: "PM",
-               data: "pmaxBySpeed",
-               className: 'colResult',
-               render: $.fn.dataTable.render.number('', ',', 2)
-         }
        ],
        "dom": "<'row'<'resultsFilter'>><'row'<'col-sm-6'B><'col-sm-6'f>>rtip",
        buttons: [
-                       { text: "Exportar resultats", className: "btn btn-primary",
-                               action: function( e, dt, node, config ) {
-                                       var columns = ["Data", "Jugador", "Estació", "Exercici",
-                                               "RL", "Carrega", "n", "Perdua", "Rep", "Rang", "Vm", "VM", 
"Pm", "PM"];
-
-                                       var csv = columns.join(";") + "\n";
-                                       var today = new Date();
-                                       var dd = today.getDate();
-                                       var mm = today.getMonth()+1;
-                                       var yyyy = today.getFullYear();
-                                       var hh = today.getHours();
-                                       var MM = today.getMinutes();
-
-                                       var filename = "resultats_" + yyyy + formatDateNumber(mm) + 
formatDateNumber(dd) + formatDateNumber(hh) + formatDateNumber(MM)   + ".csv";
-                                               var rows = $("#results").dataTable().$('tr', 
{"filter":"applied"});
-                                               rows.each(function( index ) {
-                                                 //console.log( index + ": " + table.row( this ).data() );
-                                                       var data = table.row(this).data();
-                                                       var date = new Date(data.dt);
-                                                       var _offsetHours = date.getTimezoneOffset()/60;
-                                                       var dateStr = formatDateNumber(date.getDate()) + "-" 
+ formatDateNumber(date.getMonth() + 1 ) + "-" +
-                                                               date.getFullYear() + " " + 
formatDateNumber(date.getHours() + _offsetHours) + ":"
-                                                               + formatDateNumber(date.getMinutes()) + ":00";
-                                                               csv += dateStr + ";"
-                                                                               + data.personName + ";"
-                                                                               + data.stationName +";"
-                                                                               + data.exerciseName + ";"
-                                                                               + data.laterality + ";"
-                                                                               + data.resistance + ";"
-                                                                               + data.repetitions + ";"
-                                                                               + data.lossBySpeed + ";"
-                                                                               + data.numBySpeed + ";"
-                                                                               + data.rangeBySpeed + ";"
-                                                                               + data.vmeanBySpeed + ";"
-                                                                               + data.vmaxBySpeed + ";"
-                                                                               + data.pmeanBySpeed + ";"
-                                                                               + data.pmaxBySpeed + "\n";
-                                                       //console.log(index + ": " +dateStr);
-                                               });
-                                               var csvData = 'data:text/csv;charset=utf-8,' + "\uFEFF" + 
encodeURI(csv);
-                                               // For IE (tested 10+)
-                                               //console.log(filename);
-                                               //console.log(csv);
-            if (window.navigator.msSaveOrOpenBlob) {
-                                                               var blob = new 
Blob([decodeURIComponent(encodeURI(csv))], {
-                    type: "text/csv;charset=utf-8;"
-                });
-                navigator.msSaveBlob(blob, filename);
-                                                               alert();
-            } else {
-                                                         var link=document.createElement('a');
-                /*$(link)
-                    .attr({
-                        'download': filename
-                        ,'href': csvData
-                        //,'target' : '_blank' //if you want it to open in a new window
-                });*/
-                                                               link.href= csvData;
-                                                               link.download=filename;
-                                                               
document.getElementById('hiddenContainer').appendChild(link);
-                                                               link.click();
-            }
-                                               return csv;
-            }},
-                       { text: 'Eliminar registres',
-                         className: "btn btn-danger btnDeleteResults",
-                         enabled: false,
-                         action: function(e, dt, node, config) {
-                               // Ask for confirmation
-                               var total =  $('.deleteCheckbox:checked').length;
-                               if (total == 1) {
-                                 var r = confirm("Estàs segur que vols esborrar aquest resultat?");
-                               } else {
-                                 var r = confirm("Estàs segur que vols esborrar aquests resultats?");
-                               }
-                               if (r == true) {
-                                 var results = [];
-                                 $.each($('.deleteCheckbox:checked'), function(index, value) {
-                                       var v = $(value);
-                                       console.log(index + ":" + v.attr('data-result-id'));
-                                       results.push(v.attr('data-result-id'));
-
-                                 });
-                                 var url = '/api/v1/results/delete';
-                                 $.ajax({
-                                       url: url,
-                                       type: "POST",
-                                       contentType: 'application/json;charset=UTF-8',
-                                       data: JSON.stringify(results)
-                                 }).done(function(msg){
-                                       // Results have been deleted. Refresh table and enable again the 
interval
-                                       //console.log(msg);
-                                       $('.btnDeleteResults').addClass('disabled');
-                                       table.ajax.reload(enableDeletion, false);
-                                       refreshIntervalId = refreshIntervalTrigger();
-                                       console.log("Interval refresh is enabled with id " + 
refreshIntervalId);
-                                 })
-                               }
-                         }}
-               ],
-       "pageLength": 15,
-       "order": [ 
-         [0, 'desc']
-       ],
-       "ajax": "/api/v1/results",
-       "processing": true,
-       "severSide": true,
-       "language": {
-         "lengthMenu": "Mostrant _MENU_ resultats per pàgina",
-         "zeroRecords": "No hi han resultats per mostrar",
-         "info": "Mostrant els resultats _START_ a _END_ d'un total de _TOTAL_",
-         "infoEmpty": "La busqueda no ha retornat resultats",
-         "infoFiltered": "(filtrat de _MAX_ resultats)",
-         "decimal": ",",
-         "thousands": ".",
-         "paginate": {
+               { text: "Exportar resultats", className: "btn btn-primary",
+               action: function( e, dt, node, config ) {
+                       var columns = ["Data", "Jugador", "Estació", "Exercici",
+                       "RL", "Carrega", "n", "Perdua", "Rep", "Rang", "Vm", "VM", "Pm", "PM"];
+
+                       var csv = columns.join(";") + "\n";
+                       var today = new Date();
+                       var dd = today.getDate();
+                       var mm = today.getMonth()+1;
+                       var yyyy = today.getFullYear();
+                       var hh = today.getHours();
+                       var MM = today.getMinutes();
+
+                       var filename = "resultats_" + yyyy + formatDateNumber(mm) + formatDateNumber(dd) + 
formatDateNumber(hh) + formatDateNumber(MM)   + ".csv";
+                       var rows = $("#results").dataTable().$('tr', {"filter":"applied"});
+                       rows.each(function( index ) {
+                               //console.log( index + ": " + table.row( this ).data() );
+                               var data = table.row(this).data();
+                               var date = new Date(data.dt);
+                               var _offsetHours = date.getTimezoneOffset()/60;
+                               var dateStr = formatDateNumber(date.getDate()) + "-" + 
formatDateNumber(date.getMonth() + 1 ) + "-" +
+                               date.getFullYear() + " " + formatDateNumber(date.getHours() + _offsetHours) + 
":"
+                               + formatDateNumber(date.getMinutes()) + ":00";
+                               csv += dateStr + ";"
+                               + data.personName + ";"
+                               + data.stationName +";"
+                               + data.exerciseName + ";"
+                               + data.laterality + ";"
+                               + data.resistance.toString().replace(".", ",") + ";"
+                               + data.repetitions + ";"
+                               + data.lossBySpeed.toString().replace(".", ",") + ";"
+                               + data.numBySpeed + ";"
+                               + data.rangeBySpeed.toString().replace(".", ",") + ";"
+                               + data.vmeanBySpeed.toString().replace(".", ",") + ";"
+                               + data.vmaxBySpeed.toString().replace(".", ",") + ";"
+                               + data.pmeanBySpeed.toString().replace(".", ",") + ";"
+                               + data.pmaxBySpeed.toString().replace(".", ",") + "\n";
+                               console.log(index + ": " + data.pmaxBySpeed.toFixed(4));
+                       });
+                       var csvData = 'data:text/csv;charset=utf-8,' + "\uFEFF" + encodeURI(csv);
+                       // For IE (tested 10+)
+                       //console.log(filename);
+                       //console.log(csv);
+                       if (window.navigator.msSaveOrOpenBlob) {
+                               var blob = new Blob([decodeURIComponent(encodeURI(csv))], {
+                                       type: "text/csv;charset=utf-8;"
+                               });
+                               navigator.msSaveBlob(blob, filename);
+                               alert();
+                       } else {
+                               var link=document.createElement('a');
+                               /*$(link)
+                               .attr({
+                               'download': filename
+                               ,'href': csvData
+                               //,'target' : '_blank' //if you want it to open in a new window
+                       });*/
+                       link.href= csvData;
+                       link.download=filename;
+                       document.getElementById('hiddenContainer').appendChild(link);
+                       link.click();
+               }
+               return csv;
+       }},
+       { text: 'Eliminar registres',
+       className: "btn btn-danger btnDeleteResults",
+       enabled: false,
+       action: function(e, dt, node, config) {
+               // Ask for confirmation
+               var total =  $('.deleteCheckbox:checked').length;
+               if (total == 1) {
+                       var r = confirm("Estàs segur que vols esborrar aquest resultat?");
+               } else {
+                       var r = confirm("Estàs segur que vols esborrar aquests resultats?");
+               }
+               if (r == true) {
+                       var results = [];
+                       $.each($('.deleteCheckbox:checked'), function(index, value) {
+                               var v = $(value);
+                               console.log(index + ":" + v.attr('data-result-id'));
+                               results.push(v.attr('data-result-id'));
+
+                       });
+                       var url = '/api/v1/results/delete';
+                       $.ajax({
+                               url: url,
+                               type: "POST",
+                               contentType: 'application/json;charset=UTF-8',
+                               data: JSON.stringify(results)
+                       }).done(function(msg){
+                               // Results have been deleted. Refresh table and enable again the interval
+                               //console.log(msg);
+                               $('.btnDeleteResults').addClass('disabled');
+                               table.ajax.reload(enableDeletion, false);
+                               refreshIntervalId = refreshIntervalTrigger();
+                               console.log("Interval refresh is enabled with id " + refreshIntervalId);
+                       })
+               }
+       }}
+],
+"pageLength": 15,
+"order": [ 
+       [1, 'desc']
+],
+"ajax": "/api/v1/results",
+"processing": true,
+"severSide": true,
+"language": {
+       "lengthMenu": "Mostrant _MENU_ resultats per pàgina",
+       "zeroRecords": "No hi han resultats per mostrar",
+       "info": "Mostrant els resultats _START_ a _END_ d'un total de _TOTAL_",
+       "infoEmpty": "La busqueda no ha retornat resultats",
+       "infoFiltered": "(filtrat de _MAX_ resultats)",
+       "decimal": ",",
+       "thousands": ".",
+       "paginate": {
                "first": '<i class="fa fa-fast-backward"></i>',
                "last": '<i class="fa fa-fast-forward"></i>',
                "next": '<i class="fa fa-forward"></i>',
                "previous": '<i class="fa fa-backward"></i>'
-         },
-         "search": "Cerca:"
        },
-       initComplete: function() {
-         /*
-                 The following functions are to create the filters for results view,
-                 by player, exercice and station.
-         */
-         this.api().columns().every(function() {
+       "search": "Cerca:"
+},
+initComplete: function() {
+       /*
+       The following functions are to create the filters for results view,
+       by player, exercice and station.
+       */
+       this.api().columns().every(function() {
 
                var column = this;
                var idx = column.index();
                if (idx == COLUMN_PLAYER) {
-                 var select = $('<select class="form-control"><option value="">Tots els 
jugadors</option></select>')
+                       var select = $('<select class="form-control"><option value="">Tots els 
jugadors</option></select>')
                        .appendTo($('#filterByPlayer'))
                        .on('change', function() {
-                         // Player selected
-                         var val = $.fn.dataTable.util.escapeRegex(
-                               $(this).val()
-                         );
+                               // Player selected
+                               var val = $.fn.dataTable.util.escapeRegex(
+                                       $(this).val()
+                               );
 
-                         column
+                               column
                                .search(val ? '^' + val + '$' : '', true, false)
                                .draw();
-                         // Hide column if is a selected Player
-                         //console.log(val);
-                         column.visible(val == '');
+                               // Hide column if is a selected Player
+                               //console.log(val);
+                               column.visible(val == '');
 
                        });
 
-                 column.data().unique().sort().each(function(d, j) {
-                       select.append('<option value="' + d + '">' + d + '</option>')
-                 });
+                       column.data().unique().sort().each(function(d, j) {
+                               select.append('<option value="' + d + '">' + d + '</option>')
+                       });
                } else if (idx == COLUMN_STATION) {
-                 var select = $('<select class="form-control"><option value="">Totes les 
estacions</option></select>')
+                       var select = $('<select class="form-control"><option value="">Totes les 
estacions</option></select>')
                        .appendTo($('#filterByStation'))
                        .on('change', function() {
-                         var val = $.fn.dataTable.util.escapeRegex(
-                               $(this).val()
-                         );
+                               var val = $.fn.dataTable.util.escapeRegex(
+                                       $(this).val()
+                               );
 
-                         column
+                               column
                                .search(val ? '^' + val + '$' : '', true, false)
                                .draw();
-                         column.visible(val == '');
+                               column.visible(val == '');
 
                        });
 
-                 column.data().unique().sort().each(function(d, j) {
-                       select.append('<option value="' + d + '">' + d + '</option>')
-                 });
+                       column.data().unique().sort().each(function(d, j) {
+                               select.append('<option value="' + d + '">' + d + '</option>')
+                       });
                } else if (idx == COLUMN_EXERCISE) {
-                 var select = $('<select class="form-control"><option value="">Tots els 
exercicis</option></select>')
+                       var select = $('<select class="form-control"><option value="">Tots els 
exercicis</option></select>')
                        .appendTo($('#filterByExercice'))
                        .on('change', function() {
-                         var val = $.fn.dataTable.util.escapeRegex(
-                               $(this).val()
-                         );
+                               var val = $.fn.dataTable.util.escapeRegex(
+                                       $(this).val()
+                               );
 
-                         column
+                               column
                                .search(val ? '^' + val + '$' : '', true, false)
                                .draw();
-                         column.visible(val == '');
+                               column.visible(val == '');
 
                        });
 
-                 column.data().unique().sort().each(function(d, j) {
-                       select.append('<option value="' + d + '">' + d + '</option>')
+                       column.data().unique().sort().each(function(d, j) {
+                               select.append('<option value="' + d + '">' + d + '</option>')
 
-                 });
+                       });
 
                }
-         });
-               console.log("Enable delection for first time");
-               enableDeletion();
-       }
-  });
+       });
+       console.log("Enable delection for first time");
+       enableDeletion();
+}
+});
 
-       $('#results').on( 'draw.dt', function () {
-    console.log( 'Table redrawn' );
-               deselectAllCheckboxes();
+$('#results').on( 'draw.dt', function () {
+       console.log( 'Table redrawn' );
+       deselectAllCheckboxes();
 
 } );
 
-  /* Enable the result deletion */
-  function enableDeletion() {
-         // Called every time a delete checkbox is changed
-               //alert();
-               console.log("enableDeletion called");
-               $('.deleteCheckbox').on('change', function() {
-                 var totalChecked = $('.deleteCheckbox:checked').length;
-                 console.log(totalChecked);
-                 if (totalChecked > 0) {
-                               // 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);
-                 }
-         });
-  }
-
-       function deselectAllCheckboxes() {
-               //$('.deleteCheckbox').attr("checked", false);
-               $('.deleteCheckbox').prop("checked", false);
-               $('.btnDeleteResults').addClass('disabled');
-               if (refreshIntervalId == -1) {
+/* Enable the result deletion */
+function enableDeletion() {
+       // Called every time a delete checkbox is changed
+       //alert();
+       console.log("enableDeletion called");
+       $('.deleteCheckbox').on('change', function() {
+               var totalChecked = $('.deleteCheckbox:checked').length;
+               console.log(totalChecked);
+               if (totalChecked > 0) {
+                       // 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);
                }
+       });
+}
+
+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);
-        };
+function refreshIntervalTrigger() {
+       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);
+refreshIntervalId = refreshIntervalTrigger();
+console.log("Interval refresh is enabled with id " + refreshIntervalId);
 });
 </script>
 
diff --git a/chronojumpserver/templates/sprints.html b/chronojumpserver/templates/sprints.html
index cbf7e9e..bbfa603 100755
--- a/chronojumpserver/templates/sprints.html
+++ b/chronojumpserver/templates/sprints.html
@@ -14,19 +14,19 @@
 <div id="resultsFilter" class="row">
        <div class="col-sm-8">
                <label class="radio-inline dayfilter" style="margin-top:5px">
-                 <input type="radio" name="filterByDayOptions" id="filterByDay1" value="1" >1d
+                       <input type="radio" name="filterByDayOptions" id="filterByDay1" value="1" >1d
                </label>
                <label class="radio-inline dayfilter" style="margin-top:5px">
-                 <input type="radio" name="filterByDayOptions" id="filterByDay2" value="3">3d
+                       <input type="radio" name="filterByDayOptions" id="filterByDay2" value="3">3d
                </label>
                <label class="radio-inline dayfilter" style="margin-top:5px">
-                 <input type="radio" name="filterByDayOptions" id="filterByDay3" value="7">7d
+                       <input type="radio" name="filterByDayOptions" id="filterByDay3" value="7">7d
                </label>
                <label class="radio-inline dayfilter" style="margin-top:5px">
-                 <input type="radio" name="filterByDayOptions" id="filterByDay4" value="14">14d
+                       <input type="radio" name="filterByDayOptions" id="filterByDay4" value="14">14d
                </label>
                <label class="radio-inline dayfilter" style="margin-top:5px">
-                 <input type="radio" name="filterByDayOptions" id="filterByDay5" value="all" checked>Tots
+                       <input type="radio" name="filterByDayOptions" id="filterByDay5" value="all" 
checked>Tots
                </label>
        </div>
        <div class="col-sm-4">
@@ -38,6 +38,7 @@
 <div class="row" style="margin-top:20px">
        <table id="sprints" class="table table-hovered" cellspacing="0" width="100%">
        </table>
+       <div id="hiddenContainer" style="display:none"/>
 </div>
 
 
@@ -52,264 +53,386 @@
 <script src="{{ url_for('assets', filename='DataTables/extensions/Buttons/js/buttons.html5.min.js') 
}}"></script>
 <script>
 /*!
- * ResultSprints javascript functions for Chronojump Server
- * Author: Marcos Venteo <mventeo gmail com>
- * version: 1.0
- */
+* ResultSprints javascript functions for Chronojump Server
+* Author: Marcos Venteo <mventeo gmail com>
+* version: 1.0
+*/
 
 function formatDateNumber(val) {
-    if (val < 10) {
-        return '0' + val;
-    } else {
-        return val;
-    }
+       if (val < 10) {
+               return '0' + val;
+       } else {
+               return val;
+       }
 }
 
 $(document).ready(function() {
 
-  // Initialize datatable with results
-  $("input[name='filterByDayOptions']").on('click', function() {
-    var table = $('#results').DataTable();
-    table.draw();
-  });
-
-  $.fn.dataTable.ext.search.push(
-    function(settings, data, dataIndex) {
-      var filter = $("input[name='filterByDayOptions']:checked").val();
-      var date = Date.parse(data[1]); // use data for the age column
-      var d = new Date();
-      if (filter != "all") {
-        d.setDate(d.getDate() - filter - 1);
-        if (date >= d) {
-          return true;
-        }
-        return false;
-      } else {
-        return true;
-      }
-
-
-    }
-  );
-
-  var table = $('#sprints').DataTable({
-    "columns": [{
-        type: "num",
-        title: "id",
-        data: "id",
-        visible: false
-      },
-      {
-        type: "date",
-        data: "dt",
-        visible: false
-      },
-      {
-        type: "customdate",
-        title: "Data",
-        data: "dt",
-        render: function(value) {
-          // Compare with today
-          today = new Date();
-          // To adjust the hour
-          var _offsetHours = today.getTimezoneOffset()/60;
-          var dd = today.getDate();
-          var mm = today.getMonth();
-          var yy = today.getFullYear();
-
-          var dt = new Date(value);
-          dt.setHours(dt.getHours() + _offsetHours);
-          var dd2 = dt.getDate();
-          var mm2 = dt.getMonth();
-          var yy2 = dt.getFullYear();
-          var hh = dt.getHours();
-          var MM = dt.getMinutes();
-          if (dd == dd2 && mm == mm2 && yy == yy2) {
-            // Today, show the result hours and minute
-            return formatDateNumber(hh) + ':' + formatDateNumber(MM);
-          } else if (yy == yy2) {
-            // Same year
-            return dd2 + "/" + (mm2 + 1) + " " + formatDateNumber(hh) + ":" + formatDateNumber(MM);
-          } else {
-            return dd2 + "/" + (mm2 + 1) + "/" + yy2 + " " + formatDateNumber(hh) + ":" + 
formatDateNumber(MM);
-          }
-
-        }
-      },
-      {
-        type: "html",
-        data: "personName",
-        title: "Jugador"
-      },
-      {
-        type: "html",
-        title: "Distancia",
-        data: "distances"
-      },
-      {
-        type: "num",
-        title: "t1",
-        data: "t1",
-        className: 'colResult',
-        render: $.fn.dataTable.render.number('', ',', 2)
-      },
-      {
-        type: "num",
-        title: "t2",
-        data: "t2",
-        className: 'colResult',
-        render: $.fn.dataTable.render.number('', ',', 2)
-      },
-      {
-        type: "num",
-        title: "t3",
-        data: "t3",
-        className: 'colResult',
-        render: $.fn.dataTable.render.number('', ',', 2)
-      },
-      {
-        type: "num",
-        title: "t4",
-        data: "t4",
-        className: 'colResult',
-        render: $.fn.dataTable.render.number('', ',', 2)
-      },
-      {
-        type: "num",
-        data: "k",
-        title: "k",
-        className: 'colResult',
-        render: $.fn.dataTable.render.number('', ',', 2)
-      },
-      {
-        type: "num",
-        title: "VMax",
-        data: "vmax",
-        className: 'colResult',
-        render: $.fn.dataTable.render.number('', ',', 2)
-      },
-      {
-        type: "num",
-        title: "AMax",
-        data: "amax",
-        className: 'colResult',
-        render: $.fn.dataTable.render.number('', ',', 2)
-      },
-      {
-        type: "num",
-        title: "FMax",
-        data: "fmax",
-        className: 'colResult',
-        render: $.fn.dataTable.render.number('', ',', 2)
-      },
-      {
-        type: "num",
-        title: "PMax",
-        data: "pmax",
-        className: 'colResult',
-        render: $.fn.dataTable.render.number('', ',', 2)
-      }
-    ],
-    "dom": "<'row'<'resultsFilter'>><'row'<'col-sm-6'B><'col-sm-6'f>>rtip",
-    buttons: [
-            { extend: 'csv', text: 'Exportar Sprints', className: "btn btn-primary", fieldSeparator: ";"}
-        ],
-    "pageLength": 15,
-    "order": [ 
-      [0, 'desc']
-    ],
-    "ajax": "/api/v1/sprints",
-    "processing": true,
-    "severSide": true,
-    "language": {
-      "lengthMenu": "Mostrant _MENU_ resultats per pàgina",
-      "zeroRecords": "No hi han resultats per mostrar",
-      "info": "Mostrant els resultats _START_ a _END_ d'un total de _TOTAL_",
-      "infoEmpty": "La busqueda no ha retornat resultats",
-      "infoFiltered": "(filtrat de _MAX_ resultats)",
-      "decimal": ",",
-      "thousands": ".",
-      "paginate": {
-        "first": '<i class="fa fa-fast-backward"></i>',
-        "last": '<i class="fa fa-fast-forward"></i>',
-        "next": '<i class="fa fa-forward"></i>',
-        "previous": '<i class="fa fa-backward"></i>'
-      },
-      "search": "Cerca:"
-    },
-    initComplete: function() {
-      /*
-          The following functions are to create the filters for results view,
-          by player, exercice and station.
-      */
-      this.api().columns().every(function() {
-
-        var column = this;
-        var idx = column.index();
-        if (idx == 3) {
-          var select = $('<select class="form-control"><option value="">Tots els jugadors</option></select>')
-            .appendTo($('#filterByPlayer'))
-            .on('change', function() {
-              // Player selected
-              var val = $.fn.dataTable.util.escapeRegex(
-                $(this).val()
-              );
-
-              column
-                .search(val ? '^' + val + '$' : '', true, false)
-                .draw();
-              // Hide column if is a selected Player
-              //console.log(val);
-              column.visible(val == '');
-            });
-
-          column.data().unique().sort().each(function(d, j) {
-            select.append('<option value="' + d + '">' + d + '</option>')
-          });
-        } else if (idx == 4) {
-          var select = $('<select class="form-control"><option value="">Totes les 
estacions</option></select>')
-            .appendTo($('#filterByStation'))
-            .on('change', function() {
-              var val = $.fn.dataTable.util.escapeRegex(
-                $(this).val()
-              );
-
-              column
-                .search(val ? '^' + val + '$' : '', true, false)
-                .draw();
-              column.visible(val == '');
-            });
-
-          column.data().unique().sort().each(function(d, j) {
-            select.append('<option value="' + d + '">' + d + '</option>')
-          });
-        } else if (idx == 5) {
-          var select = $('<select class="form-control"><option value="">Tots els 
exercicis</option></select>')
-            .appendTo($('#filterByExercice'))
-            .on('change', function() {
-              var val = $.fn.dataTable.util.escapeRegex(
-                $(this).val()
-              );
-
-              column
-                .search(val ? '^' + val + '$' : '', true, false)
-                .draw();
-              column.visible(val == '');
-            });
-
-          column.data().unique().sort().each(function(d, j) {
-            select.append('<option value="' + d + '">' + d + '</option>')
-          });
-        }
-      });
-    }
-  });
-
-
-  setInterval(function() {
-    /* Set the interval for refresh */
-    table.ajax.reload(null, false);
-  }, 15000);
+       var refreshIntervalId;
+
+       var COLUMN_PLAYER = 4;
+
+       // Initialize datatable with results
+       $("input[name='filterByDayOptions']").on('click', function() {
+               var table = $('#results').DataTable();
+               table.draw();
+       });
+
+       $.fn.dataTable.ext.search.push(
+               function(settings, data, dataIndex) {
+                       var filter = $("input[name='filterByDayOptions']:checked").val();
+                       var date = Date.parse(data[1]); // use data for the age column
+                       var d = new Date();
+                       if (filter != "all") {
+                               d.setDate(d.getDate() - filter - 1);
+                               if (date >= d) {
+                                       return true;
+                               }
+                               return false;
+                       } else {
+                               return true;
+                       }
+
+
+               }
+       );
+
+       var table = $('#sprints').DataTable({
+               "columns": [{
+                       type: "num",
+                       title: "id",
+                       data: "id",
+                       visible: false
+               },
+               {
+                       type: "date",
+                       data: "dt",
+                       visible: false
+               },
+               {
+                       type: "html",
+                       orderable:false,
+                       render: function(value, type, row) {
+                               return '<input class="deleteCheckbox" type="checkbox" data-result-id="' + 
row.id + '"/>';
+                       }
+               },
+               {
+                       type: "customdate",
+                       title: "Data",
+                       data: "dt",
+                       render: function(value) {
+                               // Compare with today
+                               today = new Date();
+                               // To adjust the hour
+                               var _offsetHours = today.getTimezoneOffset()/60;
+                               var dd = today.getDate();
+                               var mm = today.getMonth();
+                               var yy = today.getFullYear();
+
+                               var dt = new Date(value);
+                               dt.setHours(dt.getHours() + _offsetHours);
+                               var dd2 = dt.getDate();
+                               var mm2 = dt.getMonth();
+                               var yy2 = dt.getFullYear();
+                               var hh = dt.getHours();
+                               var MM = dt.getMinutes();
+                               if (dd == dd2 && mm == mm2 && yy == yy2) {
+                                       // Today, show the result hours and minute
+                                       return formatDateNumber(hh) + ':' + formatDateNumber(MM);
+                               } else if (yy == yy2) {
+                                       // Same year
+                                       return formatDateNumber(dd2) + "/" + formatDateNumber(mm2 + 1) + " " 
+ formatDateNumber(hh) + ":" + formatDateNumber(MM);
+                               } else {
+                                       return formatDateNumber(dd2) + "/" + formatDateNumber(mm2 + 1) + "/" 
+ yy2 + " " + formatDateNumber(hh) + ":" + formatDateNumber(MM);
+                               }
+
+                       }
+               },
+               {
+                       type: "html",
+                       data: "personName",
+                       title: "Jugador"
+               },
+               {
+                       type: "html",
+                       title: "Distancia",
+                       data: "distances"
+               },
+               {
+                       type: "num",
+                       title: "t1",
+                       data: "t1",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       title: "t2",
+                       data: "t2",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       title: "t3",
+                       data: "t3",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       title: "t4",
+                       data: "t4",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       data: "k",
+                       title: "k",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       title: "VMax",
+                       data: "vmax",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       title: "AMax",
+                       data: "amax",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       title: "FMax",
+                       data: "fmax",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               },
+               {
+                       type: "num",
+                       title: "PMax",
+                       data: "pmax",
+                       className: 'colResult',
+                       render: $.fn.dataTable.render.number('', ',', 2)
+               }
+       ],
+       "dom": "<'row'<'resultsFilter'>><'row'<'col-sm-6'B><'col-sm-6'f>>rtip",
+       buttons: [
+               { text: "Exportar resultats", className: "btn btn-primary",
+               action: function( e, dt, node, config ) {
+                       var columns = ["Data", "Jugador", "Distancia", "t1",
+                       "t2", "t3", "t4", "k", "VMax", "AMax", "FMax", "PMax"];
+
+                       var csv = columns.join(";") + "\n";
+                       var today = new Date();
+                       var dd = today.getDate();
+                       var mm = today.getMonth()+1;
+                       var yyyy = today.getFullYear();
+                       var hh = today.getHours();
+                       var MM = today.getMinutes();
+
+                       var filename = "curses_" + yyyy + formatDateNumber(mm) + formatDateNumber(dd) + 
formatDateNumber(hh) + formatDateNumber(MM)   + ".csv";
+                       var rows = $("#sprints").dataTable().$('tr', {"filter":"applied"});
+                       rows.each(function( index ) {
+                               //console.log( index + ": " + table.row( this ).data() );
+                               var data = table.row(this).data();
+                               var date = new Date(data.dt);
+                               var _offsetHours = date.getTimezoneOffset()/60;
+                               var dateStr = formatDateNumber(date.getDate()) + "-" + 
formatDateNumber(date.getMonth() + 1 ) + "-" +
+                               date.getFullYear() + " " + formatDateNumber(date.getHours() + _offsetHours) + 
":"
+                               + formatDateNumber(date.getMinutes()) + ":00";
+                               csv += dateStr + ";"
+                               + data.personName + ";"
+                               + data.distancia +";"
+                               + data.t1.toString().replace(".", ",") + ";"
+                               + data.t2.toString().replace(".", ",") + ";"
+                               + data.t3.toString().replace(".", ",") + ";"
+                               + data.t4.toString().replace(".", ",") + ";"
+                               + data.k.toString().replace(".", ",") + ";"
+                               + data.vmax.toString().replace(".", ",") + ";"
+                               + data.amax.toString().replace(".", ",") + ";"
+                               + data.fmax.toString().replace(".", ",") + ";"
+                               + data.pmax.toString().replace(".", ",") + "\n";
+                               
+                       });
+                       var csvData = 'data:text/csv;charset=utf-8,' + "\uFEFF" + encodeURI(csv);
+                       // For IE (tested 10+)
+                       //console.log(filename);
+                       //console.log(csv);
+                       if (window.navigator.msSaveOrOpenBlob) {
+                               var blob = new Blob([decodeURIComponent(encodeURI(csv))], {
+                                       type: "text/csv;charset=utf-8;"
+                               });
+                               navigator.msSaveBlob(blob, filename);
+                               alert();
+                       } else {
+                               var link=document.createElement('a');
+                               /*$(link)
+                               .attr({
+                               'download': filename
+                               ,'href': csvData
+                               //,'target' : '_blank' //if you want it to open in a new window
+                       });*/
+                       link.href= csvData;
+                       link.download=filename;
+                       document.getElementById('hiddenContainer').appendChild(link);
+                       link.click();
+               }
+               return csv;
+       }},
+       { text: 'Eliminar registres',
+       className: "btn btn-danger btnDeleteResults",
+       enabled: false,
+       action: function(e, dt, node, config) {
+               // Ask for confirmation
+               var total =  $('.deleteCheckbox:checked').length;
+               if (total == 1) {
+                       var r = confirm("Estàs segur que vols esborrar aquesta cursa?");
+               } else {
+                       var r = confirm("Estàs segur que vols esborrar aquestes curses?");
+               }
+               if (r == true) {
+                       var results = [];
+                       $.each($('.deleteCheckbox:checked'), function(index, value) {
+                               var v = $(value);
+                               console.log(index + ":" + v.attr('data-result-id'));
+                               results.push(v.attr('data-result-id'));
+
+                       });
+                       var url = '/api/v1/sprints/delete';
+                       $.ajax({
+                               url: url,
+                               type: "POST",
+                               contentType: 'application/json;charset=UTF-8',
+                               data: JSON.stringify(results)
+                       }).done(function(msg){
+                               // Results have been deleted. Refresh table and enable again the interval
+                               //console.log(msg);
+                               $('.btnDeleteResults').addClass('disabled');
+                               table.ajax.reload(enableDeletion, false);
+                               refreshIntervalId = refreshIntervalTrigger();
+                               console.log("Interval refresh is enabled with id " + refreshIntervalId);
+                       })
+               }
+       }}
+],
+"pageLength": 15,
+"order": [ 
+       [1, 'desc']
+],
+"ajax": "/api/v1/sprints",
+"processing": true,
+"severSide": true,
+"language": {
+       "lengthMenu": "Mostrant _MENU_ resultats per pàgina",
+       "zeroRecords": "No hi han resultats per mostrar",
+       "info": "Mostrant els resultats _START_ a _END_ d'un total de _TOTAL_",
+       "infoEmpty": "La busqueda no ha retornat resultats",
+       "infoFiltered": "(filtrat de _MAX_ resultats)",
+       "decimal": ",",
+       "thousands": ".",
+       "paginate": {
+               "first": '<i class="fa fa-fast-backward"></i>',
+               "last": '<i class="fa fa-fast-forward"></i>',
+               "next": '<i class="fa fa-forward"></i>',
+               "previous": '<i class="fa fa-backward"></i>'
+       },
+       "search": "Cerca:"
+},
+initComplete: function() {
+       /*
+       The following functions are to create the filters for results view,
+       by player, exercice and station.
+       */
+       this.api().columns().every(function() {
+
+               var column = this;
+               var idx = column.index();
+               if (idx == COLUMN_PLAYER) {
+                       var select = $('<select class="form-control"><option value="">Tots els 
jugadors</option></select>')
+                       .appendTo($('#filterByPlayer'))
+                       .on('change', function() {
+                               // Player selected
+                               var val = $.fn.dataTable.util.escapeRegex(
+                                       $(this).val()
+                               );
+
+                               column
+                               .search(val ? '^' + val + '$' : '', true, false)
+                               .draw();
+                               // Hide column if is a selected Player
+                               //console.log(val);
+                               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();
+}
+});
+
+$('#sprints').on( 'draw.dt', function () {
+       console.log( 'Table sprints redrawn' );
+       deselectAllCheckboxes();
+
+} );
+
+/* Enable the result deletion */
+function enableDeletion() {
+       // Called every time a delete checkbox is changed
+       //alert();
+       console.log("enableDeletion called");
+       $('.deleteCheckbox').on('change', function() {
+               var totalChecked = $('.deleteCheckbox:checked').length;
+               console.log(totalChecked);
+               if (totalChecked > 0) {
+                       // 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);
+               }
+       });
+}
+
+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);
+};
+
+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]