Browse Source

[PORT] Port web_ckeditor4 to 10.0

pull/1037/head
George Daramouskas 7 years ago
committed by Holger Brunn
parent
commit
3371fe5f6b
  1. 50
      web_ckeditor4/README.rst
  2. 30
      web_ckeditor4/__manifest__.py
  3. 4
      web_ckeditor4/models/ckeditor_monkeypatch.py
  4. 4
      web_ckeditor4/static/src/css/web_ckeditor4.css
  5. 180
      web_ckeditor4/static/src/js/web_ckeditor4.js
  6. 25
      web_ckeditor4/static/src/js/web_ckeditor4_formview.js
  7. 2
      web_ckeditor4/views/qweb.xml

50
web_ckeditor4/README.rst

@ -1,44 +1,56 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3
===================
CKEditor web widget CKEditor web widget
=================== ===================
This addon provides a widget for editing html fields via CKEditor 4.6.6
This module introduces the text_ckeditor4 widget that when used allows the user
to use specific features of ckeditor.
Usage
=====
Configuration
=============
To use this module, you need to:
In your view definition, use widget="text_html" if you need just html display.
In the unlikely case you need specific features of ckeditor,
use widget="text_ckeditor4".
#. Go to ...
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/162/10.0
Known issues / Roadmap Known issues / Roadmap
====================== ======================
* This version of CKEditor contains a patch that prevents the referencing of * This version of CKEditor contains a patch that prevents the referencing of
the editor's iframe if it has already been cleaned up by Odoo. In 8.0, this is
the case if the editor was created in an x2many popup. The patch was proposed
as https://github.com/ckeditor/ckeditor-dev/pull/200
the editor's iframe if it has already been cleaned up by Odoo. In 8.0, this is
the case if the editor was created in an x2many popup. The patch was proposed
as https://github.com/ckeditor/ckeditor-dev/pull/200
Bug Tracker Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/web/issues/new?body=module:%20web_ckeditor4%0Aversion:%201.1%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/{project_repo}/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits Credits
======= =======
CKEditor 4.4.6 Copyright (C) 2003-2015 CKSource - Frederico Knabben
Images
------
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
Contributors Contributors
------------ ------------
* Holger Brunn <hbrunn@therp.nl>
* Stefan Rijnhart <stefan@therp.nl>
* George Daramouskas <gdaramouskas@therp.nl>
* Holger Brunn <hbrunn@therp.nl>
* Stefan Rijnhart <stefan@therp.nl>
Do not contact contributors directly about support or help with technical issues.
Maintainer Maintainer
---------- ----------
@ -53,4 +65,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.
To contribute to this module, please visit https://odoo-community.org.

30
web_ckeditor4/__manifest__.py

@ -1,28 +1,9 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013-2015 Therp BV (<http://therp.nl>)
# All Rights Reserved
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
'name': 'CKEditor 4.x widget', 'name': 'CKEditor 4.x widget',
'version': '8.0.1.0.0',
'version': '10.0.1.0.0',
'author': "Therp BV,Odoo Community Association (OCA)", 'author': "Therp BV,Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/web', 'website': 'https://github.com/OCA/web',
'summary': 'Provides a widget for editing HTML fields using CKEditor 4.x', 'summary': 'Provides a widget for editing HTML fields using CKEditor 4.x',
@ -37,7 +18,6 @@
'css': [ 'css': [
'static/src/css/web_ckeditor4.css', 'static/src/css/web_ckeditor4.css',
], ],
'installable': False,
'installable': True,
'auto_install': False, 'auto_install': False,
'certificate': '',
} }

4
web_ckeditor4/models/ckeditor_monkeypatch.py

@ -27,7 +27,7 @@ class CkeditorMonkeypatch(models.AbstractModel):
_name = 'ckeditor.monkeypatch' _name = 'ckeditor.monkeypatch'
_description = 'Monkeypatches for CKEditor' _description = 'Monkeypatches for CKEditor'
def _register_hook(self, cr):
def _register_hook(self):
marker = self._name.replace('.', '_') marker = self._name.replace('.', '_')
if not hasattr(clean, marker): if not hasattr(clean, marker):
# monkey patch lxml's html cleaner to allow image data urls # monkey patch lxml's html cleaner to allow image data urls
@ -41,4 +41,4 @@ class CkeditorMonkeypatch(models.AbstractModel):
# TODO: do something else for 2.3.1 <= version <= 3.2, before data # TODO: do something else for 2.3.1 <= version <= 3.2, before data
# urls were not cleaned at all # urls were not cleaned at all
setattr(clean, marker, True) setattr(clean, marker, True)
return super(CkeditorMonkeypatch, self)._register_hook(cr)
return super(CkeditorMonkeypatch, self)._register_hook()

4
web_ckeditor4/static/src/css/web_ckeditor4.css

@ -1,5 +1,5 @@
.openerp .oe_form_field_text_ckeditor4.disabled, .openerp td.oe_form_field_text_ckeditor4, .openerp .oe_form_field_text_ckeditor4_raw.disabled.openerp, .openerp td.oe_form_field_text_ckeditor4_raw {
/* here we need to reset openerp's styles to
.odoo .oe_form_field_text_ckeditor4.disabled, .odoo td.oe_form_field_text_ckeditor4, .odoo .oe_form_field_text_ckeditor4_raw.disabled.odoo, .odoo td.oe_form_field_text_ckeditor4_raw {
/* here we need to reset odoo's styles to
* have the HTML display as (probably) intended * have the HTML display as (probably) intended
*/ */
white-space: normal; white-space: normal;

180
web_ckeditor4/static/src/js/web_ckeditor4.js

@ -20,8 +20,12 @@
# #
############################################################################*/ ############################################################################*/
openerp.web_ckeditor4 = function(instance)
{
odoo.define('web_ckeditor4', function(require){
"use strict";
var core = require('web.core');
var session = require('web.session');
var formats = require('web.formats');
var ckeditor_addFunction_org = CKEDITOR.tools.addFunction; var ckeditor_addFunction_org = CKEDITOR.tools.addFunction;
//this is a quite complicated way to kind of monkey patch the private //this is a quite complicated way to kind of monkey patch the private
//method onDomReady of ckeditor's plugin wysiwigarea, which causes problems //method onDomReady of ckeditor's plugin wysiwigarea, which causes problems
@ -33,17 +37,17 @@ openerp.web_ckeditor4 = function(instance)
{ {
var scope_reference = scope; var scope_reference = scope;
return ckeditor_addFunction_org(function() return ckeditor_addFunction_org(function()
{
var self = this,
self_arguments=arguments;
setTimeout(function()
{
var self = this,
self_arguments=arguments;
setTimeout(function()
{ {
if(self.editor) if(self.editor)
{ {
fn.apply(self, self_arguments); fn.apply(self, self_arguments);
} }
}, 0); }, 0);
}, scope);
}, scope);
} }
return ckeditor_addFunction_org(fn, scope); return ckeditor_addFunction_org(fn, scope);
}; };
@ -51,51 +55,41 @@ openerp.web_ckeditor4 = function(instance)
CKEDITOR.on('dialogDefinition', function(e) CKEDITOR.on('dialogDefinition', function(e)
{ {
_.each(e.data.definition.contents, function(element) _.each(e.data.definition.contents, function(element)
{
if(!element || element.filebrowser!='uploadButton')
{ {
return
}
_.each(element.elements, function(element)
{
if(!element.onClick || element.type!='fileButton')
if(!element || element.filebrowser!='uploadButton')
{ {
return return
} }
var onClick_org = element.onClick;
element.onClick = function(e1)
{
onClick_org.apply(this, arguments);
_.each(jQuery('#'+this.domId).closest('table')
.find('iframe').contents().find(':file')
.get(0).files,
function(file)
_.each(element.elements, function(element)
{
if(!element.onClick || element.type!='fileButton')
{ {
var reader = new FileReader();
reader.onload = function(load_event)
{
CKEDITOR.tools.callFunction(
e.editor._.filebrowserFn,
load_event.target.result,
'');
}
reader.readAsDataURL(file);
});
return false;
}
return
}
var onClick_org = element.onClick;
element.onClick = function(e1)
{
onClick_org.apply(this, arguments);
_.each(jQuery('#'+this.domId).closest('table')
.find('iframe').contents().find(':file')
.get(0).files,
function(file)
{
var reader = new FileReader();
reader.onload = function(load_event)
{
CKEDITOR.tools.callFunction(
e.editor._.filebrowserFn,
load_event.target.result,
'');
}
reader.readAsDataURL(file);
});
return false;
}
});
}); });
});
}); });
instance.web.form.widgets.add('text_ckeditor4',
'instance.web_ckeditor4.FieldCKEditor4');
instance.web.form.widgets.add('text_ckeditor4_raw',
'instance.web_ckeditor4.FieldCKEditor4Raw');
instance.web.form.widgets.add('text_html',
'instance.web_ckeditor4.FieldCKEditor4');
instance.web.form.widgets.add('html',
'instance.web_ckeditor4.FieldCKEditor4');
function filter_html(value, ckeditor_filter, ckeditor_writer) function filter_html(value, ckeditor_filter, ckeditor_writer)
{ {
var fragment = CKEDITOR.htmlParser.fragment.fromHtml(value); var fragment = CKEDITOR.htmlParser.fragment.fromHtml(value);
@ -105,59 +99,70 @@ openerp.web_ckeditor4 = function(instance)
return ckeditor_writer.getHtml(); return ckeditor_writer.getHtml();
}; };
default_ckeditor_filter = new CKEDITOR.filter(
var default_ckeditor_filter = new CKEDITOR.filter(
{
'*':
{ {
'*':
{
attributes: 'href,src,style,alt,width,height,dir',
styles: '*',
classes: '*',
},
'html head title meta style body p div span a h1 h2 h3 h4 h5 img br hr table tr th td ul ol li dd dt strong pre b i': true,
});
default_ckeditor_writer = new CKEDITOR.htmlParser.basicWriter();
instance.web_ckeditor4.FieldCKEditor4 = instance.web.form.FieldText.extend({
ckeditor_config: {
removePlugins: 'iframe,flash,forms,smiley,pagebreak,stylescombo',
filebrowserImageUploadUrl: 'dummy',
extraPlugins: 'filebrowser',
// this is '#39' per default which screws up single quoted text in ${}
entities_additional: '',
attributes: 'href,src,style,alt,width,height,dir',
styles: '*',
classes: '*',
},
'html head title meta style body p div span a h1 h2 h3 h4 h5 img br hr table tr th td ul ol li dd dt strong pre b i': true,
});
var default_ckeditor_writer = new CKEDITOR.htmlParser.basicWriter();
var FieldCKEditor4 = core.form_widget_registry.get('text').extend({
ckeditor_config: function () {
return {
removePlugins: this._getRemovePlugins(),
removeButtons: this._getRemoveButtons(),
filebrowserImageUploadUrl: 'dummy',
extraPlugins: 'filebrowser',
// this is '#39' per default which screws up single quoted text in ${}
entities_additional: ''
};
}, },
ckeditor_filter: default_ckeditor_filter, ckeditor_filter: default_ckeditor_filter,
ckeditor_writer: default_ckeditor_writer, ckeditor_writer: default_ckeditor_writer,
_getRemovePlugins: function () {
return 'iframe,flash,forms,smiley,pagebreak,stylescombo';
},
_getRemoveButtons: function () {
return '';
},
start: function() start: function()
{ {
this._super.apply(this, arguments); this._super.apply(this, arguments);
CKEDITOR.lang.load(instance.session.user_context.lang.split('_')[0], 'en', function() {});
CKEDITOR.lang.load(session.user_context.lang.split('_')[0], 'en', function() {});
}, },
initialize_content: function() initialize_content: function()
{ {
var self = this; var self = this;
this._super.apply(this, arguments); this._super.apply(this, arguments);
if(!this.$textarea)
if(!this.$el)
{ {
return; return;
}
this.editor = CKEDITOR.replace(this.$textarea.get(0),
_.extend(
{
language: instance.session.user_context.lang.split('_')[0],
on:
} else if (!this.get('effective_readonly')) {
this.editor = CKEDITOR.replace(this.$el.get(0),
_.extend(
{ {
'change': function()
language: session.user_context.lang.split('_')[0],
on:
{ {
self.store_dom_value();
'change': function()
{
self.store_dom_value();
},
}, },
}, },
},
this.ckeditor_config));
self.ckeditor_config()
)
);
}
}, },
store_dom_value: function() store_dom_value: function()
{ {
this.internal_set_value(this.editor ? this.editor.getData() : instance.web.parse_value(this.get('value'), this));
this.internal_set_value(this.editor ? this.editor.getData() : formats.parse_value(this.get('value'), this));
}, },
filter_html: function(value) filter_html: function(value)
{ {
@ -197,28 +202,37 @@ openerp.web_ckeditor4 = function(instance)
}, },
_cleanup_editor: function() _cleanup_editor: function()
{ {
if(this.editor)
if(this.editor && this.editor.status != 'unloaded')
{ {
var id = this.editor.id
this.editor.removeAllListeners(); this.editor.removeAllListeners();
this.editor.destroy(); this.editor.destroy();
this.editor = null; this.editor = null;
$('.' + id).remove();
} }
}, },
destroy: function() destroy: function()
{ {
this.destroy_content();
this._super();
this._cleanup_editor();
this._super();
}, },
destroy_content: function() destroy_content: function()
{ {
this._cleanup_editor(); this._cleanup_editor();
} }
}); });
instance.web_ckeditor4.FieldCKEditor4Raw = instance.web_ckeditor4.FieldCKEditor4.extend({
var FieldCKEditor4Raw = FieldCKEditor4.extend({
filter_html: function(value) filter_html: function(value)
{ {
return value; return value;
} }
}); });
}
core.form_widget_registry.add('text_ckeditor4', FieldCKEditor4);
core.form_widget_registry.add('text_ckeditor4_raw', FieldCKEditor4Raw);
core.form_widget_registry.add('text_html', FieldCKEditor4);
core.form_widget_registry.add('html', FieldCKEditor4);
return {
'FieldCKEditor4': FieldCKEditor4,
'FieldCKEditor4Raw': FieldCKEditor4Raw
}
});

25
web_ckeditor4/static/src/js/web_ckeditor4_formview.js

@ -0,0 +1,25 @@
odoo.define('web_ckeditor4.FormView', function(require) {
"use strict";
var core = require('web.core');
var FormView = core.view_registry.get('form');
FormView.include({
can_be_discarded: function(message) {
var self = this;
var res = this._super().done(function() {
// if form can be discarded
// we want to destroy all ck4 editor instances
for(name in CKEDITOR.instances){
if (self.fields.hasOwnProperty(name)){
self.fields[name].destroy_content();
}
}
});
return res;
}
});
});

2
web_ckeditor4/views/qweb.xml

@ -10,6 +10,8 @@
src="/web_ckeditor4/static/lib/ckeditor/ckeditor.js"></script> src="/web_ckeditor4/static/lib/ckeditor/ckeditor.js"></script>
<script type="text/javascript" <script type="text/javascript"
src="/web_ckeditor4/static/lib/ckeditor/config.js"></script> src="/web_ckeditor4/static/lib/ckeditor/config.js"></script>
<script type="text/javascript"
src="/web_ckeditor4/static/src/js/web_ckeditor4_formview.js"></script>
<script type="text/javascript" <script type="text/javascript"
src="/web_ckeditor4/static/src/js/web_ckeditor4.js"></script> src="/web_ckeditor4/static/src/js/web_ckeditor4.js"></script>
</xpath> </xpath>

Loading…
Cancel
Save