summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2015-12-21 11:37:53 +0100
committerMartin Trigaux <mat@odoo.com>2015-12-21 11:37:53 +0100
commite4bf03aeaf2c8200164c27f0d93994e2c173bded (patch)
treeabce75b917f931d042dba1e34060efd625f90ed7 /addons/web_editor/static/src
parent82a495eed52a9f42e5b88caa52c20a85f8d81ce3 (diff)
parentc298cf3250fcfa351775dc57c3b913169e30e418 (diff)
[MERGE] Forward port of branch saas-7 up to c298cf3
Diffstat (limited to 'addons/web_editor/static/src')
-rw-r--r--addons/web_editor/static/src/js/backend.js4
-rw-r--r--addons/web_editor/static/src/js/rte.js10
-rw-r--r--addons/web_editor/static/src/js/rte.summernote.js1
-rw-r--r--addons/web_editor/static/src/js/summernote.js18
-rw-r--r--addons/web_editor/static/src/js/translator.js36
5 files changed, 52 insertions, 17 deletions
diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js
index 0cd7541c7e2..17a2df31c6e 100644
--- a/addons/web_editor/static/src/js/backend.js
+++ b/addons/web_editor/static/src/js/backend.js
@@ -97,8 +97,8 @@ var FieldTextHtmlSimple = widget.extend({
if (value.match(/^\s*$/)) {
value = '<p><br/></p>';
} else {
- value = "<p>"+value.split(/<br\/?>/).join("</p><p>")+"</p>";
- value = value.replace('<p><p>', '<p>').replace('</p></p>', '</p>');
+ value = "<p>"+value.split(/<br\/?>/).join("<br/></p><p>")+"</p>";
+ value = value.replace(/<p><\/p>/g, '').replace('<p><p>', '<p>').replace('</p></p>', '</p>');
}
return value;
},
diff --git a/addons/web_editor/static/src/js/rte.js b/addons/web_editor/static/src/js/rte.js
index c107ca342ae..f50b93912ae 100644
--- a/addons/web_editor/static/src/js/rte.js
+++ b/addons/web_editor/static/src/js/rte.js
@@ -508,6 +508,16 @@ var RTE = Widget.extend({
var $target = $(event.target);
var $editable = $target.closest('.o_editable');
+ if ($target.is('a')) {
+ $target.attr('contenteditable', true);
+ setTimeout(function () {
+ $editable.attr('contenteditable', false);
+ });
+ } else if ($editable.attr('contenteditable') === 'false') {
+ $target.removeAttr('contenteditable');
+ $editable.attr('contenteditable', true);
+ }
+
if (!$editable.size()) {
return;
}
diff --git a/addons/web_editor/static/src/js/rte.summernote.js b/addons/web_editor/static/src/js/rte.summernote.js
index ca7d97ffd82..01020a84c22 100644
--- a/addons/web_editor/static/src/js/rte.summernote.js
+++ b/addons/web_editor/static/src/js/rte.summernote.js
@@ -772,6 +772,7 @@ eventHandler.attach = function (oLayoutInfo, options) {
var fn_detach = eventHandler.detach;
eventHandler.detach = function (oLayoutInfo, options) {
fn_detach.call(this, oLayoutInfo, options);
+ oLayoutInfo.editable().off('mousedown');
oLayoutInfo.editor().off("dragstart");
oLayoutInfo.editor().off('click');
$(document).off('mousedown', summernote_mousedown);
diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js
index ff509800c50..14db16a831c 100644
--- a/addons/web_editor/static/src/js/summernote.js
+++ b/addons/web_editor/static/src/js/summernote.js
@@ -1115,7 +1115,7 @@ $.summernote.pluginEvents.enter = function (event, editor, layoutInfo) {
$(node).html(br);
node = br;
} else {
- node = dom.splitTree(last, {'node': r.sc, 'offset': r.so});
+ node = dom.splitTree(last, {'node': r.sc, 'offset': r.so}) || r.sc;
if (!contentBefore) {
var cur = dom.node(dom.lastChild(node.previousSibling));
if (!dom.isBR(cur)) {
@@ -2298,7 +2298,7 @@ function summernote_paste (event) {
// keep norma feature if copy a picture
var clipboardData = event.originalEvent.clipboardData;
- if (clipboardData.items) {
+ if (!_.isEmpty(clipboardData.items)) {
var item = list.last(clipboardData.items);
var isClipboardImage = item.kind === 'file' && item.type.indexOf('image/') !== -1;
if (isClipboardImage) {
@@ -2336,8 +2336,8 @@ function summernote_paste (event) {
$node.find('*').each(function() {
var $node = $(this);
- if ($(this).attr('style')) {
- var style = _.filter($(this).attr('style').split(/\s*;\s*/), function (style) {
+ if ($node.attr('style')) {
+ var style = _.filter($node.attr('style').split(/\s*;\s*/), function (style) {
return /width|height|color|background-color|font-weight|text-align|font-style|text-decoration/i.test(style) && $node.css(style.split(':')[0]) !== $('body').css(style.split(':')[0]);
}).join(';');
if (style.length) {
@@ -2347,8 +2347,8 @@ function summernote_paste (event) {
}
}
- if ($(this).attr('class')) {
- var classes = _.filter($(this).attr('class').split(/\s+/), function (style) {
+ if ($node.attr('class')) {
+ var classes = _.filter($node.attr('class').split(/\s+/), function (style) {
return /(^|\s)(fa|pull|text|bg)(\s|-|$)/.test(style);
}).join(' ');
if (classes.length) {
@@ -2365,6 +2365,12 @@ function summernote_paste (event) {
$node.find('span:not([class]):not([style])').each(function () {
$(this).replaceWith($(this).contents());
});
+ $node.find('span + span').each(function () {
+ if ($(this).attr('class') === $(this).prev().attr('class') && $(this).attr('style') === $(this).prev().attr('style')) {
+ $(this).prev().append($(this).contents());
+ $(this).remove();
+ }
+ });
/*
reset architecture HTML node and add <p> tag
diff --git a/addons/web_editor/static/src/js/translator.js b/addons/web_editor/static/src/js/translator.js
index 0d41699c3f3..b9ed671020d 100644
--- a/addons/web_editor/static/src/js/translator.js
+++ b/addons/web_editor/static/src/js/translator.js
@@ -37,10 +37,12 @@ $.fn.extend({
var RTE_Translate = rte.Class.extend({
saveElement: function ($el, context) {
// remove multi edition
+ var key = $el.data('oe-translation-id') ? 'translation:'+$el.data('oe-translation-id') :
+ ($el.data('oe-model') ? $el.data('oe-model')+":"+$el.data('oe-id')+":"+$el.data('oe-field')+":"+$el.data('oe-type')+":"+$el.data('oe-expression') : false);
+ if (!key || this.__saved[key]) return true;
+ this.__saved[key] = true;
+
if ($el.data('oe-translation-id')) {
- var key = 'translation:'+$el.data('oe-translation-id');
- if (this.__saved[key]) return true;
- this.__saved[key] = true;
var translation_content = this.getEscapedElement($el).html();
return ajax.jsonRpc('/web/dataset/call', 'call', {
@@ -48,13 +50,24 @@ var RTE_Translate = rte.Class.extend({
method: 'write',
args: [
[+$el.data('oe-translation-id')],
- {value: translation_content, state: 'translated'},
+ {'value': translation_content, 'state': 'translated'},
context || base.get_context()
],
});
- }
+ } else {
+ var markup = this.getEscapedElement($el).prop('outerHTML');
- return this._super.apply(this, arguments);
+ return ajax.jsonRpc('/web/dataset/call', 'call', {
+ model: 'ir.ui.view',
+ method: 'save',
+ args: [
+ $el.data('oe-id'),
+ markup,
+ $el.data('oe-xpath') || null,
+ context || base.get_context()
+ ],
+ });
+ }
},
});
@@ -107,13 +120,16 @@ var Translate = Widget.extend({
return this.edit();
},
setTarget: function ($target) {
- this.$target = $target.find('[data-oe-translation-id], [data-oe-model][data-oe-id][data-oe-field]');
+ var $edit = $target.find('[data-oe-translation-id], [data-oe-model][data-oe-id][data-oe-field]');
+ $edit.filter(':has([data-oe-translation-id], [data-oe-model][data-oe-id][data-oe-field])').attr('data-oe-readonly', true);
+
+ this.$target = $edit.not('[data-oe-readonly]');
// attributes
var attrs = ['placeholder', 'title', 'alt'];
_.each(attrs, function (attr) {
- $target.find('['+attr+'*="data-oe-translation-id="]').each(function () {
+ $target.find('['+attr+'*="data-oe-translation-id="]').filter(':empty, input, select, textarea, img').each(function () {
var $node = $(this);
var translation = $node.data('translation') || {};
var trans = $node.attr(attr);
@@ -192,7 +208,7 @@ var Translate = Widget.extend({
}
event.preventDefault();
event.stopPropagation();
- if (event.type !== 'click') {
+ if (event.type !== 'mousedown') {
return;
}
@@ -302,6 +318,8 @@ if (edit_translations) {
$('form[action*=edit_translations]').each(function () {
this.action = this.action.replace(/[$?]edit_translations[^&?]+/, '');
});
+
+ $('title').html($('title').html().replace(/&lt;span data-oe-translation-id.+?&gt;(.+?)&lt;\/span&gt;/, '\$1'));
});
}