summaryrefslogtreecommitdiff
path: root/addons/web_editor/static
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2016-09-30 17:23:30 +0200
committerChristophe Simonis <chs@odoo.com>2016-09-30 17:23:30 +0200
commitc8cc54559b75a621e4444ecdca6abd901b45e494 (patch)
tree92141325d4dbbf70bbfb8e0c040d4435c8d2378f /addons/web_editor/static
parentb2804b1d2ae5fd7ec5c0eca79a8db77476badc84 (diff)
parent91a14488250bc2bb405cc6d300359aa272642484 (diff)
[MERGE] forward port branch 10.0 up to 91a1448
Diffstat (limited to 'addons/web_editor/static')
-rw-r--r--addons/web_editor/static/src/js/ace.js63
-rw-r--r--addons/web_editor/static/src/js/backend.js4
-rw-r--r--addons/web_editor/static/src/js/editor.js2
-rw-r--r--addons/web_editor/static/src/js/iframe.js1
-rw-r--r--addons/web_editor/static/src/js/snippets.options.js2
-rw-r--r--addons/web_editor/static/src/js/transcoder.js29
-rw-r--r--addons/web_editor/static/src/js/widgets.js22
-rw-r--r--addons/web_editor/static/src/less/web_editor.ui.components.less57
-rw-r--r--addons/web_editor/static/src/less/web_editor.ui.less15
9 files changed, 136 insertions, 59 deletions
diff --git a/addons/web_editor/static/src/js/ace.js b/addons/web_editor/static/src/js/ace.js
index cd20815f49c..5fbe7589265 100644
--- a/addons/web_editor/static/src/js/ace.js
+++ b/addons/web_editor/static/src/js/ace.js
@@ -127,13 +127,14 @@ var ViewEditor = Widget.extend({
loadViews: function (views) {
var $viewList = this.$('#ace-view-list').empty();
- _(this.buildViewGraph(views)).each(function (view) {
+ var viewGraph = this.buildViewGraph(views);
+ _(viewGraph).each(function (view) {
if (!view.id) { return; }
this.views[view.id] = view;
new ViewOption(this, view).appendTo($viewList);
- this.loadView(view.id);
}.bind(this));
+ return this.loadView(viewGraph[0].id);
},
buildViewGraph: function (views) {
var activeViews = _.uniq(_.filter(views, function (view) {
@@ -171,32 +172,36 @@ var ViewEditor = Widget.extend({
loadView: function (id) {
var viewId = parseInt(id, 10);
var self = this;
- ajax.jsonRpc('/web/dataset/call', 'call', {
+ return ajax.jsonRpc('/web/dataset/call', 'call', {
model: 'ir.ui.view',
method: 'read',
args: [[viewId], ['arch'], _.extend(base.get_context(), {'lang': null})],
}).then(function (result) {
- var editingSession = self.buffers[viewId] = new ace.EditSession(result[0].arch);
- editingSession.setMode("ace/mode/xml");
- editingSession.setUndoManager(new ace.UndoManager());
- editingSession.setUseWorker(false);
- editingSession.on("change", function () {
- setTimeout(function () {
- var $option = self.$('#ace-view-list').find('[value='+viewId+']');
- var bufferName = $option.text();
- var dirtyMarker = " (unsaved changes)";
- var isDirty = editingSession.getUndoManager().hasUndo();
- if (isDirty && bufferName.indexOf(dirtyMarker) < 0) {
- $option.text(bufferName + dirtyMarker);
- } else if (!isDirty && bufferName.indexOf(dirtyMarker) > 0) {
- $option.text(bufferName.substring(0, bufferName.indexOf(dirtyMarker)));
- }
- }, 1);
- });
- if (viewId === self.selectedViewId()) {
- self.displayView.call(self, viewId);
- }
+ self._displayArch(result[0].arch, viewId);
+ });
+ },
+ _displayArch: function(arch, viewId) {
+ var self = this;
+ var editingSession = this.buffers[viewId] = new ace.EditSession(arch);
+ editingSession.setUseWorker(false);
+ editingSession.setMode("ace/mode/xml");
+ editingSession.setUndoManager(new ace.UndoManager());
+ editingSession.on("change", function () {
+ setTimeout(function () {
+ var $option = self.$('#ace-view-list').find('[value='+viewId+']');
+ var bufferName = $option.text();
+ var dirtyMarker = " (unsaved changes)";
+ var isDirty = editingSession.getUndoManager().hasUndo();
+ if (isDirty && bufferName.indexOf(dirtyMarker) < 0) {
+ $option.text(bufferName + dirtyMarker);
+ } else if (!isDirty && bufferName.indexOf(dirtyMarker) > 0) {
+ $option.text(bufferName.substring(0, bufferName.indexOf(dirtyMarker)));
+ }
+ }, 1);
});
+ if (viewId === self.selectedViewId()) {
+ self.displayView.call(self, viewId);
+ }
},
selectedViewId: function () {
return parseInt(this.$('#ace-view-list').val(), 10);
@@ -212,8 +217,16 @@ var ViewEditor = Widget.extend({
}
},
displaySelectedView: function () {
- this.displayView(this.selectedViewId());
- this.updateHash();
+ var self = this;
+ var viewID = this.selectedViewId();
+ if (this.buffers[viewID]) {
+ this.displayView(viewID);
+ this.updateHash();
+ } else {
+ this.loadView(viewID).then(function() {
+ self.updateHash();
+ });
+ }
},
formatXml: function () {
var xml = new XmlDocument(this.aceEditor.getValue());
diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js
index a20da344b03..6d31f75f6ca 100644
--- a/addons/web_editor/static/src/js/backend.js
+++ b/addons/web_editor/static/src/js/backend.js
@@ -195,6 +195,9 @@ var FieldTextHtml = widget.extend({
self.trigger('changed_value');
self.resize();
};
+ window.odoo[this.callback+"_do_action"] = function () {
+ self.do_action.apply(self, arguments);
+ };
// init jqery objects
this.$iframe = this.$el.find('iframe');
@@ -379,6 +382,7 @@ var FieldTextHtml = widget.extend({
delete window.odoo[this.callback+"_content"];
delete window.odoo[this.callback+"_updown"];
delete window.odoo[this.callback+"_downup"];
+ delete window.odoo[this.callback+"_do_action"];
}
});
diff --git a/addons/web_editor/static/src/js/editor.js b/addons/web_editor/static/src/js/editor.js
index 1163635146f..240a0a36121 100644
--- a/addons/web_editor/static/src/js/editor.js
+++ b/addons/web_editor/static/src/js/editor.js
@@ -16,7 +16,7 @@ var editor = {};
editor.dummy = function () {return true;}; // used for snippets, options...
-editor.editable = !!$('html').data('editable');
+editor.editable = !!($('html').data('editable') || $("[data-oe-model]").length); // temporary hack, this should be done in python
ajax.loadXML('/web_editor/static/src/xml/editor.xml', qweb);
diff --git a/addons/web_editor/static/src/js/iframe.js b/addons/web_editor/static/src/js/iframe.js
index 398dc2e5bf9..e2c3b5ef8a4 100644
--- a/addons/web_editor/static/src/js/iframe.js
+++ b/addons/web_editor/static/src/js/iframe.js
@@ -10,6 +10,7 @@ var snippet_editor = require('web_editor.snippet.editor');
ajax.loadXML('/web/static/src/xml/base_common.xml', core.qweb);
+var callback = window ? window["callback"] : undefined;
window.top.odoo[callback+"_updown"] = function (value, fields_values, field_name) {
var $editable = $("#editable_area");
if(value !== $editable.prop("innerHTML")) {
diff --git a/addons/web_editor/static/src/js/snippets.options.js b/addons/web_editor/static/src/js/snippets.options.js
index 6d4800cd0db..4d533cadd00 100644
--- a/addons/web_editor/static/src/js/snippets.options.js
+++ b/addons/web_editor/static/src/js/snippets.options.js
@@ -609,7 +609,7 @@ odoo.define('web_editor.snippets.options', function (require) {
var _editor = new widget.MediaDialog(null, {}, null, $image[0]).open();
_editor.$('[href="#editor-media-video"], [href="#editor-media-icon"]').addClass('hidden');
- _editor.on('saved', this, function () {
+ _editor.on('save', this, function () {
var value = $image.attr("src");
this.background(type, value, $li);
this.$target.addClass("oe_custom_bg");
diff --git a/addons/web_editor/static/src/js/transcoder.js b/addons/web_editor/static/src/js/transcoder.js
index ddd8ce73533..20d4f5844af 100644
--- a/addons/web_editor/static/src/js/transcoder.js
+++ b/addons/web_editor/static/src/js/transcoder.js
@@ -118,7 +118,7 @@ var getMatchedCSSRules = function (a) {
// convert font awsome into image
var font_to_img = function ($editable) {
- $(".fa", $editable).each(function () {
+ $editable.find(".fa").each(function () {
var $font = $(this);
var icon, content;
_.find(widget.fontIcons, function (font) {
@@ -132,15 +132,13 @@ var font_to_img = function ($editable) {
});
if (content) {
var color = $font.css("color").replace(/\s/g, '');
- var src = _.str.sprintf('/web_editor/font_to_img/%s/%s/'+Math.max(1, $font.height()), content.charCodeAt(0), window.encodeURI(color));
- var $img = $("<img/>").attr("src", src)
- .attr("data-class", $font.attr("class"))
- .attr("class", $font.attr("class").replace(new RegExp("(^|\\s+)" + icon + "(-[^\\s]+)?", "gi"), '')) // remove inline font-awsome style
- .attr("style", $font.attr("style"))
- .attr("height", $font.height())
- .css("height", "")
- .css("font-size", "");
- $font.replaceWith($img);
+ $font.replaceWith($("<img/>", {
+ "src": _.str.sprintf('/web_editor/font_to_img/%s/%s/%s', content.charCodeAt(0), window.encodeURI(color), Math.max(1, $font.height())),
+ "data-class": $font.attr("class"),
+ "data-style": $font.attr("style"),
+ "class": $font.attr("class").replace(new RegExp("(^|\\s+)" + icon + "(-[^\\s]+)?", "gi"), ''), // remove inline font-awsome style
+ "style": $font.attr("style")
+ }).css({height: "auto", width: "auto"}));
} else {
$font.remove();
}
@@ -148,13 +146,12 @@ var font_to_img = function ($editable) {
};
// convert image into font awsome
var img_to_font = function ($editable) {
- $("img[src*='/web_editor/font_to_img/']", $editable).each(function () {
+ $editable.find("img[src*='/web_editor/font_to_img/']").each(function () {
var $img = $(this);
- var $font = $("<span/>")
- .attr("class", $img.data("class"))
- .attr("style", $img.attr("style"))
- .css("height", "");
- $img.replaceWith($font);
+ $img.replaceWith($("<span/>", {
+ "class": $img.data("class"),
+ "style": $img.data("style")
+ }));
});
};
diff --git a/addons/web_editor/static/src/js/widgets.js b/addons/web_editor/static/src/js/widgets.js
index 00a693d40f2..7a3ab09dd76 100644
--- a/addons/web_editor/static/src/js/widgets.js
+++ b/addons/web_editor/static/src/js/widgets.js
@@ -34,11 +34,11 @@ Dialog = Dialog.extend({
self.$('input:first').focus();
});
this.on("closed", this, function () {
- this.trigger(this.destroyAction);
+ this.trigger(this.destroyAction, this.final_data || null);
});
},
save: function () {
- this.destroyAction = "saved";
+ this.destroyAction = "save";
this.close();
},
});
@@ -164,8 +164,8 @@ var MediaDialog = Dialog.extend({
},
save: function () {
if (this.options.select_images) {
- this.trigger("saved", this.active.save());
- this.close();
+ this.final_data = this.active.save();
+ this._super.apply(this, arguments);
return;
}
if(this.rte) {
@@ -198,8 +198,8 @@ var MediaDialog = Dialog.extend({
}
var media = this.active.media;
- $(document.body).trigger("media-saved", [media, self.old_media]);
- self.trigger("saved", [media, self.old_media]);
+ this.final_data = [media, self.old_media];
+ $(document.body).trigger("media-saved", this.final_data);
// Update editor bar after image edition (in case the image change to icon or other)
_.defer(function () {
@@ -312,10 +312,8 @@ var ImageDialog = Widget.extend({
},
save: function () {
if (this.options.select_images) {
- this.parent.trigger("save", this.images);
return this.images;
}
- this.parent.trigger("save", this.media);
var img = this.images[0];
if (!img) {
@@ -668,7 +666,6 @@ var fontIconsDialog = Widget.extend({
*/
save: function () {
var self = this;
- this.parent.trigger("save", this.media);
var style = this.media.attributes.style ? this.media.attributes.style.value : '';
var classes = (this.media.className||"").split(/\s+/);
var custom_classes = /^fa(-[1-5]x|spin|rotate-(9|18|27)0|flip-(horizont|vertic)al|fw|border)?$/;
@@ -684,6 +681,8 @@ var fontIconsDialog = Widget.extend({
style = style.replace(/\s*width:[^;]+/, '');
}
$(this.media).attr("class", _.compact(final_classes).join(' ')).attr("style", style);
+
+ return this.media;
},
/**
* return the data font object (with base, parser and icons) or null
@@ -907,7 +906,6 @@ var VideoDialog = Widget.extend({
return false;
},
save: function () {
- this.parent.trigger("save", this.media);
var video_id = this.$("#video_id").val();
if (!video_id) {
this.$("button.btn-primary").click();
@@ -921,6 +919,8 @@ var VideoDialog = Widget.extend({
'</div>');
$(this.media).replaceWith($iframe);
this.media = $iframe[0];
+
+ return this.media;
},
clear: function () {
if (this.media.dataset.src) {
@@ -1095,7 +1095,7 @@ var LinkDialog = Dialog.extend({
if (classes.replace(/(^|[ ])(btn-default|btn-success|btn-primary|btn-info|btn-warning|btn-danger)([ ]|$)/gi, ' ')) {
self.data.style = {'background-color': '', 'color': ''};
}
- self.trigger("save", self.data);
+ self.final_data = self.data;
}).then(_super);
},
bind_data: function () {
diff --git a/addons/web_editor/static/src/less/web_editor.ui.components.less b/addons/web_editor/static/src/less/web_editor.ui.components.less
index 31d2ce07dac..7dd882ffbd0 100644
--- a/addons/web_editor/static/src/less/web_editor.ui.components.less
+++ b/addons/web_editor/static/src/less/web_editor.ui.components.less
@@ -119,6 +119,63 @@
.o-animation(fadeInDownSmall, 700ms, @fill-mode: forwards);
}
+// ACE EDITOR
+.o_ace_view_editor {
+ @o-ace-color: #2F3129;
+ background: @o-ace-color;
+ color: white;
+ .o-flex-display();
+ .o-flex-flow(column, nowrap);
+
+ .o_ace_view_editor_title {
+ .o-flex(0, 0, auto);
+ .o-flex-display();
+ .o-align-items(center);
+ .o-justify-content(space-between);
+ padding: @grid-gutter-width/4;
+
+ > * {
+ .o-flex(0, 0, auto);
+ margin: 0 @grid-gutter-width/4;
+
+ &.oe_include_bundles {
+ .o-flex-display();
+ .o-align-items(center);
+ font-size: 11px;
+
+ > .o_checkbox {
+ margin-right: @grid-gutter-width/4;
+ }
+ }
+ }
+
+ > select {
+ .o-flex(0, 1, auto);
+ min-width: 60px;
+ }
+ }
+ #ace-view-id {
+ .o-flex(0, 0, auto);
+ padding: @grid-gutter-width/4 @grid-gutter-width/2;
+ background-color: lighten(@o-ace-color, 10%);
+ }
+ #ace-view-editor {
+ height: 70%; // in case flex is not supported
+ .o-flex(1, 1, auto);
+ .ace_gutter {
+ cursor: ew-resize;
+ }
+ }
+
+ &.oe_ace_open {
+ opacity: 0.97;
+ }
+ &.oe_ace_closed {
+ z-index: -1000;
+ opacity: 0;
+ }
+}
+
// MODALS
body .modal {
// SELECT MEDIA
diff --git a/addons/web_editor/static/src/less/web_editor.ui.less b/addons/web_editor/static/src/less/web_editor.ui.less
index 00b6414bd16..4f1eb7dc4be 100644
--- a/addons/web_editor/static/src/less/web_editor.ui.less
+++ b/addons/web_editor/static/src/less/web_editor.ui.less
@@ -70,12 +70,17 @@
margin: 10px;
padding: 4px;
}
-html[lang] > body.editor_enable{
- [data-oe-translation-state] {
- background: rgba(255, 255, 90, 0.5) !important;
+html[lang] > body.editor_enable [data-oe-translation-state] {
+ @o-color-content-to-translate: rgb(255, 255, 90);
+ @o-color-translated-content: rgb(120, 215, 110);
+
+ background: fade(@o-color-content-to-translate, 50%)!important;
+
+ &[data-oe-translation-state="translated"] {
+ background: fade(@o-color-translated-content, 50%)!important;
}
- [data-oe-translation-state="translated"] {
- background: rgba(120, 215, 110, 0.5) !important;
+ &.o_dirty {
+ background: fade(@o-color-translated-content, 25%)!important;
}
}