// Dashgoals :)

This commit is contained in:
Damien Metzger
2013-10-23 15:37:43 +02:00
parent ff3455be78
commit 9930c375c7
9 changed files with 197 additions and 98 deletions
+22 -24
View File
@@ -1,38 +1,36 @@
function line_chart_goals(widget_name, chart_details)
function bar_chart_goals(widget_name, chart_details)
{
nv.addGraph(function() {
var chart = nv.models.lineChart()
.useInteractiveGuideline(true)
.x(function(d) { return d[0] })
.y(function(d) { return d[1]/100 })
.color(d3.scale.category10().range());
chart.xAxis
.tickFormat(function(d) {
return d3.time.format('%m/%d/%y')(new Date(d))
});
chart.yAxis
.tickFormat(d3.format(',.1%'));
nv.addGraph(function() {
var chart = nv.models.multiBarChart();
chart.yAxis.tickFormat(d3.format('%'));
d3.select('#dash_goals_chart1 svg')
.datum(chart_details.data)
.transition()
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
}
function dashgoals_calc_sales()
{
$('.dashgoals_sales').each(function() {
var key = $(this).attr('id').substr(16);
var sales = parseFloat($('#dashgoals_traffic_' + key).val()) * parseFloat($('#dashgoals_avg_cart_value_' + key).val()) * parseFloat($('#dashgoals_conversion_' + key).val()) / 100;
if (isNaN(sales))
$(this).text('0');
else
$(this).text(parseInt(sales));
});
}
$(document).ready(function() {
$('.dashgoals_config_input').keyup(function() {
$('.dashgoals_sales').each(function() {
var key = $(this).attr('id').substr(16);
var sales = parseFloat($('#dashgoals_traffic_' + key).val()) * parseFloat($('#dashgoals_average_cart_value_' + key).val()) * parseFloat($('#dashgoals_conversion_rate_' + key).val()) / 100;
if (isNaN(sales))
$(this).text('0');
else
$(this).text(parseInt(sales));
});
dashgoals_calc_sales();
});
});
dashgoals_calc_sales();
});
@@ -35,32 +35,35 @@
</a>
</span>
</header>
<section id="dashgoals_config" class="dash_config">
<section id="dashgoals_config" class="dash_config hide">
<header><i class="icon-wrench"></i> {l s='Configuration' mod='dashgoals'}</header>
<table class="table table-condensed table-striped table-bordered">
<thead>
<tr>
<th>-</th>
<th>{l s='Traffic' mod='dashgoals'}</th>
<th>{l s='Conversion Rate' mod='dashgoals'}</th>
<th>{l s='Average Cart Value' mod='dashgoals'}</th>
<th>{l s='Sales' mod='dashgoals'}</th>
</tr>
</thead>
<tbody>
{foreach $goals_months as $month}
<tr>
<td>{$month}</td>
<td><input id="dashgoals_traffic_{$month@key}" name="dashgoals_traffic_{$month@key}" class="dashgoals_config_input form-control" value="" /></td>
<td><input id="dashgoals_conversion_rate_{$month@key}" name="dashgoals_conversion_rate_{$month@key}" class="dashgoals_config_input form-control" value="" /></td>
<td><input id="dashgoals_average_cart_value_{$month@key}" name="dashgoals_average_cart_value_{$month@key}" class="dashgoals_config_input form-control" value="" /></td>
<td id="dashgoals_sales_{$month@key}" class="dashgoals_sales">0</td>
</tr>
{/foreach}
</tbody>
</table>
<form class="defaultForm form-horizontal" method="post" action="{$link->getAdminLink('AdminDashboard')}">
<table class="table table-condensed table-striped table-bordered">
<thead>
<tr>
<th>{$goals_year}</th>
<th>{l s='Traffic' mod='dashgoals'}</th>
<th>{l s='Conversion Rate' mod='dashgoals'}</th>
<th>{l s='Average Cart Value' mod='dashgoals'}</th>
<th>{l s='Sales' mod='dashgoals'}</th>
</tr>
</thead>
<tbody>
{foreach $goals_months as $month}
<tr>
<td>{$month.label}</td>
<td><input id="dashgoals_traffic_{$month@key}" name="dashgoals_traffic_{$month@key}" class="dashgoals_config_input form-control" value="{$month.values.traffic|intval}" /></td>
<td><input id="dashgoals_conversion_{$month@key}" name="dashgoals_conversion_{$month@key}" class="dashgoals_config_input form-control" value="{$month.values.conversion|floatval}" /></td>
<td><input id="dashgoals_avg_cart_value_{$month@key}" name="dashgoals_avg_cart_value_{$month@key}" class="dashgoals_config_input form-control" value="{$month.values.avg_cart_value|intval}" /></td>
<td id="dashgoals_sales_{$month@key}" class="dashgoals_sales">0</td>
</tr>
{/foreach}
</tbody>
</table>
<input class="btn btn-default" name="submitDashGoals" type="submit" value="{l s='Save' mod='dashgoals'}" />
</form>
</section>
<section class="loading hide">
<section class="loading">
<div id="dash_goals_chart1" class="chart with-transitions">
<svg></svg>
</div>