summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2017-04-05 11:50:43 +0200
committerYannick Tivisse <yti@odoo.com>2017-06-19 17:37:38 +0200
commite331c0bd19c4738b5646bb6fe9ccb959e14b3d9d (patch)
treea480ce7e3622b1c52d52807a7817b24fffc3e529
parentac23ca499ed34337a692fd01ee1d207b40d30926 (diff)
[IMP] website: improve setting ga_client_id from dashboard
It now update the website settings parameter use_google_analytics_dashboard so that the settings are correctly updated with the user choice. Implementation is changed so that the dashboard uses a jsonRpc call instead of directly calling ir_config_parameter set_param.
-rw-r--r--addons/website/controllers/backend.py22
-rw-r--r--addons/website/static/src/js/website.backendDashboard.js26
2 files changed, 34 insertions, 14 deletions
diff --git a/addons/website/controllers/backend.py b/addons/website/controllers/backend.py
index 0aeb2540133..8a59d730714 100644
--- a/addons/website/controllers/backend.py
+++ b/addons/website/controllers/backend.py
@@ -35,3 +35,25 @@ class WebsiteBackend(http.Controller):
ga_client_id = request.env['ir.config_parameter'].sudo().get_param('google_management_client_id', default='')
dashboard_data['dashboards']['visits']['ga_client_id'] = ga_client_id
return dashboard_data
+
+ @http.route('/website/dashboard/set_ga_client_id', type='json', auth='user')
+ def website_set_ga_client_id(self, ga_client_id):
+ if not request.env.user.has_group('base.group_system'):
+ return {
+ 'error': {
+ 'title': 'Access Error',
+ 'message': 'You do not have sufficient rights to perform that action.',
+ }
+ }
+ if not ga_client_id.endswith('.apps.googleusercontent.com') or ga_client_id.startswith(" "):
+ return {
+ 'error': {
+ 'title': 'Incorrect Client ID',
+ 'message': 'The Google Analytics Client ID you have entered seems incorrect.',
+ }
+ }
+ request.env['website.config.setting'].create({
+ 'use_google_analytics_dashboard': True,
+ 'google_management_client_id': ga_client_id,
+ })
+ return True
diff --git a/addons/website/static/src/js/website.backendDashboard.js b/addons/website/static/src/js/website.backendDashboard.js
index 9c6416da4ac..f5c9c6b7b2f 100644
--- a/addons/website/static/src/js/website.backendDashboard.js
+++ b/addons/website/static/src/js/website.backendDashboard.js
@@ -96,21 +96,19 @@ var Dashboard = Widget.extend(ControlPanelMixin, {
},
on_save_ga_client_id: function(ga_client_id) {
-
- if (!ga_client_id.endsWith(".apps.googleusercontent.com") || ga_client_id.startsWith(" ")) {
- this.do_warn(_t('Incorrect Client ID'), _t('The Google Analytics Client ID you have entered seems incorrect.'));
- return;
- }
-
var self = this;
- this._rpc({
- model: 'ir.config_parameter',
- method: 'set_param',
- args: ['google_management_client_id', ga_client_id],
- })
- .then(function(){
- self.on_date_range_button('week');
- });
+ return this._rpc({
+ route: '/website/dashboard/set_ga_client_id',
+ params: {
+ 'ga_client_id': ga_client_id
+ },
+ }).then(function (result) {
+ if (result.error) {
+ self.do_warn(result.error.title, result.error.message);
+ return;
+ }
+ self.on_date_range_button('week');
+ });
},
render_dashboards: function() {