[REM] Removed TranslateDialog. Use ir.translation#translate() instead
bzr revid: fme@openerp.com-20120830161237-twthb37lkbv6yn3t
This commit is contained in:
parent
3fea5ea545
commit
42f184bf6f
|
@ -22,10 +22,6 @@ instance.web.form.FieldManagerMixin = {
|
||||||
* Must return the asked field as in fields_get.
|
* Must return the asked field as in fields_get.
|
||||||
*/
|
*/
|
||||||
get_field: function(field_name) {},
|
get_field: function(field_name) {},
|
||||||
/**
|
|
||||||
* Called by the field when the translate button is clicked.
|
|
||||||
*/
|
|
||||||
open_translate_dialog: function(field) {},
|
|
||||||
/**
|
/**
|
||||||
* Returns true when the view is in create mode.
|
* Returns true when the view is in create mode.
|
||||||
*/
|
*/
|
||||||
|
@ -1049,9 +1045,6 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||||
is_create_mode: function() {
|
is_create_mode: function() {
|
||||||
return this.get("actual_mode") === "create";
|
return this.get("actual_mode") === "create";
|
||||||
},
|
},
|
||||||
open_translate_dialog: function(field) {
|
|
||||||
return this._super(field);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1882,6 +1875,10 @@ instance.web.form.FieldInterface = {
|
||||||
* Must set the focus on the field. Return false if field is not focusable.
|
* Must set the focus on the field. Return false if field is not focusable.
|
||||||
*/
|
*/
|
||||||
focus: function() {},
|
focus: function() {},
|
||||||
|
/**
|
||||||
|
* Called when the translate button is clicked.
|
||||||
|
*/
|
||||||
|
on_translate: function() {},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1936,9 +1933,7 @@ instance.web.form.AbstractField = instance.web.form.FormWidget.extend(instance.w
|
||||||
this._super();
|
this._super();
|
||||||
if (this.field.translate) {
|
if (this.field.translate) {
|
||||||
this.$el.addClass('oe_form_field_translatable');
|
this.$el.addClass('oe_form_field_translatable');
|
||||||
this.$el.find('.oe_field_translate').click(_.bind(function() {
|
this.$el.find('.oe_field_translate').click(this.on_translate);
|
||||||
this.field_manager.open_translate_dialog(this);
|
|
||||||
}, this));
|
|
||||||
}
|
}
|
||||||
this.$label = this.view.$el.find('label[for=' + this.id_for_label + ']');
|
this.$label = this.view.$el.find('label[for=' + this.id_for_label + ']');
|
||||||
if (instance.session.debug) {
|
if (instance.session.debug) {
|
||||||
|
@ -2000,6 +1995,13 @@ instance.web.form.AbstractField = instance.web.form.FormWidget.extend(instance.w
|
||||||
set_input_id: function(id) {
|
set_input_id: function(id) {
|
||||||
this.id_for_label = id;
|
this.id_for_label = id;
|
||||||
},
|
},
|
||||||
|
on_translate: function() {
|
||||||
|
var self = this;
|
||||||
|
var trans = new instance.web.DataSet(this, 'ir.translation', this.view.dataset.get_context());
|
||||||
|
return trans.call('translate', [this.view.dataset.model, this.view.datarecord.id, this.name]).then(function(action) {
|
||||||
|
self.do_action(action);
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1050,119 +1050,6 @@ instance.web.Sidebar = instance.web.Widget.extend({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.web.TranslateDialog = instance.web.Dialog.extend({
|
|
||||||
dialog_title: {toString: function () { return _t("Translations"); }},
|
|
||||||
init: function(view) {
|
|
||||||
// TODO fme: should add the language to fields_view_get because between the fields view get
|
|
||||||
// and the moment the user opens the translation dialog, the user language could have been changed
|
|
||||||
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: '80%',
|
|
||||||
destroy_on_close: false,
|
|
||||||
});
|
|
||||||
this.view = view;
|
|
||||||
this.view_type = view.fields_view.type || '';
|
|
||||||
this.$fields_form = null;
|
|
||||||
this.$view_form = null;
|
|
||||||
this.$sidebar_form = null;
|
|
||||||
this.translatable_fields_keys = _.map(this.view.translatable_fields || [], function(i) { return i.name; });
|
|
||||||
this.languages = null;
|
|
||||||
this.languages_loaded = $.Deferred();
|
|
||||||
(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);
|
|
||||||
},
|
|
||||||
start: function() {
|
|
||||||
var self = this;
|
|
||||||
this._super();
|
|
||||||
return $.when(this.languages_loaded).then(function() {
|
|
||||||
self.$el.html(instance.web.qweb.render('TranslateDialog', { widget: self }));
|
|
||||||
self.$fields_form = self.$el.find('.oe_translation_form');
|
|
||||||
self.$fields_form.find('.oe_trad_field').change(function() {
|
|
||||||
$(this).toggleClass('touched', ($(this).val() != $(this).attr('data-value')));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
on_languages_loaded: function(langs) {
|
|
||||||
this.languages = langs;
|
|
||||||
this.languages_loaded.resolve();
|
|
||||||
},
|
|
||||||
do_load_fields_values: function(callback) {
|
|
||||||
var self = this,
|
|
||||||
deffered = [];
|
|
||||||
this.$fields_form.find('.oe_trad_field').val('').removeClass('touched');
|
|
||||||
_.each(self.languages, function(lg) {
|
|
||||||
var deff = $.Deferred();
|
|
||||||
deffered.push(deff);
|
|
||||||
var callback = function(values) {
|
|
||||||
_.each(self.translatable_fields_keys, function(f) {
|
|
||||||
var value = values[0][f] || '';
|
|
||||||
self.$fields_form.find('.oe_trad_field[name="' + lg.code + '-' + f + '"]').val(value).attr('data-value', value);
|
|
||||||
});
|
|
||||||
deff.resolve();
|
|
||||||
};
|
|
||||||
if (lg.code === self.view_language) {
|
|
||||||
var values = {};
|
|
||||||
_.each(self.translatable_fields_keys, function(field) {
|
|
||||||
values[field] = self.view.fields[field].get_value();
|
|
||||||
});
|
|
||||||
callback([values]);
|
|
||||||
} else {
|
|
||||||
self.view.dataset.read_ids([self.view.datarecord.id], self.translatable_fields_keys, {
|
|
||||||
context: { 'lang': lg.code }
|
|
||||||
}).then(callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$.when.apply(null, deffered).then(callback);
|
|
||||||
},
|
|
||||||
open: function(field) {
|
|
||||||
var self = this;
|
|
||||||
this._super();
|
|
||||||
$.when(this.languages_loaded).then(function() {
|
|
||||||
if (self.view.translatable_fields && self.view.translatable_fields.length) {
|
|
||||||
self.do_load_fields_values(function() {
|
|
||||||
if (field) {
|
|
||||||
var $field_input = self.$el.find('tr[data-field="' + field.name + '"] td:nth-child(2) *:first-child');
|
|
||||||
self.$el.scrollTo($field_input);
|
|
||||||
$field_input.focus();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
sup.call(self);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
on_btn_save: function() {
|
|
||||||
var trads = {};
|
|
||||||
var self = this;
|
|
||||||
var trads_mutex = new $.Mutex();
|
|
||||||
self.$fields_form.find('.oe_trad_field.touched').each(function() {
|
|
||||||
var field = $(this).attr('name').split('-');
|
|
||||||
if (!trads[field[0]]) {
|
|
||||||
trads[field[0]] = {};
|
|
||||||
}
|
|
||||||
trads[field[0]][field[1]] = $(this).val();
|
|
||||||
});
|
|
||||||
_.each(trads, function(data, code) {
|
|
||||||
if (code === self.view_language) {
|
|
||||||
_.each(data, function(value, field) {
|
|
||||||
self.view.fields[field].set_value(value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
trads_mutex.exec(function() {
|
|
||||||
return self.view.dataset.write(self.view.datarecord.id, data, { context : { 'lang': code } });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
this.close();
|
|
||||||
return trads_mutex;
|
|
||||||
},
|
|
||||||
on_btn_close: function() {
|
|
||||||
this.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
instance.web.View = instance.web.Widget.extend({
|
instance.web.View = instance.web.Widget.extend({
|
||||||
// name displayed in view switchers
|
// name displayed in view switchers
|
||||||
display_name: '',
|
display_name: '',
|
||||||
|
@ -1214,12 +1101,6 @@ instance.web.View = instance.web.Widget.extend({
|
||||||
action_views_ids: {}
|
action_views_ids: {}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
open_translate_dialog: function(field) {
|
|
||||||
if (!this.translate_dialog) {
|
|
||||||
this.translate_dialog = new instance.web.TranslateDialog(this);
|
|
||||||
}
|
|
||||||
this.translate_dialog.open(field);
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* Fetches and executes the action identified by ``action_data``.
|
* Fetches and executes the action identified by ``action_data``.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1202,28 +1202,6 @@
|
||||||
</t>
|
</t>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="TranslateDialog">
|
|
||||||
<table t-if="widget.view.translatable_fields" class="oe_form oe_translation_form" border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
||||||
<tr>
|
|
||||||
<td class="oe_form_separator" width="1%" nowrap="nowrap">
|
|
||||||
<div class="oe_horizontal_separator">Field</div>
|
|
||||||
</td>
|
|
||||||
<th t-foreach="widget.languages" align="left">
|
|
||||||
<div class="oe_horizontal_separator"><t t-esc="name"/></div>
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
<tr t-foreach="widget.view.translatable_fields" t-as="field" t-att-data-field="field.name">
|
|
||||||
<td class="oe_form_group_cell" width="1%" nowrap="nowrap">
|
|
||||||
<label class="oe_label"><t t-esc="field.string"/>:</label>
|
|
||||||
</td>
|
|
||||||
<td t-foreach="widget.languages" t-as="lg" class="oe_form_group_cell">
|
|
||||||
<input t-if="field.field.type == 'char'" type="text" t-attf-name="#{lg.code}-#{field.name}" value="" data-value="" class="oe_trad_field" style="width: 100%"/>
|
|
||||||
<textarea t-if="field.field.type == 'text'" t-attf-name="#{lg.code}-#{field.name}" data-value="" class="oe_trad_field" style="width: 100%"></textarea>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</t>
|
|
||||||
|
|
||||||
<t t-name="AbstractFormPopup.render">
|
<t t-name="AbstractFormPopup.render">
|
||||||
<div>
|
<div>
|
||||||
<table style="width:100%">
|
<table style="width:100%">
|
||||||
|
|
Loading…
Reference in New Issue