2014-03-18 13:30:36 +00:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
2014-04-25 12:49:13 +00:00
|
|
|
if (!openerp.website.translatable) {
|
|
|
|
// Temporary hack until the editor bar is moved to the web client
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-18 13:30:36 +00:00
|
|
|
var website = openerp.website;
|
|
|
|
website.add_template_file('/website_gengo/static/src/xml/website.gengo.xml');
|
|
|
|
|
|
|
|
website.EditorBar.include({
|
|
|
|
events: _.extend({}, website.EditorBar.prototype.events, {
|
|
|
|
'click a[data-action=translation_gengo_post]': 'translation_gengo_post',
|
2014-03-19 13:31:21 +00:00
|
|
|
'click a[data-action=translation_gengo_info]': 'translation_gengo_info',
|
2014-03-18 13:30:36 +00:00
|
|
|
}),
|
2014-03-24 10:36:31 +00:00
|
|
|
edit:function () {
|
|
|
|
this.gengo_translate = true;
|
2014-03-18 13:30:36 +00:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
var self = this;
|
2014-04-01 05:45:18 +00:00
|
|
|
var gengo_langs = ["ar_SY","id_ID","nl_NL","fr_CA","pl_PL","zh_TW","sv_SE","ko_KR","pt_PT","en_US","ja_JP","es_ES","zh_CN","de_DE","fr_FR","fr_BE","ru_RU","it_IT","pt_BR","pt_BR","th_TH","nb_NO","ro_RO","tr_TR","bg_BG","da_DK","en_GB","el_GR","vi_VN","he_IL","hu_HU","fi_FI"];
|
2014-03-24 10:36:31 +00:00
|
|
|
if (gengo_langs.indexOf(website.get_context()['lang']) != -1){
|
2014-03-27 10:30:14 +00:00
|
|
|
self.$('.gengo_post,.gengo_wait,.gengo_inprogress,.gengo_info').remove();
|
2014-03-24 10:36:31 +00:00
|
|
|
self.$('button[data-action=save]')
|
|
|
|
.after(openerp.qweb.render('website.ButtonGengoTranslator'));
|
2014-03-21 07:14:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
translation_gengo_display:function(){
|
|
|
|
var self = this;
|
2014-03-24 10:36:31 +00:00
|
|
|
if($('.oe_translatable_todo').length == 0){
|
|
|
|
self.$el.find('.gengo_post').addClass("hidden");
|
|
|
|
self.$el.find('.gengo_inprogress').removeClass("hidden");
|
|
|
|
}
|
2014-03-18 13:30:36 +00:00
|
|
|
},
|
|
|
|
translation_gengo_post: function () {
|
|
|
|
var self = this;
|
|
|
|
var translatable_list = $.find('.oe_translatable_todo');
|
2014-03-25 14:13:08 +00:00
|
|
|
this.new_words = 0;
|
|
|
|
$('.oe_translatable_todo').each(function () {
|
|
|
|
self.new_words += $(this).text().trim().replace(/ +/g," ").split(" ").length;
|
|
|
|
});
|
|
|
|
openerp.jsonRpc('/website/check_gengo_set', 'call', {
|
|
|
|
}).then(function (res) {
|
2014-03-26 07:10:57 +00:00
|
|
|
if (res == 0){
|
2014-03-25 14:13:08 +00:00
|
|
|
var dialog = new website.GengoTranslatorPostDialog(self.new_words);
|
|
|
|
dialog.appendTo($(document.body));
|
|
|
|
dialog.on('service_level', this, function () {
|
|
|
|
var gengo_service_level = dialog.$el.find(".form-control").val();
|
|
|
|
dialog.$el.modal('hide');
|
|
|
|
self.$el.find('.gengo_post').addClass("hidden");
|
|
|
|
self.$el.find('.gengo_wait').removeClass("hidden");
|
|
|
|
var trans ={}
|
|
|
|
$('.oe_translatable_todo').each(function () {
|
|
|
|
var $node = $(this);
|
|
|
|
var data = $node.data();
|
|
|
|
if (!trans[data.oeTranslationViewId]) {
|
|
|
|
trans[data.oeTranslationViewId] = [];
|
|
|
|
}
|
|
|
|
trans[data.oeTranslationViewId].push({
|
|
|
|
initial_content: self.getInitialContent(this),
|
|
|
|
new_content:self.getInitialContent(this),
|
|
|
|
translation_id: data.oeTranslationId || null,
|
|
|
|
gengo_translation: gengo_service_level,
|
2014-04-09 21:45:09 +00:00
|
|
|
gengo_comment:"\nOriginal Page: " + document.URL
|
2014-03-25 14:13:08 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
openerp.jsonRpc('/website/set_translations', 'call', {
|
|
|
|
'data': trans,
|
|
|
|
'lang': website.get_context()['lang'],
|
|
|
|
}).then(function () {
|
|
|
|
$('.oe_translatable_todo').addClass('oe_translatable_inprogress').removeClass('oe_translatable_todo');
|
|
|
|
self.$el.find('.gengo_wait').addClass("hidden");
|
|
|
|
self.$el.find('.gengo_inprogress,.gengo_discard').removeClass("hidden");
|
2014-03-28 11:37:15 +00:00
|
|
|
openerp.jsonRpc('/website/post_gengo_jobs', 'call', {});
|
2014-03-25 14:13:08 +00:00
|
|
|
self.save();
|
|
|
|
}).fail(function () {
|
|
|
|
alert("Could not Post translation");
|
|
|
|
});
|
2014-03-18 13:30:36 +00:00
|
|
|
});
|
2014-03-25 14:13:08 +00:00
|
|
|
}else{
|
2014-03-26 07:10:57 +00:00
|
|
|
var dialog = new website.GengoApiConfigDialog(res);
|
2014-03-25 14:13:08 +00:00
|
|
|
dialog.appendTo($(document.body));
|
2014-03-28 06:36:23 +00:00
|
|
|
dialog.on('set_config', this, function () {
|
|
|
|
dialog.$el.modal('hide');
|
|
|
|
});
|
2014-03-25 14:13:08 +00:00
|
|
|
}
|
2014-03-18 13:30:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
},
|
2014-03-19 13:31:21 +00:00
|
|
|
translation_gengo_info: function () {
|
2014-03-24 10:36:31 +00:00
|
|
|
var repr = $(document.documentElement).data('mainObject');
|
|
|
|
var translated_ids = [];
|
|
|
|
$('.oe_translatable_text').not(".oe_translatable_inprogress").each(function(){
|
|
|
|
translated_ids.push($(this).attr('data-oe-translation-id'));
|
|
|
|
});
|
|
|
|
openerp.jsonRpc('/website/get_translated_length', 'call', {
|
|
|
|
'translated_ids': translated_ids,
|
2014-03-19 13:31:21 +00:00
|
|
|
'lang': website.get_context()['lang'],
|
|
|
|
}).done(function(res){
|
|
|
|
var dialog = new website.GengoTranslatorStatisticDialog(res);
|
|
|
|
dialog.appendTo($(document.body));
|
|
|
|
|
|
|
|
});
|
|
|
|
},
|
2014-03-18 13:30:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
website.GengoTranslatorPostDialog = openerp.Widget.extend({
|
|
|
|
events: _.extend({}, website.EditorBar.prototype.events, {
|
|
|
|
'hidden.bs.modal': 'destroy',
|
|
|
|
'click button[data-action=service_level]': function (ev) {
|
|
|
|
this.trigger('service_level');
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
template: 'website.GengoTranslatorPostDialog',
|
2014-03-25 14:13:08 +00:00
|
|
|
init:function(new_words){
|
|
|
|
this.new_words = new_words;
|
|
|
|
return this._super.apply(this, arguments);
|
|
|
|
},
|
2014-03-18 13:30:36 +00:00
|
|
|
start: function () {
|
|
|
|
this.$el.modal();
|
|
|
|
},
|
|
|
|
});
|
2014-03-19 13:31:21 +00:00
|
|
|
|
|
|
|
website.GengoTranslatorStatisticDialog = openerp.Widget.extend({
|
|
|
|
events: _.extend({}, website.EditorBar.prototype.events, {
|
|
|
|
'hidden.bs.modal': 'destroy',
|
|
|
|
}),
|
|
|
|
template: 'website.GengoTranslatorStatisticDialog',
|
2014-03-27 11:16:12 +00:00
|
|
|
init:function(res){
|
|
|
|
var self = this;
|
|
|
|
this.inprogess = 0;
|
|
|
|
this.new_words = 0;
|
|
|
|
this.done = res.done;
|
|
|
|
$('.oe_translatable_todo').each(function () {
|
|
|
|
self.new_words += $(this).text().trim().replace(/ +/g," ").split(" ").length;
|
|
|
|
});
|
|
|
|
$('.oe_translatable_inprogress').each(function () {
|
|
|
|
self.inprogess += $(this).text().trim().replace(/ +/g," ").split(" ").length;
|
|
|
|
});
|
|
|
|
this.total = this.done + this.inprogess;
|
|
|
|
return this._super.apply(this, arguments);
|
|
|
|
},
|
2014-03-19 13:31:21 +00:00
|
|
|
start: function (res) {
|
|
|
|
this.$el.modal(this.res);
|
|
|
|
},
|
|
|
|
});
|
2014-03-25 14:13:08 +00:00
|
|
|
website.GengoApiConfigDialog = openerp.Widget.extend({
|
|
|
|
events: _.extend({}, website.EditorBar.prototype.events, {
|
|
|
|
'hidden.bs.modal': 'destroy',
|
2014-03-28 06:36:23 +00:00
|
|
|
'click button[data-action=set_config]': 'set_config'
|
2014-03-25 14:13:08 +00:00
|
|
|
}),
|
|
|
|
template: 'website.GengoApiConfigDialog',
|
2014-03-26 07:10:57 +00:00
|
|
|
init:function(company_id){
|
|
|
|
this.company_id = company_id;
|
|
|
|
return this._super.apply(this, arguments);
|
|
|
|
},
|
2014-03-25 14:13:08 +00:00
|
|
|
start: function (res) {
|
|
|
|
this.$el.modal(this.res);
|
|
|
|
},
|
2014-03-28 06:36:23 +00:00
|
|
|
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");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-03-25 14:13:08 +00:00
|
|
|
});
|
2014-03-18 13:30:36 +00:00
|
|
|
|
|
|
|
})();
|