[FIX] Save translations and t-fields

bzr revid: fme@openerp.com-20130926131708-16xmpbrx0vxlgbtw
This commit is contained in:
Fabien Meghazi
2013-09-26 15:17:08 +02:00
parent da26fe77b9
commit 8c25a35cc6
2 changed files with 13 additions and 5 deletions
@@ -282,7 +282,7 @@
});
}).get();
return $.when.apply(null, defs).then(function () {
window.location.href = window.location.href.replace(/unable_editor(=[^&]*)?|#.*/g, '');
website.reload();
});
},
/**
@@ -8,6 +8,7 @@
website.EditorBar.include({
start: function () {
var self = this;
this.initial_content = {};
return this._super.apply(this, arguments).then(function () {
self.$('button[data-action=edit]').text("Translate");
self.$('[data-action=snippet]').hide();
@@ -70,12 +71,15 @@
if (ev.type == 'paste') {
self.sanitizeNode($node[0]);
}
if ($node.data('initial_content') !== $node.text()) {
if (self.getInitialContent($node[0]) !== $node.text()) {
$node.addClass('oe_dirty').removeClass('oe_translatable_todo');
}
}, 0);
});
},
getInitialContent: function (node) {
return this.initial_content[node.attributes['data-oe-nodeid'].value];
},
sanitizeNode: function (node) {
node.text(node.text());
},
@@ -99,9 +103,13 @@
node.className += ' oe_translatable_todo';
}
node.contentEditable = true;
$(node).data('initial_content', content);
var nid = _.uniqueId();
$(node).attr('data-oe-nodeid', nid);
this.initial_content[nid] = content;
},
save: function () {
var self = this;
var mysuper = this._super;
var trans = {};
// this._super.apply(this, arguments);
$('.oe_translatable_text.oe_dirty').each(function () {
@@ -111,7 +119,7 @@
trans[data.oeTranslationViewId] = [];
}
trans[data.oeTranslationViewId].push({
initial_content: data.initial_content,
initial_content: self.getInitialContent(this),
new_content: $node.text(),
translation_id: data.oeTranslationId || null
});
@@ -120,7 +128,7 @@
'data': trans,
'lang': website.get_context()['lang'],
}).then(function () {
website.reload();
mysuper.call(self);
}).fail(function () {
// TODO: bootstrap alert with error message
alert("Could not save translation");