blob: c5dd36150e17027517d2e2440ad054d31bd13e27 [file] [log] [blame]
Rushabh Mehta29a75c42011-08-25 19:17:44 +05301pscript.onload_dashboard = function() {
2 // load jqplot
3 $.scriptPath = 'js/'
4 $.require(['jquery/jquery.jqplot.min.js',
5 'jquery/jqplot-plugins/jqplot.barRenderer.js',
6 'jquery/jqplot-plugins/jqplot.canvasAxisTickRenderer.min.js',
7 'jquery/jqplot-plugins/jqplot.canvasTextRenderer.min.js',
8 'jquery/jqplot-plugins/jqplot.categoryAxisRenderer.min.js']);
9
10
11 pscript.dashboard_settings = {
12 company: sys_defaults.company,
13 start: dateutil.obj_to_str(dateutil.add_days(new Date(), -60)),
14 end: dateutil.obj_to_str(new Date()),
15 interval: 7
16 }
17
18 var ph = new PageHeader($('.dashboard .header').get(0), 'Dashboards');
19 var db = new Dashboard();
20
21 ph.add_button('Settings', db.show_settings);
22
23 db.refresh();
24
25}
26
27Dashboard = function() {
28 var me = this;
29 $.extend(me, {
30 refresh: function() {
31 $('.dashboard .help_box').css('display', 'block');
32 $c_page('home', 'dashboard', 'load_dashboard', JSON.stringify(pscript.dashboard_settings), function(r,rt) {
33 $('.dashboard .help_box').css('display', 'none');
34 me.render(r.message);
35 })
36 },
37
38 render: function(data) {
39 $('.dashboard_table').html('');
40 var t = make_table($('.dashboard_table').get(0), 4, 2, '100%', ['50%', '50%'], {padding: '5px'});
41 var ridx=0; var cidx=0;
42 for(var i=0; i< data.length; i++) {
43 // switch columns and rows
44 if(cidx==2) { cidx=0; ridx++}
45
46 // give an id!
47 var cell = $td(t,ridx,cidx);
48 var title = $a(cell, 'div', 'dashboard-title', '', data[i][0].title);
49 var parent = $a(cell, 'div', 'dashboard-graph')
50
51 parent.id = '_dashboard' + ridx + '-' + cidx;
52
53 // render graph
54 me.render_graph(parent.id, data[i][1]);
55 cidx++;
56 }
57 },
58
59 render_graph: function(parent, values) {
60 var vl = [];
61 $.each(values, function(i,v) {
62 vl.push([dateutil.str_to_user(v[0]), v[1]]);
63 });
64 $.jqplot(parent, [vl], {
65 seriesDefaults:{
66 renderer:$.jqplot.BarRenderer,
67 rendererOptions: {fillToZero: true},
68 },
69 axes: {
70 // Use a category axis on the x axis and use our custom ticks.
71 xaxis: {
72 min: 0,
73 renderer: $.jqplot.CategoryAxisRenderer,
74 tickRenderer: $.jqplot.CanvasAxisTickRenderer,
75 tickOptions: {
76 angle: -30,
77 fontSize: '8pt'
78 }
79 },
80 // Pad the y axis just a little so bars can get close to, but
81 // not touch, the grid boundaries. 1.2 is the default padding.
82 yaxis: {
83 min: 0,
84 pad: 1.05,
85 tickOptions: {formatString: '%d'}
86 }
87 }
88 });
89 },
90
91 show_settings: function() {
92 var d = new wn.widgets.Dialog({
93 title: 'Set Company Settings',
94 width: 500,
95 fields: [
96 {
97 label:'Company',
98 reqd: 1,
99 fieldname:'company',
100 fieldtype:'Link',
101 options: 'Company'
102 },
103 {
104 label:'Start Date',
105 reqd: 1,
106 fieldname:'start',
107 fieldtype:'Date',
108 },
109 {
110 label:'End Date',
111 reqd: 1,
112 fieldname:'end',
113 fieldtype:'Date',
114 },
115 {
116 label:'Interval',
117 reqd: 1,
118 fieldname:'interval',
119 fieldtype:'Int'
120 },
121 {
122 label:'Regenerate',
123 fieldname:'refresh',
124 fieldtype:'Button'
125 }
126 ]
127 });
128 d.onshow = function() {
129 d.set_values(pscript.dashboard_settings);
130 }
131 d.fields_dict.refresh.input.onclick = function() {
132 pscript.dashboard_settings = d.get_values();
133 me.refresh();
134 d.hide();
135 }
136 d.show();
137 }
138 })
139}