summaryrefslogtreecommitdiff
path: root/addons/website_crm/static
diff options
context:
space:
mode:
authorMartin Geubelle <mge@odoo.com>2016-02-08 15:00:48 +0100
committerMartin Geubelle <mge@odoo.com>2016-03-10 13:41:10 +0100
commit42c82d57de980b68ef4d7a573ad712e06685d646 (patch)
tree725bc981191159aeb58edc81adbd0618f8a1ea0c /addons/website_crm/static
parentc603b93e1d64de61890f7e26a793147e920d2a25 (diff)
[ADD] website, website_sale, website_crm: new dashboard
Diffstat (limited to 'addons/website_crm/static')
-rw-r--r--addons/website_crm/static/src/js/website_crm_backend.js62
-rw-r--r--addons/website_crm/static/src/xml/website_crm_dashboard.xml46
2 files changed, 108 insertions, 0 deletions
diff --git a/addons/website_crm/static/src/js/website_crm_backend.js b/addons/website_crm/static/src/js/website_crm_backend.js
new file mode 100644
index 00000000000..6c8c77383ae
--- /dev/null
+++ b/addons/website_crm/static/src/js/website_crm_backend.js
@@ -0,0 +1,62 @@
+odoo.define('website_crm.backend', function (require) {
+"use strict";
+
+var core = require('web.core');
+var WebsiteBackend = require('website.backendDashboard');
+
+var QWeb = core.qweb;
+
+WebsiteBackend.include({
+
+ events: _.defaults({
+ 'change .js_field_selection': 'on_field_selection',
+ }, WebsiteBackend.prototype.events),
+
+ init: function(parent, context) {
+ this._super(parent, context);
+
+ this.dashboards_templates.push('website_crm.dashboard_leads');
+ this.graphs.push('leads');
+
+ this.leads_table = [];
+ this.lead_fields = [];
+ this.lead_field = '';
+ },
+
+ compute_percentages: function() {
+ if (!this.dashboards_data.leads.leads || !this.dashboards_data.leads.leads.length) {
+ return;
+ }
+ var leads = this.dashboards_data.leads.leads;
+ var lead_field_keys = _.pluck(leads, this.lead_field);
+ var leads_counter = _.groupBy(lead_field_keys);
+ this.leads_table = $.map(leads_counter, function(e, key) {
+ return {
+ 'value': e.length,
+ 'key': key,
+ 'perc': Math.round(e.length*100/leads.length)
+ };
+ });
+ this.leads_table.sort(function(a, b) { return b.value - a.value; });
+ },
+
+ fetch_data: function() {
+ var self = this;
+ return this._super().then(function() {
+ var leads = self.dashboards_data.leads.leads;
+ if (leads && leads.length) {
+ self.lead_fields = Object.keys(self.dashboards_data.leads.leads[0]);
+ self.lead_field = self.lead_fields[0];
+ self.compute_percentages();
+ }
+ });
+ },
+
+ on_field_selection: function(ev) {
+ this.lead_field = ev.currentTarget.value;
+ this.compute_percentages();
+ this.$('.js_leads_table').replaceWith(QWeb.render("website.LeadsTable", {'widget': this}));
+ },
+});
+
+});
diff --git a/addons/website_crm/static/src/xml/website_crm_dashboard.xml b/addons/website_crm/static/src/xml/website_crm_dashboard.xml
new file mode 100644
index 00000000000..f2f1596a40b
--- /dev/null
+++ b/addons/website_crm/static/src/xml/website_crm_dashboard.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<templates>
+ <t t-name="website_crm.dashboard_leads">
+ <div class="row o_dashboard_leads">
+ <div class="col-xs-12 o_box">
+ <h2>Lead Acquisition</h2>
+
+ <div class="row">
+ <div class="col-md-6">
+ <div id="o_graph_leads" class="o_graph" data-type="leads"/>
+ </div>
+
+ <div class="col-md-6">
+ <div t-if="!widget.leads_table || !widget.leads_table.length">
+ <i>There is no recent lead.</i>
+ </div>
+
+ <div t-if="widget.leads_table &amp;&amp; widget.leads_table.length" class="table-responsive">
+ <select class="js_field_selection">
+ <option t-foreach="widget.lead_fields" t-as="field" t-att-value="field"><t t-esc="field.split('_id')[0]"/></option>
+ </select>
+
+ <t t-call="website_crm.LeadsTable"/>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </t>
+
+ <t t-name="website_crm.LeadsTable">
+ <table class="table table-hover js_leads_table">
+ <tr>
+ <th></th>
+ <th>Leads</th>
+ <th>% Leads</th>
+ </tr>
+ <tr t-foreach="widget.leads_table" t-as="row">
+ <td><t t-esc="row.key"/></td>
+ <td><t t-esc="row.value"/></td>
+ <td><t t-esc="row.perc"/>%</td>
+ </tr>
+ </table>
+ </t>
+</templates>