forked from Techsystech/web
Refactor to display only existing translations
parent
31cf928dfe
commit
f814a950de
|
@ -1,3 +1,4 @@
|
||||||
# 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).
|
||||||
|
from . import models
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
# Copyright 2019 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||||
|
from odoo import models, api
|
||||||
|
|
||||||
|
|
||||||
|
class BaseModel(models.BaseModel):
|
||||||
|
|
||||||
|
_inherit = 'base'
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def get_field_translations(self, field_name):
|
||||||
|
"""Get only the existing translations for specified field
|
||||||
|
|
||||||
|
:param field_name: Name of the field
|
||||||
|
:return: dict of
|
||||||
|
{self.id: {'lang_code': (ir.translation,id, ir.translation,value)}}
|
||||||
|
"""
|
||||||
|
read_res = self.with_context(lang='en_US').read(fields=[field_name])
|
||||||
|
res = {
|
||||||
|
rec.get('id'): {'en_US': (0, rec.get(field_name))}
|
||||||
|
for rec in read_res
|
||||||
|
}
|
||||||
|
for rec_id, values in res.items():
|
||||||
|
tr_read_res = self.env['ir.translation'].search_read([
|
||||||
|
('name', '=', '%s,%s' % (self._name, field_name)),
|
||||||
|
('res_id', '=', rec_id)
|
||||||
|
])
|
||||||
|
for tr_res in tr_read_res:
|
||||||
|
if tr_res.get('lang') == 'en_US':
|
||||||
|
continue
|
||||||
|
values[tr_res.get('lang')] = (
|
||||||
|
tr_res.get('id'), tr_res.get('value')
|
||||||
|
)
|
||||||
|
return res
|
|
@ -2,3 +2,4 @@
|
||||||
* Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
* Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||||
* Serpent Consulting Services Pvt. Ltd. <jay.vora@serpentcs.com>
|
* Serpent Consulting Services Pvt. Ltd. <jay.vora@serpentcs.com>
|
||||||
* Timon Tschanz <timon.tschanz@camptocamp.ch>
|
* Timon Tschanz <timon.tschanz@camptocamp.ch>
|
||||||
|
* Akim Juillerat <akim.juillerat@camptocamp.com>
|
||||||
|
|
|
@ -34,7 +34,7 @@ var translateDialog = Dialog.extend({
|
||||||
this.view_type = parent.viewType || '';
|
this.view_type = parent.viewType || '';
|
||||||
this.$view_form = null;
|
this.$view_form = null;
|
||||||
this.$sidebar_form = null;
|
this.$sidebar_form = null;
|
||||||
this.translatable_fields = [event_data.fieldName];
|
this.translatable_field = event_data.fieldName;
|
||||||
this.res_id = res_id;
|
this.res_id = res_id;
|
||||||
this.languages = null;
|
this.languages = null;
|
||||||
this.languages_loaded = $.Deferred();
|
this.languages_loaded = $.Deferred();
|
||||||
|
@ -68,46 +68,46 @@ var translateDialog = Dialog.extend({
|
||||||
},
|
},
|
||||||
initialize_html_fields: function(lang) {
|
initialize_html_fields: function(lang) {
|
||||||
var self = this;
|
var self = this;
|
||||||
_.each(this.translatable_fields, function(f) {
|
|
||||||
// Initialize summernote if HTML field
|
// Initialize summernote if HTML field
|
||||||
self.$el.find('.oe_form_field_html .oe_translation_field[name="' + lang.code + '-' + f + '"]').each(function() {
|
this.$el.find('.oe_form_field_html .oe_translation_field[name="' + lang + '-' + this.translatable_field + '"]').each(function() {
|
||||||
var $parent = $(this).summernote({
|
var $parent = $(this).summernote({
|
||||||
'focus': false,
|
'focus': false,
|
||||||
'toolbar': [
|
'toolbar': [
|
||||||
['style', ['style']],
|
['style', ['style']],
|
||||||
['font', ['bold', 'italic', 'underline', 'clear']],
|
['font', ['bold', 'italic', 'underline', 'clear']],
|
||||||
['fontsize', ['fontsize']],
|
['fontsize', ['fontsize']],
|
||||||
['color', ['color']],
|
['color', ['color']],
|
||||||
['para', ['ul', 'ol', 'paragraph']],
|
['para', ['ul', 'ol', 'paragraph']],
|
||||||
['table', ['table']],
|
['table', ['table']],
|
||||||
['insert', ['link', 'picture']],
|
['insert', ['link', 'picture']],
|
||||||
['misc', ['codeview']],
|
['misc', ['codeview']],
|
||||||
['history', ['undo', 'redo']]
|
['history', ['undo', 'redo']]
|
||||||
],
|
],
|
||||||
'prettifyHtml': false,
|
'prettifyHtml': false,
|
||||||
'styleWithSpan': false,
|
'styleWithSpan': false,
|
||||||
'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
|
||||||
$parent.find('.note-editable').trigger('mouseup');
|
$parent.find('.note-editable').trigger('mouseup');
|
||||||
$parent.find('.note-editing-area').css({
|
$parent.find('.note-editing-area').css({
|
||||||
minHeight:'100px',
|
minHeight:'100px',
|
||||||
minWidth:'260px',
|
minWidth:'260px',
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
set_fields_values: function(lang, values) {
|
set_fields_values: function(lang, tr_value) {
|
||||||
var self = this;
|
var self = this;
|
||||||
_.each(this.translatable_fields, function(f) {
|
|
||||||
self.$el.find('.oe_translation_field[name="' + lang.code +
|
this.$el.find('.oe_translation_field[name="' + lang +
|
||||||
'-' + f + '"]').val(values[f] || '').attr(
|
'-' + this.translatable_field + '"]').val(tr_value || '').attr(
|
||||||
'data-value', values[f] || '');
|
'data-value', tr_value || '');
|
||||||
});
|
|
||||||
var textarea = this.$el.find('textarea.oe_translation_field');
|
var textarea = this.$el.find('textarea.oe_translation_field');
|
||||||
if (textarea !== undefined && textarea[0] !== undefined) {
|
if (textarea !== undefined && textarea[0] !== undefined) {
|
||||||
textarea.css({minHeight:'100px',});
|
textarea.css({minHeight:'100px',});
|
||||||
|
@ -121,29 +121,28 @@ var translateDialog = Dialog.extend({
|
||||||
deferred = [];
|
deferred = [];
|
||||||
|
|
||||||
this.$el.find('.oe_translation_field').val('').removeClass('touched');
|
this.$el.find('.oe_translation_field').val('').removeClass('touched');
|
||||||
_.each(self.languages, function(lg) {
|
|
||||||
var context = new Context(session.user_context, {lang: lg.code});
|
var deff = $.Deferred();
|
||||||
var deff = $.Deferred();
|
deferred.push(deff);
|
||||||
deferred.push(deff);
|
rpc.query({
|
||||||
rpc.query({
|
|
||||||
model: self.view.modelName,
|
model: self.view.modelName,
|
||||||
method: 'read',
|
method: 'get_field_translations',
|
||||||
args: [
|
args: [
|
||||||
[self.res_id],
|
[self.res_id],
|
||||||
],
|
],
|
||||||
kwargs: {
|
kwargs: {
|
||||||
fields: self.translatable_fields,
|
field_name: self.translatable_field,
|
||||||
context: context.eval(),
|
|
||||||
},
|
},
|
||||||
}).done(
|
}).done(
|
||||||
function (rows) {
|
function (res) {
|
||||||
|
if (res[self.res_id]){
|
||||||
if (rows[0]){
|
_.each(res[self.res_id], function(translation, lang) {
|
||||||
self.set_fields_values(lg, rows[0]);
|
self.set_fields_values(lang, translation[1]);
|
||||||
deff.resolve();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
deff.resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return deferred;
|
return deferred;
|
||||||
},
|
},
|
||||||
on_button_save: function() {
|
on_button_save: function() {
|
||||||
|
@ -193,7 +192,7 @@ FormView.include({
|
||||||
if (this.sidebar) {
|
if (this.sidebar) {
|
||||||
this.sidebar.add_items('other', _.compact([
|
this.sidebar.add_items('other', _.compact([
|
||||||
this.is_action_enabled('edit') &&
|
this.is_action_enabled('edit') &&
|
||||||
this.translatable_fields.length > 0 && {
|
this.translatable_field && {
|
||||||
label: _t('Translate'),
|
label: _t('Translate'),
|
||||||
callback: this.on_button_translate
|
callback: this.on_button_translate
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<t t-name="TranslateDialog">
|
<t t-name="TranslateDialog">
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<table t-if="widget.translatable_fields"
|
<table t-if="widget.translatable_field"
|
||||||
class="oe_frame oe_forms oe_translation_form"
|
class="oe_frame oe_forms oe_translation_form"
|
||||||
border="0" cellpadding="0" cellspacing="0" width="100%">
|
border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
<div class="separator horizontal"><t t-esc="name"/></div>
|
<div class="separator horizontal"><t t-esc="name"/></div>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
<t t-foreach="widget.translatable_fields" t-as="field_name">
|
<t t-value="widget.translatable_field" t-set="field_name" />
|
||||||
<t t-set="field" t-value="widget.view.searchView.fields[field_name]" />
|
<t t-set="field" t-value="widget.view.searchView.fields[field_name]" />
|
||||||
<tr t-att-data-field="field_name">
|
<tr t-att-data-field="field_name">
|
||||||
<td class="oe_form_frame_cell" width="1%" nowrap="nowrap">
|
<td class="oe_form_frame_cell" width="1%" nowrap="nowrap">
|
||||||
|
@ -36,7 +36,6 @@
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</t>
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
Loading…
Reference in New Issue