blob: 15e7cf3fdc09b21dccc3d42a7d6f8a1ca9a2a17c [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,
Rushabh Mehtaae5cdeb2011-08-30 13:24:49 +053013 start: dateutil.obj_to_str(dateutil.add_days(new Date(), -180)),
Rushabh Mehta29a75c42011-08-25 19:17:44 +053014 end: dateutil.obj_to_str(new Date()),
Rushabh Mehtaae5cdeb2011-08-30 13:24:49 +053015 interval: 30
Rushabh Mehta29a75c42011-08-25 19:17:44 +053016 }
17
Rushabh Mehtaae5cdeb2011-08-30 13:24:49 +053018 var ph = new PageHeader($('.dashboard .header').get(0), 'Dashboard');
Rushabh Mehta29a75c42011-08-25 19:17:44 +053019 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);
Rushabh Mehtaae5cdeb2011-08-30 13:24:49 +053049 var parent = $a(cell, 'div', 'dashboard-graph');
50 if(data[i][0].comment);
51 var comment = $a(cell, 'div', 'comment', '', data[i][0].comment)
Rushabh Mehta29a75c42011-08-25 19:17:44 +053052
53 parent.id = '_dashboard' + ridx + '-' + cidx;
54
55 // render graph
Rushabh Mehtaae5cdeb2011-08-30 13:24:49 +053056 me.render_graph(parent.id, data[i][1], data[i][0].fillColor);
Rushabh Mehta29a75c42011-08-25 19:17:44 +053057 cidx++;
58 }
59 },
60
Rushabh Mehtaae5cdeb2011-08-30 13:24:49 +053061 render_graph: function(parent, values, fillColor) {
Rushabh Mehta29a75c42011-08-25 19:17:44 +053062 var vl = [];
63 $.each(values, function(i,v) {
64 vl.push([dateutil.str_to_user(v[0]), v[1]]);
65 });
66 $.jqplot(parent, [vl], {
67 seriesDefaults:{
68 renderer:$.jqplot.BarRenderer,
69 rendererOptions: {fillToZero: true},
70 },
71 axes: {
72 // Use a category axis on the x axis and use our custom ticks.
73 xaxis: {
74 min: 0,
75 renderer: $.jqplot.CategoryAxisRenderer,
76 tickRenderer: $.jqplot.CanvasAxisTickRenderer,
77 tickOptions: {
78 angle: -30,
79 fontSize: '8pt'
80 }
81 },
82 // Pad the y axis just a little so bars can get close to, but
83 // not touch, the grid boundaries. 1.2 is the default padding.
84 yaxis: {
85 min: 0,
86 pad: 1.05,
87 tickOptions: {formatString: '%d'}
88 }
Rushabh Mehtaae5cdeb2011-08-30 13:24:49 +053089 },
90 seriesColors: [fillColor]
Rushabh Mehta29a75c42011-08-25 19:17:44 +053091 });
92 },
93
94 show_settings: function() {
95 var d = new wn.widgets.Dialog({
96 title: 'Set Company Settings',
97 width: 500,
98 fields: [
99 {
100 label:'Company',
101 reqd: 1,
102 fieldname:'company',
103 fieldtype:'Link',
104 options: 'Company'
105 },
106 {
107 label:'Start Date',
108 reqd: 1,
109 fieldname:'start',
110 fieldtype:'Date',
111 },
112 {
113 label:'End Date',
114 reqd: 1,
115 fieldname:'end',
116 fieldtype:'Date',
117 },
118 {
119 label:'Interval',
120 reqd: 1,
121 fieldname:'interval',
122 fieldtype:'Int'
123 },
124 {
125 label:'Regenerate',
126 fieldname:'refresh',
127 fieldtype:'Button'
128 }
129 ]
130 });
131 d.onshow = function() {
132 d.set_values(pscript.dashboard_settings);
133 }
134 d.fields_dict.refresh.input.onclick = function() {
135 pscript.dashboard_settings = d.get_values();
136 me.refresh();
137 d.hide();
138 }
139 d.show();
140 }
141 })
142}