From 488111719cf06538f417e1129ad1c331ee08d868 Mon Sep 17 00:00:00 2001 From: "Parth Gajjar (Open ERP)" Date: Fri, 28 Mar 2014 12:06:23 +0530 Subject: [PATCH] [IMP] improved config dialog if api key not set bzr revid: pga@tinyerp.com-20140328063623-it6j2lptjoieik91 --- addons/website_gengo/controllers/main.py | 9 ++++- .../static/src/js/website_gengo.js | 34 +++++++++++++++++++ .../static/src/xml/website.gengo.xml | 33 +++++++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/addons/website_gengo/controllers/main.py b/addons/website_gengo/controllers/main.py index b8fc9c7d59b..59131f152ba 100644 --- a/addons/website_gengo/controllers/main.py +++ b/addons/website_gengo/controllers/main.py @@ -12,11 +12,18 @@ class website_gengo(http.Controller): for trans in ir_translation_obj.browse(request.cr, request.uid, gengo_translation_ids): result['done'] += len(trans.source.split()) return result + @http.route('/website/check_gengo_set', type='json', auth='user', website=True) def check_gengo_set(self): - ir_translation_obj = request.registry['res.users'] user = request.registry['res.users'].browse(request.cr, request.uid, request.uid) company_flag = 0 if not user.company_id.gengo_public_key or not user.company_id.gengo_private_key: company_flag = user.company_id.id return company_flag + + @http.route('/website/set_gengo_config', type='json', auth='user', website=True) + def set_gengo_config(self,config): + user = request.registry['res.users'].browse(request.cr, request.uid, request.uid) + if user.company_id: + request.registry['res.company'].write(request.cr, request.uid, user.company_id.id,config) + return True diff --git a/addons/website_gengo/static/src/js/website_gengo.js b/addons/website_gengo/static/src/js/website_gengo.js index 08cfe026500..5bc8c6b9017 100644 --- a/addons/website_gengo/static/src/js/website_gengo.js +++ b/addons/website_gengo/static/src/js/website_gengo.js @@ -74,6 +74,9 @@ }else{ var dialog = new website.GengoApiConfigDialog(res); dialog.appendTo($(document.body)); + dialog.on('set_config', this, function () { + dialog.$el.modal('hide'); + }); } }); @@ -139,6 +142,7 @@ website.GengoApiConfigDialog = openerp.Widget.extend({ events: _.extend({}, website.EditorBar.prototype.events, { 'hidden.bs.modal': 'destroy', + 'click button[data-action=set_config]': 'set_config' }), template: 'website.GengoApiConfigDialog', init:function(company_id){ @@ -148,6 +152,36 @@ start: function (res) { this.$el.modal(this.res); }, + set_config:function(ev){ + var self = this; + var public_key = this.$el.find("#gengo_public_key")[0].value; + var private_key = this.$el.find("#gengo_private_key")[0].value; + var auto_approve = this.$el.find("#gengo_auto_approve")[0].checked; + var sandbox = this.$el.find("#gengo_sandbox")[0].checked; + var pub_el = this.$el.find(".gengo_group_public")[0]; + var pri_el = this.$el.find(".gengo_group_private")[0]; + if(! public_key){ + $(pub_el).addClass("has-error"); + } + else{ + $(pub_el).removeClass("has-error"); + } + if(! private_key){ + $(pri_el).addClass("has-error"); + } + else{ + $(pri_el).removeClass("has-error"); + } + if(public_key && private_key){ + openerp.jsonRpc('/website/set_gengo_config', 'call', { + 'config': {'gengo_public_key':public_key,'gengo_private_key':private_key,'gengo_auto_approve':auto_approve,'gengo_sandbox':sandbox}, + }).then(function () { + self.trigger('set_config'); + }).fail(function () { + alert("Could not submit ! Try Again"); + }); + } + } }); })(); diff --git a/addons/website_gengo/static/src/xml/website.gengo.xml b/addons/website_gengo/static/src/xml/website.gengo.xml index 62083ae025a..cdcca3a092a 100644 --- a/addons/website_gengo/static/src/xml/website.gengo.xml +++ b/addons/website_gengo/static/src/xml/website.gengo.xml @@ -118,10 +118,41 @@