{% extends "admin/change_list.html" %}
{% load i18n djangologdb_tags %}

{% block extrahead %}
	{{ block.super }}

	{% block djangologdb-jslibs %}
	<!--[if IE]><script type="text/javascript" src="{% djangologdb_media_url %}js/excanvas.min.js"></script><![endif]-->
	<script type="text/javascript" src="{% djangologdb_media_url %}js/jquery-1.3.2.min.js"></script>
	<script type="text/javascript" src="{% djangologdb_media_url %}js/jquery.flot-0.6.min.js"></script>
	{% endblock %}
	
	{% block djangologdb-jsinit %}
	<script type="text/javascript">
	$(function () {
		var options = {
			series: {
				lines: { show: true },
				points: { show: true },
				shadowSize: 0
			},
			yaxis: { min: 0, tickDecimals: 0 },
			xaxis: { tickDecimals: 0, mode: "time" }
		};

		var today = new Date();
		var start_date = new Date(today.getFullYear(), today.getMonth(), today.getDate() - {{ djangologdb_settings.HISTORY_DAYS }});
		var end_date = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1);
		
		var params = {
			start_date: start_date.getTime(),
			end_date: end_date.getTime(),
			{% ifequal djangologdb_settings.INTERVAL.days 0 %}
			interval_seconds: {{ djangologdb_settings.INTERVAL.seconds }},{% else %}
			interval_days: {{ djangologdb_settings.INTERVAL.days }},{% endifequal %}
			aggregate: '{{ aggregate }}'
		};

		$.getJSON('../datasets/', params, function(datasets) {
			var data = [];

			$.each(datasets, function(key, val) {
				data.push(datasets[key]);
			});
			
			$.plot($("#chart"), data, options);
		});
	});
	</script>
	{% endblock %}
{% endblock %}

{% block object-tools %}
	{{ block.super }}
	
	{% block djangologdb-chart %}
	<div class="module" style="padding: 10px;">
		<div id="chart" style="height: 250px;"></div>
	</div>
	{% endblock %}
{% endblock %}
