121 lines
2.7 KiB
JavaScript
Executable File
121 lines
2.7 KiB
JavaScript
Executable File
$(function(){
|
|
|
|
var that = this;
|
|
that.current_tracking_category = null;
|
|
|
|
that.displayError = function(error){
|
|
$("#content").prepend('<div class="error error_antadismarketing">'+error+'</div>');
|
|
setTimeout(function(){
|
|
$('.error_antadismarketing').remove();
|
|
}, 5000);
|
|
}
|
|
|
|
that.runCheckbox = function(elem){
|
|
var class_fields = $(elem).attr('id');
|
|
if($(elem).is(':checked')) {
|
|
$('.'+class_fields).show();
|
|
}
|
|
else {
|
|
$('.'+class_fields).hide();
|
|
}
|
|
}
|
|
|
|
that.loadStats = function(id_tracking_category){
|
|
|
|
if(typeof(id_tracking_category) == 'undefined') {
|
|
if(that.current_tracking_category !== null)
|
|
var id_tracking_category = that.current_tracking_category;
|
|
else return;
|
|
}
|
|
|
|
that.current_tracking_category = id_tracking_category;
|
|
var property = {
|
|
'ajax': 1,
|
|
'id_tracking_category': id_tracking_category,
|
|
'token': token_tracking,
|
|
'action': 'getList',
|
|
'date_from' : $('#date_from').val(),
|
|
'date_to' : $('#date_to').val(),
|
|
'check_by_date' : $('#check_by_date').is(':checked') ? 1 : 0
|
|
};
|
|
var type = 'tracking';
|
|
var ordered = $('.ordered[data-ordered-identifier='+type+'][data-direction]');
|
|
|
|
if(ordered.size() > 0) {
|
|
property.orderby = ordered.data('direction');
|
|
property.order = ordered.data('ordered');
|
|
}
|
|
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: currentIndex,
|
|
dataType : "json",
|
|
data : property,
|
|
success: function(data) {
|
|
if(data.hasError) {
|
|
that.displayError(data.error);
|
|
}
|
|
else {
|
|
$('#tracking_content').html(data);
|
|
}
|
|
|
|
},
|
|
error: function() {
|
|
that.displayError('An error occured in PHP');
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
that.init = function(){
|
|
$('body').on('click', '.load_stats', function(){
|
|
that.loadStats( $(this).attr('data-id-tracking-category') );
|
|
});
|
|
|
|
$('#tracking_date .load_stats').trigger('click');
|
|
|
|
$('#check_by_date').on('click', function(){
|
|
that.runCheckbox($(this));
|
|
});
|
|
that.runCheckbox($('#check_by_date'));
|
|
|
|
that.initSaleOrdered();
|
|
}
|
|
|
|
that.initSaleOrdered = function() {
|
|
|
|
$('body').on('click', '.ordered', function(){
|
|
|
|
var filter = $(this).attr('data-ordered');
|
|
var identifier = $(this).attr('data-ordered-identifier');
|
|
|
|
if(filter != '') {
|
|
var filter_direction = $(this).attr('data-direction');
|
|
$('.ordered[data-ordered-identifier='+identifier+']').removeAttr('data-direction');
|
|
|
|
switch(filter_direction){
|
|
case undefined:
|
|
$(this).attr('data-direction', 'ASC');
|
|
break;
|
|
case 'DESC':
|
|
$(this).removeAttr('data-direction');
|
|
break;
|
|
case 'ASC':
|
|
$(this).attr('data-direction', 'DESC');
|
|
break;
|
|
}
|
|
|
|
that.loadStats();
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
$(document).ready(function(){
|
|
that.init();
|
|
|
|
$('.datepicker').datepicker();
|
|
});
|
|
|
|
|
|
}); |