forked from Techsystech/web
[PORT] Port web_ckeditor4 to 10.0
parent
f8fcfbbf2a
commit
e052085420
|
@ -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
|
: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.
|
||||||
|
|
||||||
Configuration
|
Usage
|
||||||
=============
|
=====
|
||||||
|
|
||||||
In your view definition, use widget="text_html" if you need just html display.
|
To use this module, you need to:
|
||||||
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
|
||||||
======================
|
======================
|
||||||
|
@ -24,21 +31,26 @@ 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>`_.
|
Bugs are tracked on `GitHub Issues
|
||||||
In case of trouble, please check there if your issue has already been reported.
|
<https://github.com/OCA/{project_repo}/issues>`_. In case of trouble, please
|
||||||
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
|
check there if your issue has already been reported. If you spotted it first,
|
||||||
`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**>`_.
|
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>
|
* Holger Brunn <hbrunn@therp.nl>
|
||||||
* Stefan Rijnhart <stefan@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
|
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.
|
||||||
|
|
|
@ -1,28 +1,9 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
# Copyright 2018 Therp BV <https://therp.nl>
|
||||||
#
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
# 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/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
{
|
{
|
||||||
'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',
|
||||||
|
@ -107,7 +88,6 @@
|
||||||
#end of ckeditor debug
|
#end of ckeditor debug
|
||||||
'static/src/js/web_ckeditor4.js',
|
'static/src/js/web_ckeditor4.js',
|
||||||
],
|
],
|
||||||
'installable': False,
|
'installable': True,
|
||||||
'auto_install': False,
|
'auto_install': False,
|
||||||
'certificate': '',
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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 {
|
.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 openerp's styles to
|
/* 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;
|
||||||
|
|
|
@ -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
|
||||||
|
@ -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)
|
function filter_html(value, ckeditor_filter, ckeditor_writer)
|
||||||
{
|
{
|
||||||
var fragment = CKEDITOR.htmlParser.fragment.fromHtml(value);
|
var fragment = CKEDITOR.htmlParser.fragment.fromHtml(value);
|
||||||
|
@ -105,7 +99,7 @@ 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(
|
||||||
{
|
{
|
||||||
'*':
|
'*':
|
||||||
{
|
{
|
||||||
|
@ -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,
|
'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();
|
var default_ckeditor_writer = new CKEDITOR.htmlParser.basicWriter();
|
||||||
|
var FieldCKEditor4 = core.form_widget_registry.get('text').extend({
|
||||||
instance.web_ckeditor4.FieldCKEditor4 = instance.web.form.FieldText.extend({
|
ckeditor_config: function () {
|
||||||
ckeditor_config: {
|
return {
|
||||||
removePlugins: 'iframe,flash,forms,smiley,pagebreak,stylescombo',
|
removePlugins: this._getRemovePlugins(),
|
||||||
|
removeButtons: this._getRemoveButtons(),
|
||||||
filebrowserImageUploadUrl: 'dummy',
|
filebrowserImageUploadUrl: 'dummy',
|
||||||
extraPlugins: 'filebrowser',
|
extraPlugins: 'filebrowser',
|
||||||
// this is '#39' per default which screws up single quoted text in ${}
|
// this is '#39' per default which screws up single quoted text in ${}
|
||||||
entities_additional: '',
|
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(session.user_context.lang.split('_')[0], 'en', function() {});
|
||||||
CKEDITOR.lang.load(instance.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;
|
||||||
}
|
} else if (!this.get('effective_readonly')) {
|
||||||
this.editor = CKEDITOR.replace(this.$textarea.get(0),
|
|
||||||
|
this.editor = CKEDITOR.replace(this.$el.get(0),
|
||||||
_.extend(
|
_.extend(
|
||||||
{
|
{
|
||||||
language: instance.session.user_context.lang.split('_')[0],
|
language: session.user_context.lang.split('_')[0],
|
||||||
on:
|
on:
|
||||||
{
|
{
|
||||||
'change': function()
|
'change': function()
|
||||||
|
@ -153,11 +155,14 @@ openerp.web_ckeditor4 = function(instance)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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,16 +202,18 @@ 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._cleanup_editor();
|
||||||
this._super();
|
this._super();
|
||||||
},
|
},
|
||||||
destroy_content: function()
|
destroy_content: function()
|
||||||
|
@ -214,11 +221,18 @@ openerp.web_ckeditor4 = function(instance)
|
||||||
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
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -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…
Reference in New Issue