diff options
| author | qsm-odoo <qsm@odoo.com> | 2016-09-20 13:52:41 +0200 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2016-09-20 13:52:41 +0200 |
| commit | 9a1939bbcb38db7b9537b0fb6663cad8aa9cb366 (patch) | |
| tree | 5ac197e6fe6f51f9d47fdf5ef888534fbc65347f /addons/web_editor/static/src/js | |
| parent | e5755b12cff00af1a0e81e1954179148f733bf0c (diff) | |
| parent | 4868b045a7191d0e8b170f43275cac7130205e83 (diff) | |
[MERGE] mass_mailing, *: add new mass mailing theme system
* web_editor, website
-> Move some website options to web_editor to use them in mass_mailing
(margin and resize)
-> Rework on themes design and declaration conventions
-> Review theme switching to bring default layout on first edition and
to be able to define theme images
-> Move theme design in their own asset
-> Edition and saves fixes
Diffstat (limited to 'addons/web_editor/static/src/js')
| -rw-r--r-- | addons/web_editor/static/src/js/snippets.options.js | 225 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/transcoder.js | 6 |
2 files changed, 226 insertions, 5 deletions
diff --git a/addons/web_editor/static/src/js/snippets.options.js b/addons/web_editor/static/src/js/snippets.options.js index b4b96beabca..6d4800cd0db 100644 --- a/addons/web_editor/static/src/js/snippets.options.js +++ b/addons/web_editor/static/src/js/snippets.options.js @@ -214,6 +214,231 @@ odoo.define('web_editor.snippets.options', function (require) { /* ----- default options ---- */ + registry.marginAndResize = SnippetOption.extend({ + preventChildPropagation: true, + + start: function () { + var self = this; + this._super(); + + var resize_values = this.getSize(); + if (resize_values.n) this.$overlay.find(".oe_handle.n").removeClass("readonly"); + if (resize_values.s) this.$overlay.find(".oe_handle.s").removeClass("readonly"); + if (resize_values.e) this.$overlay.find(".oe_handle.e").removeClass("readonly"); + if (resize_values.w) this.$overlay.find(".oe_handle.w").removeClass("readonly"); + if (resize_values.size) this.$overlay.find(".oe_handle.size").removeClass("readonly"); + + var $auto_size = this.$overlay.find(".oe_handle.size .auto_size"); + var $fixed_size = this.$overlay.find(".oe_handle.size .size"); + + var auto_sized = isNaN(parseInt(self.$target.prop("style").height)); + $fixed_size.toggleClass("active", !auto_sized); + $auto_size.toggleClass("active", auto_sized); + + $fixed_size.add(this.$overlay.find(".oe_handle:not(.size)")).on('mousedown', function (event) { + event.preventDefault(); + + var $handle = $(this); + + var resize_values = self.getSize(); + var compass = false; + var XY = false; + if ($handle.hasClass('n')) { + compass = 'n'; + XY = 'Y'; + } + else if ($handle.hasClass('s')) { + compass = 's'; + XY = 'Y'; + } + else if ($handle.hasClass('e')) { + compass = 'e'; + XY = 'X'; + } + else if ($handle.hasClass('w')) { + compass = 'w'; + XY = 'X'; + } + else if ($handle.hasClass('size')) { + compass = 'size'; + XY = 'Y'; + } + + var resize = resize_values[compass]; + if (!resize) return; + + + if (compass === 'size') { + var offset = self.$target.offset().top; + if (self.$target.css("background").match(/rgba\(0, 0, 0, 0\)/)) { + self.$target.addClass("resize_editor_busy"); + } + } else { + var xy = event['page'+XY]; + var current = resize[2] || 0; + var margin_dir = {s:'bottom', n: 'top', w: 'left', e: 'right'}[compass]; + var real_margin = parseInt(self.$target.css('margin-'+margin_dir)); + _.each(resize[0], function (val, key) { + if (self.$target.hasClass(val)) { + current = key; + } else if (resize[1][key] === real_margin) { + current = key; + } + }); + var begin = current; + var beginClass = self.$target.attr("class"); + var regClass = new RegExp("\\s*" + resize[0][begin].replace(/[-]*[0-9]+/, '[-]*[0-9]+'), 'g'); + } + + self.buildingBlock.editor_busy = true; + + var cursor = $handle.css("cursor")+'-important'; + var $body = $(document.body); + $body.addClass(cursor); + + var body_mousemove = function (event) { + event.preventDefault(); + if (compass === 'size') { + var dy = event.pageY-offset; + dy = dy - dy%resize; + if (dy <= 0) dy = resize; + self.$target.css("height", dy+"px"); + self.$target.css("overflow", "hidden"); + self.on_resize(compass, null, dy); + self.buildingBlock.cover_target(self.$overlay, self.$target); + return; + } + var dd = event['page'+XY] - xy + resize[1][begin]; + var next = current+1 === resize[1].length ? current : (current+1); + var prev = current ? (current-1) : 0; + + var change = false; + if (dd > (2*resize[1][next] + resize[1][current])/3) { + self.$target.attr("class", (self.$target.attr("class")||'').replace(regClass, '')); + self.$target.addClass(resize[0][next]); + current = next; + change = true; + } + if (prev !== current && dd < (2*resize[1][prev] + resize[1][current])/3) { + self.$target.attr("class", (self.$target.attr("class")||'').replace(regClass, '')); + self.$target.addClass(resize[0][prev]); + current = prev; + change = true; + } + + if (change) { + self.on_resize(compass, beginClass, current); + self.buildingBlock.cover_target(self.$overlay, self.$target); + } + }; + + var body_mouseup = function () { + $body.unbind('mousemove', body_mousemove); + $body.unbind('mouseup', body_mouseup); + $body.removeClass(cursor); + setTimeout(function () { + self.buildingBlock.editor_busy = false; + if (begin !== current) { + self.buildingBlock.getParent().rte.historyRecordUndo(self.$target, 'resize_' + XY); + } + },0); + self.$target.removeClass("resize_editor_busy"); + + if (compass === "size") { + $fixed_size.addClass("active"); + $auto_size.removeClass("active"); + } + }; + $body.mousemove(body_mousemove); + $body.mouseup(body_mouseup); + }); + $auto_size.on('click', function () { + self.$target.css("height", ""); + self.$target.css("overflow", ""); + self.buildingBlock.getParent().rte.historyRecordUndo(self.$target, 'resize_Y'); + self.buildingBlock.cover_target(self.$overlay, self.$target); + + $fixed_size.removeClass("active"); + $auto_size.addClass("active"); + + return false; + }); + }, + getSize: function () { + this.grid = {}; + return this.grid; + }, + + on_focus : function () { + this._super(); + this.change_cursor(); + }, + + change_cursor : function () { + var _class = this.$target.attr("class") || ""; + + var col = _class.match(/col-md-([0-9-]+)/i); + col = col ? +col[1] : 0; + + var offset = _class.match(/col-md-offset-([0-9-]+)/i); + offset = offset ? +offset[1] : 0; + + var overlay_class = this.$overlay.attr("class").replace(/(^|\s+)block-[^\s]*/gi, ''); + if (col+offset >= 12) overlay_class+= " block-e-right"; + if (col === 1) overlay_class+= " block-w-right block-e-left"; + if (offset === 0) overlay_class+= " block-w-left"; + + var mb = _class.match(/mb([0-9-]+)/i); + mb = mb ? +mb[1] : parseInt(this.$target.css('margin-bottom')); + if (mb >= 128) overlay_class+= " block-s-bottom"; + else if (!mb) overlay_class+= " block-s-top"; + + var mt = _class.match(/mt([0-9-]+)/i); + mt = mt ? +mt[1] : parseInt(this.$target.css('margin-top')); + if (mt >= 128) overlay_class+= " block-n-top"; + else if (!mt) overlay_class+= " block-n-bottom"; + + this.$overlay.attr("class", overlay_class); + }, + + /* on_resize + * called when the box is resizing and the class change, before the cover_target + * @compass: resize direction : 'n', 's', 'e', 'w' + * @beginClass: attributes class at the begin + * @current: curent increment in this.grid + */ + on_resize: function () { + this.change_cursor(); + } + }); + + registry["margin-y"] = registry.marginAndResize.extend({ + preventChildPropagation: true, + + getSize: function () { + this.grid = this._super(); + var grid = [0,4,8,16,32,48,64,92,128]; + this.grid = { + // list of class (Array), grid (Array), default value (INT) + n: [_.map(grid, function (v) {return 'mt'+v;}), grid], + s: [_.map(grid, function (v) {return 'mb'+v;}), grid], + // INT if the user can resize the snippet (resizing per INT px) + size: null + }; + return this.grid; + }, + }); + + registry.resize = registry.marginAndResize.extend({ + preventChildPropagation: true, + + getSize: function () { + this.grid = this._super(); + this.grid.size = 8; + return this.grid; + }, + }); + /** * The colorpicker option is designed to change the background color class of a snippet. This class change the * default background color and text color of the snippet content. diff --git a/addons/web_editor/static/src/js/transcoder.js b/addons/web_editor/static/src/js/transcoder.js index fbdc4b34b87..ddd8ce73533 100644 --- a/addons/web_editor/static/src/js/transcoder.js +++ b/addons/web_editor/static/src/js/transcoder.js @@ -3,12 +3,8 @@ odoo.define('web_editor.transcoder', function (require) { var widget = require('web_editor.widget'); -var cache = {}; var rulesCache = []; var getMatchedCSSRules = function (a) { - if(cache[a.tagName + "." +a.className]) { - return cache[a.tagName + "." +a.className]; - } if (!rulesCache.length) { var sheets = document.styleSheets; for(var i = sheets.length-1; i >= 0 ; i--) { @@ -117,7 +113,7 @@ var getMatchedCSSRules = function (a) { delete style['padding-left']; } - return a.className ? cache[a.tagName + "." +a.className] = style : style; + return style; }; // convert font awsome into image |
