Skip to content

Commit

Permalink
Fix filters error
Browse files Browse the repository at this point in the history
  • Loading branch information
reyiyo committed Jan 29, 2013
1 parent a3f5537 commit 68639bd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 31 deletions.
29 changes: 26 additions & 3 deletions app/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@ function Controller() {
this.base_path = 'output/datatables/'
};

Controller.prototype.get_values = function(date, report, freq) {
Controller.prototype.getValues = function(date, report, freq) {
return $.ajax( {
"dataType": 'json',
"type": "GET",
"url": this.getPath(date, report, freq),
"statusCode": {
404: view.handleAjaxError
}
});
};

Controller.prototype.getPath = function(date, report, freq) {
var path = this.base_path;

if (freq == 'Semanales') {
path += 'weekly/';
path += this.getSunday(date) + '/';
path += report.filename;
return path;
} else if (freq == 'Mensuales') {
path += 'monthly/';
}
Expand All @@ -15,7 +29,16 @@ Controller.prototype.get_values = function(date, report, freq) {
}

path += report.filename;

return path;
//return $.getJSON(path)
}

Controller.prototype.getSunday = function(d) {
d = new Date(d);
var day = d.getDay(),
diff = d.getDate() - day + (day == 0 ? -6:0); // adjust when day is sunday
var fecha = new Date(d.setDate(diff));
var dia = fecha.getDate();
var m = fecha.getMonth()+1;
var y = fecha.getFullYear();
return '' + y +'/'+ (m<=9?'0'+m:m) +'/'+ (dia<=9?'0'+dia:dia);
};
26 changes: 9 additions & 17 deletions app/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ function View() {
Report.NoCategorizados(),
];
this.reports = reports;
this.selectedFreq = 'Estadísticas Globales';
var reportNames = $.map(reports, function(elem, i) {
return elem.name;
});
this.reportNames = reportNames;
this.selectedReport = reports[reportNames.indexOf('Globales')];
this.controller = new Controller();
}

Expand Down Expand Up @@ -60,34 +58,28 @@ View.prototype = {
},

loadValues: function(date) {
this.restartTable();
$('.alert').hide();
var path = this.controller.get_values(date, this.selectedReport, this.selectedFreq);
var jqxhr = this.controller.getValues(date, this.selectedReport, this.selectedFreq);
jqxhr.done(function(data) { view.createDataTable(data.aaData) });
jqxhr.fail(view.handleAjaxError);
},

createDataTable: function(aaData) {
$('#data-table').dataTable({
"bDestroy": true,
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"sAjaxSource": path,
"aaData": aaData,
"aoColumns": this.selectedReport.colsInfo,
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
},
"aaSorting": this.selectedReport.sortInfo,
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "GET",
"url": sSource,
"success": fnCallback,
"error": view.handleAjaxError,
"statusCode": {
404: view.handleAjaxError
}
} );
}
}).columnFilter({aoColumns:this.selectedReport.filterInfo});
},

handleAjaxError: function ( xhr, textStatus, error ) {
view.restartTable();
$('#alert').fadeIn();
},

Expand Down
11 changes: 5 additions & 6 deletions datatables/extras/jquery.dataTables.columnFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@
}

function _fnColumnIndex(iColumnIndex) {
if (properties.bUseColVis)
return iColumnIndex;
else
return oTable.fnSettings().oApi._fnVisibleToColumnIndex(oTable.fnSettings(), iColumnIndex);
//return iColumnIndex;
//return oTable.fnSettings().oApi._fnColumnIndexToVisible(oTable.fnSettings(), iColumnIndex);
return iColumnIndex;
//if (properties.bUseColVis)
// return iColumnIndex;
//else
//return oTable.fnSettings().oApi._fnVisibleToColumnIndex(oTable.fnSettings(), iColumnIndex);
}

function fnCreateInput(oTable, regex, smart, bIsNumber, iFilterLength, iMaxLenght) {
Expand Down
15 changes: 10 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
width: 25px
}
</style>

<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
Expand Down Expand Up @@ -98,16 +98,18 @@
<!-- Javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/jquery.js"></script>

<script src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="app/controller.js"></script>
<script src="app/view.js"></script>
<script src="app/reports.js"></script>
<script src="datatables/js/jquery.dataTables.js"></script>
<script src="datatables/js/DT_bootstrap_paging.js"></script>
<script src="datatables/extras/jquery.dataTables.columnFilter.js"></script>

<script src="app/controller.js"></script>
<script src="app/reports.js"></script>
<script src="app/view.js"></script>

<script>
var view = new View();
$(function(){
Expand All @@ -127,11 +129,14 @@
view.loadValues($('#date-input').data('date'));
});

view.selectReport('Globales', 'Globales');

/* Hide alert */
$('.close').click(function(){
$(this).parent().hide();
});
});
</script>

</body>
</html>

0 comments on commit 68639bd

Please sign in to comment.