|
@ -1,90 +1,95 @@ |
|
|
openerp.web_translate_dialog_page = function (openerp) { |
|
|
|
|
|
|
|
|
openerp.web_translate_dialog_page = function (instance) { |
|
|
|
|
|
|
|
|
var _t = openerp.web._t; |
|
|
|
|
|
var QWeb = openerp.web.qweb; |
|
|
|
|
|
|
|
|
"use strict"; |
|
|
|
|
|
|
|
|
openerp.web.PageView.include({ |
|
|
|
|
|
on_loaded: function(data) { |
|
|
|
|
|
|
|
|
var QWeb = instance.web.qweb, |
|
|
|
|
|
_t = instance.web._t, |
|
|
|
|
|
_lt = instance.web._lt; |
|
|
|
|
|
|
|
|
|
|
|
instance.web.FormView.include({ |
|
|
|
|
|
load_form: function(data) { |
|
|
this._super(data); |
|
|
this._super(data); |
|
|
this.$form_header.find('button.oe_form_button_translate').click(this.on_button_translate); |
|
|
|
|
|
|
|
|
this.$buttons.on('click', '.oe_form_button_translate', |
|
|
|
|
|
this.guard_active(this.on_button_translate)); |
|
|
}, |
|
|
}, |
|
|
on_button_translate: function() { |
|
|
on_button_translate: function() { |
|
|
var self = this; |
|
|
var self = this; |
|
|
$.when(this.has_been_loaded).then(function() { |
|
|
$.when(this.has_been_loaded).then(function() { |
|
|
self.open_translate_dialog(this); |
|
|
self.open_translate_dialog(this); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
}, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
openerp.web.View.include({ |
|
|
|
|
|
// Replace the translation dialog by the new one
|
|
|
|
|
|
open_translate_dialog: function(field) { |
|
|
|
|
|
if (!this.translate_dialog) { |
|
|
|
|
|
this.translate_dialog = new openerp.web_translate_dialog_page.TranslateDialogPage(this).start(); |
|
|
|
|
|
} |
|
|
|
|
|
this.translate_dialog.open(field); |
|
|
|
|
|
|
|
|
instance.web.View.include({ |
|
|
|
|
|
open_translate_dialog: function() { |
|
|
|
|
|
new instance.web_translate_dialog_page.TranslateDialogPage(this).open(); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// completely redefine the translation dialog because we can
|
|
|
|
|
|
// not completely tie the standard one to our needs by sub-classing
|
|
|
|
|
|
openerp.web_translate_dialog_page.TranslateDialogPage = openerp.web.Dialog.extend({ |
|
|
|
|
|
|
|
|
instance.web_translate_dialog_page.TranslateDialogPage = instance.web.Dialog.extend({ |
|
|
|
|
|
template: "TranslateDialogPage", |
|
|
dialog_title: {toString: function () { return _t("Translations"); }}, |
|
|
dialog_title: {toString: function () { return _t("Translations"); }}, |
|
|
init: function(view) { |
|
|
|
|
|
this.view_language = view.session.user_context.lang; |
|
|
|
|
|
this['on_button_' + _t("Save")] = this.on_btn_save; |
|
|
|
|
|
this['on_button_' + _t("Close")] = this.on_btn_close; |
|
|
|
|
|
this._super(view, { |
|
|
|
|
|
width: '80%', |
|
|
|
|
|
height: '90%' |
|
|
|
|
|
}); |
|
|
|
|
|
this.view = view; |
|
|
|
|
|
this.view_type = view.fields_view.type || ''; |
|
|
|
|
|
this.$fields_form = null; |
|
|
|
|
|
|
|
|
init: function(parent, options, content) { |
|
|
|
|
|
this._super(parent, options, content); |
|
|
|
|
|
this.view_language = this.session.user_context.lang; |
|
|
|
|
|
this.view = parent; |
|
|
|
|
|
this.view_type = parent.fields_view.type || ''; |
|
|
this.$view_form = null; |
|
|
this.$view_form = null; |
|
|
this.$sidebar_form = null; |
|
|
this.$sidebar_form = null; |
|
|
this.translatable_fields_keys = _.map(this.view.translatable_fields || [], function(i) { return i.name;}); |
|
|
this.translatable_fields_keys = _.map(this.view.translatable_fields || [], function(i) { return i.name;}); |
|
|
this.languages = null; |
|
|
this.languages = null; |
|
|
this.languages_loaded = $.Deferred(); |
|
|
this.languages_loaded = $.Deferred(); |
|
|
(new openerp.web.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(), |
|
|
|
|
|
[['translatable', '=', '1']])).read_slice(['code', 'name'], { sort: 'id' }).then(this.on_languages_loaded); |
|
|
|
|
|
|
|
|
(new instance.web.DataSetSearch(this, |
|
|
|
|
|
'res.lang', |
|
|
|
|
|
this.view.dataset.get_context(), |
|
|
|
|
|
[['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(); |
|
|
}, |
|
|
}, |
|
|
start: function() { |
|
|
|
|
|
var self = this; |
|
|
|
|
|
this._super(); |
|
|
|
|
|
|
|
|
open: function() { |
|
|
|
|
|
var self = this, |
|
|
|
|
|
sup = this._super; |
|
|
|
|
|
// the template needs the languages
|
|
|
$.when(this.languages_loaded).then(function() { |
|
|
$.when(this.languages_loaded).then(function() { |
|
|
self.$element.html(QWeb.render('TranslateDialogPage', { widget: self })); |
|
|
|
|
|
self.$fields_form = self.$element.find('.oe_translation_form'); |
|
|
|
|
|
self.$fields_form.find('.oe_trad_field').change(function() { |
|
|
|
|
|
$(this).toggleClass('touched', ($(this).val() != $(this).attr('data-value'))); |
|
|
|
|
|
}); |
|
|
|
|
|
var $textarea = self.$fields_form.find('textarea.oe_trad_field'); |
|
|
|
|
|
$textarea.addClass('autosizeAnimated').autosize({append: "\n"}); |
|
|
|
|
|
$textarea.css({minHeight:'100px'}); |
|
|
|
|
|
|
|
|
// if (self.view.translatable_fields && self.view.translatable_fields.length) {
|
|
|
|
|
|
return sup.call(self); |
|
|
}); |
|
|
}); |
|
|
return this; |
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
start: function() { |
|
|
|
|
|
var self = this; |
|
|
|
|
|
self.$el.find('.oe_trad_field').change(function() { |
|
|
|
|
|
$(this).toggleClass('touched', ($(this).val() != $(this).attr('data-value'))); |
|
|
|
|
|
}); |
|
|
|
|
|
this.$buttons.html(QWeb.render("TranslateDialogPage.buttons")); |
|
|
|
|
|
this.$buttons.find(".oe_form_translate_dialog_save_button").click(function(){ |
|
|
|
|
|
self.on_button_save(); |
|
|
|
|
|
self.on_button_close(); |
|
|
|
|
|
}); |
|
|
|
|
|
this.$buttons.find(".oe_form_translate_dialog_cancel_button").click(function(){ |
|
|
|
|
|
self.on_button_close(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
self.do_load_fields_values(); |
|
|
|
|
|
// var $textarea = self.$el.find('textarea.oe_trad_field');
|
|
|
|
|
|
// $textarea.addClass('autosizeAnimated').autosize({append: "\n"});
|
|
|
|
|
|
// $textarea.css({minHeight:'100px'});
|
|
|
|
|
|
}, |
|
|
// use a `read_translations` method instead of a `read`
|
|
|
// use a `read_translations` method instead of a `read`
|
|
|
// this latter leave the fields empty if there is no
|
|
|
// this latter leave the fields empty if there is no
|
|
|
// translation for a field instead of taking the src field
|
|
|
// translation for a field instead of taking the src field
|
|
|
do_load_fields_values: function(callback) { |
|
|
do_load_fields_values: function(callback) { |
|
|
var self = this, |
|
|
var self = this, |
|
|
deffered = []; |
|
|
|
|
|
|
|
|
deferred = []; |
|
|
|
|
|
|
|
|
this.$fields_form.find('.oe_trad_field').val('').removeClass('touched'); |
|
|
|
|
|
|
|
|
this.$el.find('.oe_trad_field').val('').removeClass('touched'); |
|
|
_.each(self.languages, function(lg) { |
|
|
_.each(self.languages, function(lg) { |
|
|
var deff = $.Deferred(); |
|
|
var deff = $.Deferred(); |
|
|
deffered.push(deff); |
|
|
|
|
|
|
|
|
deferred.push(deff); |
|
|
var callback = function(values) { |
|
|
var callback = function(values) { |
|
|
_.each(self.translatable_fields_keys, function(f) { |
|
|
|
|
|
self.$fields_form.find('.oe_trad_field[name="' + lg.code + '-' + f + '"]').val(values[0][f] || '').attr('data-value', values[0][f] || ''); |
|
|
|
|
|
}); |
|
|
|
|
|
deff.resolve(); |
|
|
|
|
|
}; |
|
|
}; |
|
|
self.view.dataset.call( |
|
|
self.view.dataset.call( |
|
|
'read_translations', |
|
|
'read_translations', |
|
@ -92,29 +97,22 @@ openerp.web_translate_dialog_page = function (openerp) { |
|
|
self.translatable_fields_keys, |
|
|
self.translatable_fields_keys, |
|
|
self.view.dataset.get_context({ |
|
|
self.view.dataset.get_context({ |
|
|
'lang': lg.code |
|
|
'lang': lg.code |
|
|
})], callback); |
|
|
|
|
|
|
|
|
})]).done(function (values) { |
|
|
|
|
|
_.each(self.translatable_fields_keys, function(f) { |
|
|
|
|
|
self.$el.find('.oe_trad_field[name="' + lg.code + '-' + f + '"]') |
|
|
|
|
|
.val(values[0][f] || '') |
|
|
|
|
|
.attr('data-value', values[0][f] || ''); |
|
|
|
|
|
}); |
|
|
|
|
|
deff.resolve(); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
$.when.apply(null, deffered).then(callback); |
|
|
|
|
|
|
|
|
return deferred; |
|
|
}, |
|
|
}, |
|
|
open: function(field) { |
|
|
|
|
|
var self = this, |
|
|
|
|
|
sup = this._super; |
|
|
|
|
|
$.when(this.languages_loaded).then(function() { |
|
|
|
|
|
if (self.view.translatable_fields && self.view.translatable_fields.length) { |
|
|
|
|
|
self.do_load_fields_values(function() { |
|
|
|
|
|
sup.call(self); |
|
|
|
|
|
$(window).resize(); |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
sup.call(self); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
on_btn_save: function() { |
|
|
|
|
|
|
|
|
on_button_save: function() { |
|
|
var trads = {}, |
|
|
var trads = {}, |
|
|
self = this, |
|
|
self = this, |
|
|
trads_mutex = new $.Mutex(); |
|
|
trads_mutex = new $.Mutex(); |
|
|
self.$fields_form.find('.oe_trad_field.touched').each(function() { |
|
|
|
|
|
|
|
|
self.$el.find('.oe_trad_field.touched').each(function() { |
|
|
var field = $(this).attr('name').split('-'); |
|
|
var field = $(this).attr('name').split('-'); |
|
|
if (!trads[field[0]]) { |
|
|
if (!trads[field[0]]) { |
|
|
trads[field[0]] = {}; |
|
|
trads[field[0]] = {}; |
|
@ -128,15 +126,22 @@ openerp.web_translate_dialog_page = function (openerp) { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
trads_mutex.exec(function() { |
|
|
trads_mutex.exec(function() { |
|
|
return new openerp.web.DataSet(self, self.view.dataset.model, self.view.dataset.get_context()).write(self.view.datarecord.id, data, { context : { 'lang': code }}); |
|
|
|
|
|
|
|
|
return new instance.web.DataSet(self, self.view.dataset.model, self.view.dataset.get_context()).write(self.view.datarecord.id, data, { context : { 'lang': code }}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
this.close(); |
|
|
this.close(); |
|
|
}, |
|
|
}, |
|
|
on_btn_close: function() { |
|
|
|
|
|
|
|
|
on_button_close: function() { |
|
|
this.close(); |
|
|
this.close(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
instance.web.form.AbstractField.include({ |
|
|
|
|
|
on_translate: function() { |
|
|
|
|
|
// the image next to the fields opens the translate dialog
|
|
|
|
|
|
this.view.open_translate_dialog(); |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|