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. 40
      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. 76
      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

40
web_ckeditor4/README.rst

@ -1,17 +1,24 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
.. 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
===================
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
=====
To use this module, you need to:
Configuration
=============
#. Go 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".
.. 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
======================
@ -24,21 +31,26 @@ as https://github.com/ckeditor/ckeditor-dev/pull/200
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
=======
CKEditor 4.4.6 Copyright (C) 2003-2015 CKSource - Frederico Knabben
Images
------
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
Contributors
------------
* Holger Brunn <hbrunn@therp.nl>
* Stefan Rijnhart <stefan@therp.nl>
* George Daramouskas <gdaramouskas@therp.nl>
Do not contact contributors directly about support or help with technical issues.
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
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',
'version': '8.0.1.0.0',
'version': '10.0.1.0.0',
'author': "Therp BV,Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/web',
'summary': 'Provides a widget for editing HTML fields using CKEditor 4.x',
@ -37,7 +18,6 @@
'css': [
'static/src/css/web_ckeditor4.css',
],
'installable': False,
'installable': True,
'auto_install': False,
'certificate': '',
}

4
web_ckeditor4/models/ckeditor_monkeypatch.py

@ -27,7 +27,7 @@ class CkeditorMonkeypatch(models.AbstractModel):
_name = 'ckeditor.monkeypatch'
_description = 'Monkeypatches for CKEditor'
def _register_hook(self, cr):
def _register_hook(self):
marker = self._name.replace('.', '_')
if not hasattr(clean, marker):
# 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
# urls were not cleaned at all
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
*/
white-space: normal;

76
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;
//this is a quite complicated way to kind of monkey patch the private
//method onDomReady of ckeditor's plugin wysiwigarea, which causes problems
@ -86,16 +90,6 @@ openerp.web_ckeditor4 = function(instance)
});
});
});
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)
{
var fragment = CKEDITOR.htmlParser.fragment.fromHtml(value);
@ -105,7 +99,7 @@ openerp.web_ckeditor4 = function(instance)
return ckeditor_writer.getHtml();
};
default_ckeditor_filter = new CKEDITOR.filter(
var default_ckeditor_filter = new CKEDITOR.filter(
{
'*':
{
@ -115,36 +109,44 @@ openerp.web_ckeditor4 = function(instance)
},
'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',
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: '',
entities_additional: ''
};
},
ckeditor_filter: default_ckeditor_filter,
ckeditor_writer: default_ckeditor_writer,
_getRemovePlugins: function () {
return 'iframe,flash,forms,smiley,pagebreak,stylescombo';
},
_getRemoveButtons: function () {
return '';
},
start: function()
{
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()
{
var self = this;
this._super.apply(this, arguments);
if(!this.$textarea)
if(!this.$el)
{
return;
}
this.editor = CKEDITOR.replace(this.$textarea.get(0),
} else if (!this.get('effective_readonly')) {
this.editor = CKEDITOR.replace(this.$el.get(0),
_.extend(
{
language: instance.session.user_context.lang.split('_')[0],
language: session.user_context.lang.split('_')[0],
on:
{
'change': function()
@ -153,11 +155,14 @@ openerp.web_ckeditor4 = function(instance)
},
},
},
this.ckeditor_config));
self.ckeditor_config()
)
);
}
},
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)
{
@ -197,16 +202,18 @@ openerp.web_ckeditor4 = function(instance)
},
_cleanup_editor: function()
{
if(this.editor)
if(this.editor && this.editor.status != 'unloaded')
{
var id = this.editor.id
this.editor.removeAllListeners();
this.editor.destroy();
this.editor = null;
$('.' + id).remove();
}
},
destroy: function()
{
this.destroy_content();
this._cleanup_editor();
this._super();
},
destroy_content: function()
@ -214,11 +221,18 @@ openerp.web_ckeditor4 = function(instance)
this._cleanup_editor();
}
});
instance.web_ckeditor4.FieldCKEditor4Raw = instance.web_ckeditor4.FieldCKEditor4.extend({
var FieldCKEditor4Raw = FieldCKEditor4.extend({
filter_html: function(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>
<script type="text/javascript"
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"
src="/web_ckeditor4/static/src/js/web_ckeditor4.js"></script>
</xpath>

Loading…
Cancel
Save