From 26c7acbeaa57ff8ccf972bcc8dbb58d40dda8f11 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Thu, 31 Oct 2013 11:59:25 +0100 Subject: [PATCH] admoin home stats navigation --- templates/admin/default/home.html | 44 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/templates/admin/default/home.html b/templates/admin/default/home.html index 105c640c5..c1fbfa7c6 100755 --- a/templates/admin/default/home.html +++ b/templates/admin/default/home.html @@ -13,9 +13,9 @@
{intl l='Dashboard'}
- + - +
@@ -264,6 +264,8 @@ jQuery(function($){ + var jQplotDate = new Date(); + jQplotDate.setDate(1); // Set day to 1 so we can add month without 30/31 days of month troubles. var url = "{url path='/admin/home/stats'}"; var jQplotData; // json data var jQPlotInstance; // global instance @@ -306,13 +308,10 @@ jQuery(function($){ } }; + {literal} + // Get initial data Json - $.getJSON(url) - .done(function(data) { - jQplotData = data; - jsonSuccessLoad(); - }) - .fail(jsonFailLoad); + retrieveJQPlotJson(jQplotDate.getMonth()+1, jQplotDate.getFullYear()); $('[data-toggle="jqplot"]').click(function(){ @@ -323,21 +322,26 @@ jQuery(function($){ $('.js-stats-change-month').click(function(e){ $('.js-stats-change-month').attr('disabled', true); + jQplotDate.setMonth(parseInt(jQplotDate.getMonth()) + parseInt($(this).data('month-offset'))); + retrieveJQPlotJson(jQplotDate.getMonth()+1, jQplotDate.getFullYear(), function(){$('.js-stats-change-month').attr('disabled', false);}); - $('#jqplot'); - - {literal} - $.getJSON(url, {month: 9, year: 2010}) - .done(function(data) { - jQplotData = data; - jsonSuccessLoad(); - }) - .fail(jsonFailLoad); - {/literal} }); + function retrieveJQPlotJson(month, year, callback) { + console.log(month, year); - function initJqplotData(json){ + $.getJSON(url, {month: month, year: year}) + .done(function(data) { + jQplotData = data; + jsonSuccessLoad(); + if(callback) { + callback(); + } + }) + .fail(jsonFailLoad); + } + + function initJqplotData(json) { var series = []; var seriesColors = []; $('[data-toggle="jqplot"].active').each(function(i){ @@ -391,6 +395,8 @@ jQuery(function($){ } + {/literal} + });