summaryrefslogtreecommitdiff
path: root/addons/website_links/static/src/js
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-03-20 15:23:19 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit2106e3dd2ecd61096d7c7531c2f18b00fb30aeea (patch)
tree1e41a2e698ba993d9d74b6fddd699adb15642001 /addons/website_links/static/src/js
parent749d10e8b55dce94828290d7e4d6b2b6f741e9bd (diff)
[REF] web, *: simplify our RPC system (in JS)
The RPC system was not completely satisfactory, we decided to prepare the future and do it properly. This commit introduces the new rpc system, which replace the previous new one. We now simply have a method, this._rpc, which takes a dictionary of parameters. The idea is that depending on the parameters, it is able to add correct default value when necessary. For situations where we don't have the this._rpc method, we can use the rpc.query method, which takes the same arguments, but directly calls ajax.rpc instead of triggering up some events.
Diffstat (limited to 'addons/website_links/static/src/js')
-rw-r--r--addons/website_links/static/src/js/website_links.js14
-rw-r--r--addons/website_links/static/src/js/website_links_charts.js48
2 files changed, 38 insertions, 24 deletions
diff --git a/addons/website_links/static/src/js/website_links.js b/addons/website_links/static/src/js/website_links.js
index e7e12589843..5d310fcdb86 100644
--- a/addons/website_links/static/src/js/website_links.js
+++ b/addons/website_links/static/src/js/website_links.js
@@ -49,8 +49,10 @@ if(!$('.o_website_links_create_tracked_url').length) {
});
},
fetch_objects: function() {
- return rpc.query({model: this.obj, method: 'search_read'})
- .exec({type: "ajax"})
+ return rpc.query({
+ model: this.obj,
+ method: 'search_read',
+ })
.then(function(result) {
return _.map(result, function(val) {
return {id: val.id, text:val.name};
@@ -70,9 +72,11 @@ if(!$('.o_website_links_create_tracked_url').length) {
create_object: function(name) {
var self = this;
- return rpc.query({model: this.obj, method: 'create'})
- .args([{name:name}])
- .exec({type: "ajax"})
+ return rpc.query({
+ model: this.obj,
+ method: 'create',
+ args: [{name:name}],
+ })
.then(function(record) {
self.element.attr('value', record);
self.objects.push({'id': record, 'text': name});
diff --git a/addons/website_links/static/src/js/website_links_charts.js b/addons/website_links/static/src/js/website_links_charts.js
index a0033f0148e..193c29d3a76 100644
--- a/addons/website_links/static/src/js/website_links_charts.js
+++ b/addons/website_links/static/src/js/website_links_charts.js
@@ -133,39 +133,49 @@ if(!$('.o_website_links_chart').length) {
var links_domain = ['link_id', '=', parseInt(link_id)];
var total_clicks = function() {
- return rpc.query({model: 'link.tracker.click', method: 'search_count'})
- .args([[links_domain]])
- .exec({type: "ajax"});
+ return rpc.query({
+ model: 'link.tracker.click',
+ method: 'search_count',
+ args: [[links_domain]],
+ });
};
var clicks_by_day = function() {
- return rpc.query({model: 'link.tracker.click', method: 'read_group'})
- .args([[links_domain], ['create_date']])
- .kwargs({'groupby':'create_date:day'})
- .exec({type: "ajax"});
+ return rpc.query({
+ model: 'link.tracker.click',
+ method: 'read_group',
+ args: [[links_domain], ['create_date']],
+ kwargs: {groupby:'create_date:day'},
+ });
};
var clicks_by_country = function() {
- return rpc.query({model: 'link.tracker.click', method: 'read_group'})
- .args([[links_domain], ['country_id']])
- .kwargs({'groupby':'country_id'})
- .exec({type: "ajax"});
+ return rpc.query({
+ model: 'link.tracker.click',
+ method: 'read_group',
+ args: [[links_domain], ['country_id']],
+ kwargs: {groupby:'country_id'},
+ });
};
var last_week_clicks_by_country = function() {
var interval = moment().subtract(7, 'days').format("YYYY-MM-DD");
- return rpc.query({model: 'link.tracker.click', method: 'read_group'})
- .args([[links_domain, ['create_date', '>', interval]], ['country_id']])
- .kwargs({'groupby':'country_id'})
- .exec({type: "ajax"});
+ return rpc.query({
+ model: 'link.tracker.click',
+ method: 'read_group',
+ args: [[links_domain, ['create_date', '>', interval]], ['country_id']],
+ kwargs: {groupby:'country_id'},
+ });
};
var last_month_clicks_by_country = function() {
var interval = moment().subtract(30, 'days').format("YYYY-MM-DD");
- return rpc.query({model: 'link.tracker.click', method: 'read_group'})
- .args([[links_domain, ['create_date', '>', interval]], ['country_id']])
- .kwargs({'groupby':'country_id'})
- .exec({type: "ajax"});
+ return rpc.query({
+ model: 'link.tracker.click',
+ method: 'read_group',
+ args: [[links_domain, ['create_date', '>', interval]], ['country_id']],
+ kwargs: {groupby: 'country_id'},
+ });
};
$.when(total_clicks(),