Browse Source

[MIG] web_translate_dialog migrated to v10

pull/442/merge
Jay Vora(SerpentCS) 8 years ago
committed by Pedro M. Baeza
parent
commit
68de37aeac
  1. 3
      web_translate_dialog/README.rst
  2. 3
      web_translate_dialog/__init__.py
  3. 5
      web_translate_dialog/__manifest__.py
  4. 63
      web_translate_dialog/static/src/js/web_translate_dialog.js
  5. 25
      web_translate_dialog/view/web_translate.xml

3
web_translate_dialog/README.rst

@ -31,7 +31,7 @@ pop-up with this field only.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/162/9.0
:target: https://runbot.odoo-community.org/runbot/162/10.0
Bug Tracker Bug Tracker
@ -55,6 +55,7 @@ Contributors
* Guewen Baconnier (Camptocamp) * Guewen Baconnier (Camptocamp)
* Antonio Espinosa <antonio.espinosa@tecnativa.com> * Antonio Espinosa <antonio.espinosa@tecnativa.com>
* Serpent Consulting Services Pvt. Ltd. <jay.vora@serpentcs.com>
Maintainer Maintainer
---------- ----------

3
web_translate_dialog/__init__.py

@ -1 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2012 Guewen Baconnier (Camptocamp SA)
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

5
web_translate_dialog/__manifest__.py

@ -2,10 +2,11 @@
# Copyright 2012 Guewen Baconnier (Camptocamp SA) # Copyright 2012 Guewen Baconnier (Camptocamp SA)
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> # Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
"name": "Web Translate Dialog", "name": "Web Translate Dialog",
"summary": "Easy-to-use pop-up to translate fields in several languages", "summary": "Easy-to-use pop-up to translate fields in several languages",
"version": "9.0.1.0.0",
"version": "10.0.1.0.0",
"category": "Web", "category": "Web",
"website": "https://odoo-community.org/", "website": "https://odoo-community.org/",
"author": "Camptocamp, " "author": "Camptocamp, "
@ -13,7 +14,7 @@
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"application": False, "application": False,
'installable': False,
'installable': True,
"depends": [ "depends": [
"web", "web",
], ],

63
web_translate_dialog/static/src/js/web_translate_dialog.js

@ -5,16 +5,13 @@
odoo.define('web_translate_dialog.translate_dialog', function(require){ odoo.define('web_translate_dialog.translate_dialog', function(require){
"use strict"; "use strict";
var _ = require('_');
var $ = require('$');
var core = require('web.core'); var core = require('web.core');
var data = require('web.data');
var common = require('web.form_common'); var common = require('web.form_common');
var data = require('web.data');
var Dialog = require('web.Dialog');
var FormView = require('web.FormView'); var FormView = require('web.FormView');
var View = require('web.View'); var View = require('web.View');
var Dialog = require('web.Dialog');
var _t = core._t; var _t = core._t;
var QWeb = core.qweb; var QWeb = core.qweb;
@ -32,42 +29,41 @@ var translateDialog = Dialog.extend({
this.view_type = parent.fields_view.type || ''; this.view_type = parent.fields_view.type || '';
this.$view_form = null; this.$view_form = null;
this.$sidebar_form = null; this.$sidebar_form = null;
if (!!field) {
if (field) {
this.translatable_fields_keys = [field]; this.translatable_fields_keys = [field];
this.translatable_fields = _.filter( this.translatable_fields = _.filter(
this.view.translatable_fields || [], this.view.translatable_fields || [],
function(i) {return i.name == field;}
function(i) {
return i.name === field;
}
); );
} else { } else {
this.translatable_fields_keys = _.map( this.translatable_fields_keys = _.map(
this.view.translatable_fields || [], this.view.translatable_fields || [],
function(i) {return i.name;}
function(i) {
return i.name;
}
); );
this.translatable_fields = this.view.translatable_fields.slice(0); this.translatable_fields = this.view.translatable_fields.slice(0);
} }
this.languages = null; this.languages = null;
this.languages_loaded = $.Deferred(); this.languages_loaded = $.Deferred();
(new data.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(), (new data.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(),
[['translatable', '=', '1']]))
.read_slice(['code', 'name'], { sort: 'id' })
.then(this.on_languages_loaded);
[['translatable', '=', '1']])).read_slice(['code', 'name'],
{ sort: 'id' }).then(this.on_languages_loaded);
}, },
on_languages_loaded: function(langs) { on_languages_loaded: function(langs) {
this.languages = langs; this.languages = langs;
this.languages_loaded.resolve(); this.languages_loaded.resolve();
}, },
open: function() { open: function() {
var self = this,
sup = this._super;
// the template needs the languages // the template needs the languages
$.when(this.languages_loaded).then(function() {
return sup.call(self);
});
return $.when(this.languages_loaded).then($.proxy(this._super, this));
}, },
start: function() { start: function() {
var self = this; var self = this;
this.$el.find('.oe_translation_field').change(function() { this.$el.find('.oe_translation_field').change(function() {
$(this).toggleClass('touched', ($(this).val() != $(this).attr('data-value')));
$(this).toggleClass('touched', $(this).val() !== $(this).attr('data-value'));
}); });
this.$footer.html(QWeb.render("TranslateDialog.buttons")); this.$footer.html(QWeb.render("TranslateDialog.buttons"));
this.$footer.find(".oe_form_translate_dialog_save_button").click(function(){ this.$footer.find(".oe_form_translate_dialog_save_button").click(function(){
@ -103,7 +99,7 @@ var translateDialog = Dialog.extend({
'inlinemedia': ['p'], 'inlinemedia': ['p'],
'lang': "odoo", 'lang': "odoo",
'onChange': function (value) { 'onChange': function (value) {
$(this).toggleClass('touched', (value != $(this).attr('data-value')));
$(this).toggleClass('touched', value !== $(this).attr('data-value'));
} }
}).parent(); }).parent();
// Triggers a mouseup to refresh the editor toolbar // Triggers a mouseup to refresh the editor toolbar
@ -118,14 +114,14 @@ var translateDialog = Dialog.extend({
set_fields_values: function(lang, values) { set_fields_values: function(lang, values) {
var self = this; var self = this;
_.each(this.translatable_fields_keys, function(f) { _.each(this.translatable_fields_keys, function(f) {
self.$el.find('.oe_translation_field[name="' + lang.code + '-' + f + '"]')
.val(values[f] || '')
.attr('data-value', values[f] || '');
self.$el.find('.oe_translation_field[name="' + lang.code +
'-' + f + '"]').val(values[f] || '').attr(
'data-value', values[f] || '');
}); });
this.$el.find('textarea.oe_translation_field').css({ this.$el.find('textarea.oe_translation_field').css({
minHeight:'100px', minHeight:'100px',
}); });
$(window).resize(); // triggers the autosize
$(window).resize();
this.initialize_html_fields(lang); this.initialize_html_fields(lang);
}, },
do_load_fields_values: function() { do_load_fields_values: function() {
@ -144,16 +140,14 @@ var translateDialog = Dialog.extend({
self.set_fields_values(lg, values); self.set_fields_values(lg, values);
deff.resolve(); deff.resolve();
} else { } else {
self.view.dataset.call(
'read',
[[self.view.datarecord.id],
self.view.dataset.call('read',[[self.view.datarecord.id],
self.translatable_fields_keys, self.translatable_fields_keys,
self.view.dataset.get_context({ self.view.dataset.get_context({
'lang': lg.code
})]).done(function (rows) {
self.set_fields_values(lg, rows[0]);
deff.resolve();
});
'lang': lg.code })]).done(
function (rows) {
self.set_fields_values(lg, rows[0]);
deff.resolve();
});
} }
}); });
return deferred; return deferred;
@ -175,9 +169,9 @@ var translateDialog = Dialog.extend({
} }
translation_mutex.exec(function() { translation_mutex.exec(function() {
return new data.DataSet(self, self.view.dataset.model, return new data.DataSet(self, self.view.dataset.model,
self.view.dataset.get_context())
.write(self.view.datarecord.id, text,
{ context : { 'lang': code }});
self.view.dataset.get_context()).write(
self.view.datarecord.id, text,
{ context : { 'lang': code }});
}); });
}); });
this.close(); this.close();
@ -226,4 +220,5 @@ return {
translateDialog: translateDialog, translateDialog: translateDialog,
}; };
}); // odoo.define
});

25
web_translate_dialog/view/web_translate.xml

@ -1,18 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2012 Guewen Baconnier (Camptocamp SA) <!-- Copyright 2012 Guewen Baconnier (Camptocamp SA)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<openerp>
<data>
<template id="assets_backend" name="web_translate_dialog assets"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/web_translate_dialog/static/src/js/web_translate_dialog.js"/>
<link rel="stylesheet" id="translate-dialog-stylesheet"
href="/web_translate_dialog/static/src/css/base.css"/>
</xpath>
</template>
</data>
</openerp>
<odoo>
<template id="assets_backend" name="web_translate_dialog assets"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/web_translate_dialog/static/src/js/web_translate_dialog.js"/>
<link rel="stylesheet" id="translate-dialog-stylesheet"
href="/web_translate_dialog/static/src/css/base.css"/>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save