diff options
| author | Hiral Bhavsar <hbh@odoo.com> | 2017-04-06 15:12:01 +0200 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2017-06-19 17:37:38 +0200 |
| commit | 100ab909e6516b5026bb3d2113f39fca3c4f6f86 (patch) | |
| tree | 79fd125baa4d6556cd41f1ab465cc90e1ba85801 /addons/website | |
| parent | e331c0bd19c4738b5646bb6fe9ccb959e14b3d9d (diff) | |
[IMP] website: Restructure the 'Google Analytics' wizard.
* Set the blocking warning if the user enters a 'Client ID' without
any 'Tracking ID'.
* 'Google Analytics in Dashboard' field is visible only if
'Google Analytics' is checked in website settings.
* Get/Set the value of 'google_analytics_key' and
'google_management_client_id' from 'website' model instead of
'ir.config_parameter' on 'Google Analytics' wizard.
* If ID is set on 'Google Analytics' wizard then activated the related
features and populate fields in website settings.
Diffstat (limited to 'addons/website')
| -rw-r--r-- | addons/website/controllers/backend.py | 28 | ||||
| -rw-r--r-- | addons/website/models/res_config.py | 13 | ||||
| -rw-r--r-- | addons/website/static/src/js/website.backendDashboard.js | 15 | ||||
| -rw-r--r-- | addons/website/static/src/xml/website.backend.xml | 11 | ||||
| -rw-r--r-- | addons/website/views/res_config_views.xml | 19 |
5 files changed, 61 insertions, 25 deletions
diff --git a/addons/website/controllers/backend.py b/addons/website/controllers/backend.py index 8a59d730714..3af688a6346 100644 --- a/addons/website/controllers/backend.py +++ b/addons/website/controllers/backend.py @@ -30,14 +30,16 @@ class WebsiteBackend(http.Controller): } } if has_group_designer: - ga_dashboard = request.env['ir.config_parameter'].sudo().get_param('website.has_google_analytics_dashboard') - if ga_dashboard: - 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 + config = request.env['website.config.settings'].sudo().create({}) + if config.has_google_analytics_dashboard: + dashboard_data['dashboards']['visits'] = dict( + ga_client_id=config.google_management_client_id or '', # void string instead of stringified False + ga_analytics_key=config.google_analytics_key or '', # void string instead of stringified False + ) 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): + @http.route('/website/dashboard/set_ga_data', type='json', auth='user') + def website_set_ga_data(self, ga_client_id, ga_analytics_key): if not request.env.user.has_group('base.group_system'): return { 'error': { @@ -45,15 +47,17 @@ class WebsiteBackend(http.Controller): '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(" "): + if not ga_analytics_key or not ga_client_id.endswith('.apps.googleusercontent.com'): return { 'error': { - 'title': 'Incorrect Client ID', - 'message': 'The Google Analytics Client ID you have entered seems incorrect.', + 'title': 'Incorrect Client ID / Key', + 'message': 'The Google Analytics Client ID or Key you entered seems incorrect.', } } - request.env['website.config.setting'].create({ - 'use_google_analytics_dashboard': True, + request.env['website.config.settings'].create({ + 'has_google_analytics': True, + 'has_google_analytics_dashboard': True, 'google_management_client_id': ga_client_id, - }) + 'google_analytics_key': ga_analytics_key, + }).execute() return True diff --git a/addons/website/models/res_config.py b/addons/website/models/res_config.py index 094a94e2e96..b1a8f26608d 100644 --- a/addons/website/models/res_config.py +++ b/addons/website/models/res_config.py @@ -54,6 +54,19 @@ class WebsiteConfigSettings(models.TransientModel): has_google_analytics_dashboard = fields.Boolean("Google Analytics in Dashboard") has_google_maps = fields.Boolean("Google Maps") + @api.onchange('has_google_analytics') + def onchange_has_google_analytics(self): + if not self.has_google_analytics: + self.has_google_analytics_dashboard = False + if not self.has_google_analytics: + self.google_analytics_key = False + + @api.onchange('has_google_analytics_dashboard') + def onchange_has_google_analytics_dashboard(self): + if not self.has_google_analytics_dashboard: + self.google_management_client_id = False + self.google_management_client_secret = False + def get_default_google_maps_api_key(self, fields): if not self.user_has_groups('website.group_website_designer'): raise AccessDenied() diff --git a/addons/website/static/src/js/website.backendDashboard.js b/addons/website/static/src/js/website.backendDashboard.js index f5c9c6b7b2f..f1dcdf6a6ec 100644 --- a/addons/website/static/src/js/website.backendDashboard.js +++ b/addons/website/static/src/js/website.backendDashboard.js @@ -76,7 +76,10 @@ var Dashboard = Widget.extend(ControlPanelMixin, { var dialog = new Dialog(this, { size: 'medium', title: _t('Google Analytics'), - $content: QWeb.render('website.ga_dialog_content', {ga_key: this.dashboards_data.visits.ga_client_id}), + $content: QWeb.render('website.ga_dialog_content', { + ga_key: this.dashboards_data.visits.ga_client_id, + ga_analytics_key: this.dashboards_data.visits.ga_analytics_key, + }), buttons: [ { text: _t("Save"), @@ -84,7 +87,8 @@ var Dashboard = Widget.extend(ControlPanelMixin, { close: true, click: function() { var ga_client_id = dialog.$el.find('input[name="ga_client_id"]').val(); - self.on_save_ga_client_id(ga_client_id); + var ga_analytics_key = dialog.$el.find('input[name="ga_analytics_key"]').val(); + self.on_save_ga_client_id(ga_client_id, ga_analytics_key); }, }, { @@ -95,12 +99,13 @@ var Dashboard = Widget.extend(ControlPanelMixin, { }).open(); }, - on_save_ga_client_id: function(ga_client_id) { + on_save_ga_client_id: function(ga_client_id, ga_analytics_key) { var self = this; return this._rpc({ - route: '/website/dashboard/set_ga_client_id', + route: '/website/dashboard/set_ga_data', params: { - 'ga_client_id': ga_client_id + 'ga_client_id': ga_client_id, + 'ga_analytics_key': ga_analytics_key, }, }).then(function (result) { if (result.error) { diff --git a/addons/website/static/src/xml/website.backend.xml b/addons/website/static/src/xml/website.backend.xml index a30267af9a8..9abb82e0e49 100644 --- a/addons/website/static/src/xml/website.backend.xml +++ b/addons/website/static/src/xml/website.backend.xml @@ -92,8 +92,15 @@ </div> <div t-name="website.ga_dialog_content"> - Your Google Analytic Client ID: <input type="text" name="ga_client_id" t-att-value="ga_key" style="width: 100%"></input> - <br/>Go to our <a href="https://www.odoo.com/documentation/user/online/website/optimize/google_analytics.html" target="_blank">User Documentation</a> to get more information. + Your Tracking ID: <input type="text" name="ga_analytics_key" placeholder="UA-XXXXXXXX-Y" t-att-value="ga_analytics_key" style="width: 100%"></input> + <a href="https://www.odoo.com/documentation/user/online/website/optimize/google_analytics_dashboard.html" class="oe_link fa fa-arrow-right" target="_blank"> + How to get my Tracking ID + </a> + <br/><br/> + Your Client ID: <input type="text" name="ga_client_id" t-att-value="ga_key" style="width: 100%"></input> + <a href="https://www.odoo.com/documentation/user/online/website/optimize/google_analytics_dashboard.html" class="oe_link fa fa-arrow-right" target="_blank"> + How to get my Client ID + </a> </div> <t t-name="website.DateRangeButtons"> diff --git a/addons/website/views/res_config_views.xml b/addons/website/views/res_config_views.xml index a98cfd92a5b..32f0a61e2d9 100644 --- a/addons/website/views/res_config_views.xml +++ b/addons/website/views/res_config_views.xml @@ -71,18 +71,25 @@ </div> <div class="content-group" attrs="{'invisible': [('has_google_analytics', '=', False)]}"> <div class="row mt16"> - <label class="col-md-3 o_light_label" string="Analytics Key" for="google_analytics_key"/> - <field name="google_analytics_key" placeholder="UA-XXXXXXXX-Y"/> + <label class="col-md-3 o_light_label" string="Tracking ID" for="google_analytics_key"/> + <field name="google_analytics_key" placeholder="UA-XXXXXXXX-Y" + attrs="{'required': [('google_management_client_id', '!=', False)]}"/> </div> </div> + <div attrs="{'invisible': [('has_google_analytics', '=', False)]}"> + <a href="https://www.odoo.com/documentation/user/online/website/optimize/google_analytics_dashboard.html" + class="oe_link fa fa-arrow-right" target="_blank"> + How to get my Tracking ID + </a> + </div> </div> </div> <div class="col-xs-12 col-md-6 o_setting_box" id="google_analytics_dashboard_setting"> - <div class="o_setting_left_pane"> + <div class="o_setting_left_pane" attrs="{'invisible': [('has_google_analytics', '=', False)]}"> <field name="has_google_analytics_dashboard"/> </div> - <div class="o_setting_right_pane"> + <div class="o_setting_right_pane" attrs="{'invisible': [('has_google_analytics', '=', False)]}"> <label for="has_google_analytics_dashboard"/> <div class="text-muted"> See Google Analytics data on your Website Dashboard @@ -98,9 +105,9 @@ </div> </div> <div attrs="{'invisible': [('has_google_analytics_dashboard', '=', False)]}"> - <a href="https://www.odoo.com/documentation/user/online/website/optimize/google_analytics.html" + <a href="https://www.odoo.com/documentation/user/online/website/optimize/google_analytics_dashboard.html" class="oe_link fa fa-arrow-right" target="_blank"> - Tutorial + How to get my Client ID </a> </div> </div> |
