PageRenderTime 28ms CodeModel.GetById 18ms app.highlight 8ms RepoModel.GetById 0ms app.codeStats 1ms

/src/baruwa/static/js/reports.listing.js

https://bitbucket.org/datopdog/baruwa
JavaScript | 133 lines | 106 code | 3 blank | 24 comment | 6 complexity | c245096297597a0e14b2d9ac70c1870e MD5 | raw file
Possible License(s): GPL-2.0
  1// 
  2// Baruwa - Web 2.0 MailScanner front-end.
  3// Copyright (C) 2010  Andrew Colin Kissa <andrew@topdog.za.net>
  4// 
  5// This program is free software; you can redistribute it and/or modify
  6// it under the terms of the GNU General Public License as published by
  7// the Free Software Foundation; either version 2 of the License, or
  8// (at your option) any later version.
  9// 
 10// This program is distributed in the hope that it will be useful,
 11// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13// GNU General Public License for more details.
 14// 
 15// You should have received a copy of the GNU General Public License along
 16// with this program; if not, write to the Free Software Foundation, Inc.,
 17// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 18//
 19// vim: ai ts=4 sts=4 et sw=4
 20//
 21dojo.require("dojox.charting.Chart2D");
 22dojo.require("dojox.charting.action2d.Highlight");
 23dojo.require("dojox.charting.action2d.Magnify");
 24dojo.require("dojox.charting.action2d.Shake");
 25dojo.require("dojox.charting.action2d.Tooltip");
 26dojo.require("dojox.charting.widget.Legend");
 27
 28//functions
 29function build_rows(build_array){
 30	var rows = [];
 31	var count = 0;
 32	var c = 'LightBlue_div'
 33	dojo.forEach(build_array, function(item, i){
 34	    if (c == 'LightBlue_div') {
 35	        c = 'LightGray_div';
 36	    }else{
 37	        c = 'LightBlue_div';
 38	    };
 39		rows[count++] = '<div class="'+c+'">';
 40		rows[count++] = '<div class="totals_date">'+item.date+'</div>';
 41		rows[count++] = '<div class="totals_mail">'+item.mail_total+'</div>';
 42		rows[count++] = '<div class="totals_virii">'+item.virus_total+'</div>';
 43		rows[count++] = '<div class="totals_viriip">'+item.virus_percent+'</div>';
 44		rows[count++] = '<div class="totals_spam">'+item.spam_total+'</div>';
 45		rows[count++] = '<div class="totals_spamp">'+item.spam_percent+'</div>';
 46		rows[count++] = '<div class="totals_volume">'+filesizeformat(item.size_total)+'</div>';
 47		rows[count++] = '</div>';
 48	});
 49	return rows.join('');
 50}
 51
 52function process_response(data){
 53    var spinner = dojo.byId("my-spinner");
 54	spinner.innerHTML = gettext('Processing...........');
 55	if (data.success == true) {
 56		url = window.location.pathname;
 57		var links = build_filters(data.active_filters);
 58		dojo.empty("fhl");
 59		if (links != "") {
 60		    dojo.place(links,"fhl","last");
 61		    dojo.removeClass("filterrow","hide");
 62		}else{
 63		    dojo.addClass("filterrow","hide");
 64		};
 65		dojo.query("#fhl a").onclick(function(e){
 66		    remove_filter(e,this);
 67		});
 68		dojo.xhrGet({
 69			url:url,
 70			handleAs:"json",
 71			load:function(response){
 72				dojo.empty("graphrows");
 73				var rows = build_rows(response.items);
 74				dojo.place(rows,"graphrows","last");
 75				chart.updateSeries("mail", response.pie_data.mail);
 76				chart.updateSeries("spam", response.pie_data.spam);
 77				chart.updateSeries("virii", response.pie_data.virii);
 78				chart.render();
 79				spinner.innerHTML = '';
 80            	dojo.style('my-spinner','display','none');
 81            	dojo.attr("filter_form_submit", {'value':gettext('Add')});
 82            	dojo.removeAttr('filter_form_submit','disabled');
 83            	window.scrollTo(0,0);
 84			}
 85		});
 86	}else{
 87		dojo.destroy('filter-error');
 88		dojo.create('div',{'id':"filter-error",'innerHTML':data.errors+'<div id="dismiss"><a href="#">'+gettext('Dismiss')+'</a></div>'},'afform','before');
 89		var timeout = setTimeout(function(){dojo.destroy('filter-error');},15050);
 90		dojo.query("#dismiss a").onclick(function(){clearTimeout(timeout); dojo.destroy('filter-error');});
 91		spinner.innerHTML = '';
 92    	dojo.style('my-spinner','display','none');
 93    	dojo.attr("filter_form_submit", {'value':gettext('Add')});
 94    	dojo.removeAttr('filter_form_submit','disabled');
 95	};
 96}
 97
 98dojo.addOnLoad(function(){
 99    init_form();
100    //bind to form submit
101    dojo.query("#filter-form").onsubmit(function(e){
102    	e.preventDefault();
103    	dojo.attr("filter_form_submit", {'disabled':'disabled','value':gettext('Loading')});
104    	dojo.style('my-spinner','display','block');
105    	dojo.destroy('filter-error');
106    	dojo.xhrPost({
107    		form:"filter-form",
108    		handleAs:"json",
109    		load:function(data){process_response(data);}
110    	});
111    });
112    dojo.query("#fhl a").onclick(function(e){
113        remove_filter(e,this);
114    });
115    //init chart and render
116	var dc = dojox.charting;
117	var dur = 450;
118	chart = new dojox.charting.Chart2D("chart");
119	chart.addAxis("x",{labels: labels,majorTickStep:15});
120	chart.addAxis("y",{vertical:true});
121	chart.addPlot("default",{type: "ClusteredColumns",gap:2});
122	chart.addSeries("mail", mail_data, {stroke: {color: "black"}, fill: "green"});
123	chart.addSeries("spam", spam_data, {stroke: {color: "black"}, fill: "pink"});
124	chart.addSeries("virii", virii_data, {stroke: {color: "black"}, fill: "red"});
125	var anim6a = new dc.action2d.Highlight(chart, "default", {
126	duration: dur,
127	easing:   dojo.fx.easing.sineOut
128	});
129	//var anim6b = new dc.action2d.Shake(chart, "default");
130	var anim6c = new dc.action2d.Tooltip(chart, "default");
131	chart.render();
132	var mail_legend = new dojox.charting.widget.Legend({chart: chart}, "mail_legend");
133});