[IMP] improved config dialog if api key not set
bzr revid: pga@tinyerp.com-20140328063623-it6j2lptjoieik91
This commit is contained in:
parent
2de4260240
commit
488111719c
|
@ -12,11 +12,18 @@ class website_gengo(http.Controller):
|
||||||
for trans in ir_translation_obj.browse(request.cr, request.uid, gengo_translation_ids):
|
for trans in ir_translation_obj.browse(request.cr, request.uid, gengo_translation_ids):
|
||||||
result['done'] += len(trans.source.split())
|
result['done'] += len(trans.source.split())
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@http.route('/website/check_gengo_set', type='json', auth='user', website=True)
|
@http.route('/website/check_gengo_set', type='json', auth='user', website=True)
|
||||||
def check_gengo_set(self):
|
def check_gengo_set(self):
|
||||||
ir_translation_obj = request.registry['res.users']
|
|
||||||
user = request.registry['res.users'].browse(request.cr, request.uid, request.uid)
|
user = request.registry['res.users'].browse(request.cr, request.uid, request.uid)
|
||||||
company_flag = 0
|
company_flag = 0
|
||||||
if not user.company_id.gengo_public_key or not user.company_id.gengo_private_key:
|
if not user.company_id.gengo_public_key or not user.company_id.gengo_private_key:
|
||||||
company_flag = user.company_id.id
|
company_flag = user.company_id.id
|
||||||
return company_flag
|
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
|
||||||
|
|
|
@ -74,6 +74,9 @@
|
||||||
}else{
|
}else{
|
||||||
var dialog = new website.GengoApiConfigDialog(res);
|
var dialog = new website.GengoApiConfigDialog(res);
|
||||||
dialog.appendTo($(document.body));
|
dialog.appendTo($(document.body));
|
||||||
|
dialog.on('set_config', this, function () {
|
||||||
|
dialog.$el.modal('hide');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -139,6 +142,7 @@
|
||||||
website.GengoApiConfigDialog = openerp.Widget.extend({
|
website.GengoApiConfigDialog = openerp.Widget.extend({
|
||||||
events: _.extend({}, website.EditorBar.prototype.events, {
|
events: _.extend({}, website.EditorBar.prototype.events, {
|
||||||
'hidden.bs.modal': 'destroy',
|
'hidden.bs.modal': 'destroy',
|
||||||
|
'click button[data-action=set_config]': 'set_config'
|
||||||
}),
|
}),
|
||||||
template: 'website.GengoApiConfigDialog',
|
template: 'website.GengoApiConfigDialog',
|
||||||
init:function(company_id){
|
init:function(company_id){
|
||||||
|
@ -148,6 +152,36 @@
|
||||||
start: function (res) {
|
start: function (res) {
|
||||||
this.$el.modal(this.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");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -118,10 +118,41 @@
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<b> <h3>Steps for configure Gengo </h3>
|
<b> <h3>Steps for configure Gengo </h3>
|
||||||
<div class="mb16"> 1. Go To your <b><a target="new" href="https://gengo.com/account/api_settings/">Gengo account</a></b> and generate API Keys.</div>
|
<div class="mb16"> 1. Go To your <b><a target="new" href="https://gengo.com/account/api_settings/">Gengo account</a></b> and generate API Keys.</div>
|
||||||
<div class="mb16"> 2. Then paste generated keys in <a target="new" t-att-href="'/web#return_label=Website&model=res.company&id='+widget.company_id">Your company data</a></div>
|
<div class="mb16"> 2. Then paste generated keys in given form</div>
|
||||||
|
<ul class="list-group">
|
||||||
|
<li class="list-group-item form-group gengo_group_public">
|
||||||
|
<h4 class="list-group-item-heading">
|
||||||
|
<label class="control-label">Public key</label>
|
||||||
|
</h4>
|
||||||
|
<input type="text" class="form-control url url-source" id="gengo_public_key" placeholder="Paste public key here"/>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
<li class="list-group-item form-group gengo_group_private">
|
||||||
|
<h4 class="list-group-item-heading">
|
||||||
|
<label for="link-external" class="control-label">Private key</label>
|
||||||
|
</h4>
|
||||||
|
<input type="text" class="form-control url url-source" id="gengo_private_key" placeholder="Paste private key here"/>
|
||||||
|
</li>
|
||||||
|
<li class="list-group-item form-group">
|
||||||
|
<div>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="gengo_auto_approve" class="window-new" checked="1"/>
|
||||||
|
Auto Approve Translation <small class="text-muted">- Jobs are Automatically Approved by Gengo.</small>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="gengo_sandbox" class="window-new"/>
|
||||||
|
Sandbox <small class="text-muted">- Enable if you using testing account</small>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</b>
|
</b>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
<button type="button" data-action="set_config" class="btn btn-primary">Submit</button>
|
||||||
|
or
|
||||||
<a data-action="discard" data-dismiss="modal" href="#">Close</a>
|
<a data-action="discard" data-dismiss="modal" href="#">Close</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue