diff options
| author | Frederic van der Essen <fva@openerp.com / fvdessen+o@gmail.com> | 2014-08-25 16:42:57 +0200 |
|---|---|---|
| committer | Frederic van der Essen <fva@openerp.com / fvdessen+o@gmail.com> | 2014-08-25 16:42:57 +0200 |
| commit | d7f93defb899b2b48a14d679e5dffffdb4a00eff (patch) | |
| tree | f8572183b480477622917a1f504cf49a8e202f6e /addons/website/static/src/js/website.editor.js | |
| parent | 2b67528fe9e366829d44d8aba756bc6e359b4c61 (diff) | |
| parent | 36146b3fadc47543f4b696ab75c31b3459afb15b (diff) | |
Merge branch 'master' into master-pos-new-payment-screen-fva
Conflicts:
addons/point_of_sale/point_of_sale.py
addons/point_of_sale/point_of_sale_view.xml
Diffstat (limited to 'addons/website/static/src/js/website.editor.js')
| -rw-r--r-- | addons/website/static/src/js/website.editor.js | 123 |
1 files changed, 117 insertions, 6 deletions
diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index f15278ee49f..205d8dde076 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -209,6 +209,111 @@ } }); + CKEDITOR.plugins.add('customColor', { + requires: 'panelbutton,floatpanel', + init: function (editor) { + function create_button (buttonID, label) { + var btnID = buttonID; + editor.ui.add(buttonID, CKEDITOR.UI_PANELBUTTON, { + label: label, + title: label, + modes: { wysiwyg: true }, + editorFocus: true, + context: 'font', + panel: { + css: [ '/web/css/web.assets_common/' + (new Date().getTime()), + '/web/css/website.assets_frontend/' + (new Date().getTime()), + '/web/css/website.assets_editor/' + (new Date().getTime())], + attributes: { 'role': 'listbox', 'aria-label': label }, + }, + enable: function () { + this.setState(CKEDITOR.TRISTATE_OFF); + }, + disable: function () { + this.setState(CKEDITOR.TRISTATE_DISABLED); + }, + onBlock: function (panel, block) { + var self = this; + var html = openerp.qweb.render('website.colorpicker'); + block.autoSize = true; + block.element.setHtml( html ); + $(block.element.$).on('click', 'button', function () { + self.clicked(this); + }); + if (btnID === "TextColor") { + $(".only-text", block.element.$).css("display", "block"); + $(".only-bg", block.element.$).css("display", "none"); + } + var $body = $(block.element.$).parents("body"); + setTimeout(function () { + $body.css('background-color', '#fff'); + }, 0); + }, + getClasses: function () { + var self = this; + var classes = []; + var id = this._.id; + var block = this._.panel._.panel._.blocks[id]; + var $root = $(block.element.$); + $root.find("button").map(function () { + var color = self.getClass(this); + if(color) classes.push( color ); + }); + return classes; + }, + getClass: function (button) { + var color = btnID === "BGColor" ? $(button).attr("class") : $(button).attr("class").replace(/^bg-/i, 'text-'); + return color.length && color; + }, + clicked: function (button) { + var className = this.getClass(button); + var ancestor = editor.getSelection().getCommonAncestor(); + + editor.focus(); + this._.panel.hide(); + editor.fire('saveSnapshot'); + + // remove style + var classes = []; + var $ancestor = $(ancestor.$); + var $fonts = $(ancestor.$).find('font'); + if (!ancestor.$.tagName) { + $ancestor = $ancestor.parent(); + } + if ($ancestor.is('font')) { + $fonts = $fonts.add($ancestor[0]); + } + + $fonts.filter("."+this.getClasses().join(",.")).map(function () { + var className = $(this).attr("class"); + if (classes.indexOf(className) === -1) { + classes.push(className); + } + }); + for (var k in classes) { + editor.removeStyle( new CKEDITOR.style({ + element: 'font', + attributes: { 'class': classes[k] }, + }) ); + } + + // add new style + if (className) { + editor.applyStyle( new CKEDITOR.style({ + element: 'font', + attributes: { 'class': className }, + }) ); + } + editor.fire('saveSnapshot'); + } + + }); + } + create_button("BGColor", "Background Color"); + create_button("TextColor", "Text Color"); + } + }); + CKEDITOR.plugins.add('oeref', { requires: 'widget', @@ -356,7 +461,13 @@ observer.disconnect(); var editor = this.rte.editor; var root = editor.element && editor.element.$; - editor.destroy(); + try { + editor.destroy(); + } + catch(err) { + // Hack to avoid the lost of all changes because ckeditor fails in destroy + console.log("Error in editor.destroy() : " + err.toString() + "\n " + err.stack); + } // FIXME: select editables then filter by dirty? var defs = this.rte.fetch_editables(root) .filter('.oe_dirty') @@ -558,7 +669,7 @@ website.EditorBarCustomize = openerp.Widget.extend({ events: { 'mousedown a.dropdown-toggle': 'load_menu', - 'click ul a[data-action!=ace]': 'do_customize', + 'click li:not(#html_editor):not(#theme_customize):not(#install_apps) a': 'do_customize', }, start: function() { var self = this; @@ -862,7 +973,7 @@ fillEmptyBlocks: false, filebrowserImageUploadUrl: "/website/attach", // Support for sharedSpaces in 4.x - extraPlugins: 'sharedspace,customdialogs,tablebutton,oeref', + extraPlugins: 'customColor,sharedspace,customdialogs,tablebutton,oeref', // Place toolbar in controlled location sharedSpaces: { top: 'oe_rte_toolbar' }, toolbar: [{ @@ -894,7 +1005,7 @@ {name: "Heading 5", element: 'h5'}, {name: "Heading 6", element: 'h6'}, {name: "Formatted", element: 'pre'}, - {name: "Address", element: 'address'} + {name: "Address", element: 'address'}, ], }; }, @@ -1457,9 +1568,9 @@ } var callback = _.uniqueId('func_'); this.$('input[name=func]').val(callback); - window[callback] = function (url, error) { + window[callback] = function (attachments, error) { delete window[callback]; - self.file_selected(url, error); + self.file_selected(attachments[0]['website_url'], error); }; }, file_selection: function () { |
