From be6498a0c91c23633770da1a024e34fb08009c30 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Fri, 12 Apr 2013 18:50:31 +0200 Subject: [PATCH] [ADD] web_ckeditor4 --- web_ckeditor4/__init__.py | 22 ++++ web_ckeditor4/__openerp__.py | 49 ++++++++ .../static/src/css/web_ckeditor4.css | 6 + .../static/src/js/ckeditor_basepath.js | 1 + web_ckeditor4/static/src/js/web_ckeditor4.js | 119 ++++++++++++++++++ 5 files changed, 197 insertions(+) create mode 100644 web_ckeditor4/__init__.py create mode 100644 web_ckeditor4/__openerp__.py create mode 100644 web_ckeditor4/static/src/css/web_ckeditor4.css create mode 100644 web_ckeditor4/static/src/js/ckeditor_basepath.js create mode 100644 web_ckeditor4/static/src/js/web_ckeditor4.js diff --git a/web_ckeditor4/__init__.py b/web_ckeditor4/__init__.py new file mode 100644 index 00000000..a97ee816 --- /dev/null +++ b/web_ckeditor4/__init__.py @@ -0,0 +1,22 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV () +# 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 . +# +############################################################################## + diff --git a/web_ckeditor4/__openerp__.py b/web_ckeditor4/__openerp__.py new file mode 100644 index 00000000..f75178ed --- /dev/null +++ b/web_ckeditor4/__openerp__.py @@ -0,0 +1,49 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV () +# 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 . +# +############################################################################## + +{ + 'name': 'CKEditor 4.x widget', + 'version': '1.0', + 'description': """ + This addon provides a widget for editing html fields via CKEditor 4.x + """, + 'author': 'Therp BV', + 'website': 'http://www.therp.nl', + "category": "Tools", + "depends": [ + 'web', + ], + 'css': [ + 'static/src/css/web_ckeditor4.css', + ], + 'data': [ + ], + 'js': [ + 'static/src/js/ckeditor_basepath.js', + 'static/lib/ckeditor/ckeditor.js', + 'static/lib/ckeditor/config.js', + 'static/src/js/web_ckeditor4.js', + ], + 'installable': True, + 'active': False, + 'certificate': '', +} diff --git a/web_ckeditor4/static/src/css/web_ckeditor4.css b/web_ckeditor4/static/src/css/web_ckeditor4.css new file mode 100644 index 00000000..89a730c9 --- /dev/null +++ b/web_ckeditor4/static/src/css/web_ckeditor4.css @@ -0,0 +1,6 @@ +.openerp .oe_form_field_text_ckeditor4.disabled { + /* here we need to reset openerp's styles to + * have the HTML display as (probably) intended + */ + white-space: normal; +} diff --git a/web_ckeditor4/static/src/js/ckeditor_basepath.js b/web_ckeditor4/static/src/js/ckeditor_basepath.js new file mode 100644 index 00000000..930a6c40 --- /dev/null +++ b/web_ckeditor4/static/src/js/ckeditor_basepath.js @@ -0,0 +1 @@ +CKEDITOR_BASEPATH='/web_ckeditor4/static/lib/ckeditor/' diff --git a/web_ckeditor4/static/src/js/web_ckeditor4.js b/web_ckeditor4/static/src/js/web_ckeditor4.js new file mode 100644 index 00000000..94c3a73a --- /dev/null +++ b/web_ckeditor4/static/src/js/web_ckeditor4.js @@ -0,0 +1,119 @@ +/* -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV () +# 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 . +# +############################################################################*/ + +openerp.web_ckeditor4 = function(openerp) +{ + CKEDITOR.lang.load(openerp.connection.user_context.lang.split('_')[0], 'en', function() {}); + + openerp.web.form.widgets.add('text_ckeditor4', + 'openerp.web_ckeditor4.FieldCKEditor4'); + openerp.web.page.readonly.add('text_ckeditor4', + 'openerp.web_ckeditor4.FieldCKEditor4Readonly'); + openerp.web.form.widgets.add('text_html', + 'openerp.web_ckeditor4.FieldCKEditor4'); + openerp.web.page.readonly.add('text_html', + 'openerp.web_ckeditor4.FieldCKEditor4Readonly'); + + function filter_html(value) + { + //TODO: it should be possible to use ckeditor to do the filtering + return value; + } + + openerp.web_ckeditor4.FieldCKEditor4 = openerp.web.form.FieldText.extend({ + ckeditor_config: { + removePlugins: 'iframe,flash,forms,smiley,pagebreak,stylescombo', + }, + start: function() + { + var self = this; + this._super.apply(this, arguments); + + if(this.modifiers.readonly) + { + return; + } + + self.editor = CKEDITOR.replace(this.$element.find('textarea').get(0), + _.extend( + { + language: openerp.connection.user_context.lang.split('_')[0], + }, + this.ckeditor_config)); + self.editor.once('beforeUndoImage', function () { self.on_ui_change() }); + }, + get_value: function() + { + return this.editor ? openerp.web.parse_value(this.editor.getData(), this) : this.value; + }, + set_value: function(value) + { + if(this.modifiers.readonly) + { + this._super.apply(this, [value]); + + this.$element.html(filter_html(value)); + return value; + } + else + { + if(this.editor) + { + var self = this; + if(this.editor.status != 'ready') + { + this.editor.on('instanceReady', + function() + { + self.editor.setData(value || ''); + }); + } + else + { + self.editor.setData(value || ''); + } + } + this._super.apply(this, arguments); + } + }, + + stop: function() + { + if(this.editor) + { + this.editor.destroy(true); + this.editor = null; + } + return this._super.apply(this, arguments); + } + }); + + openerp.web_ckeditor4.FieldCKEditor4Readonly = openerp.web.page.FieldCharReadonly.extend({ + set_value: function (value) + { + this._super.apply(this, arguments); + this.$element.find('div').html(filter_html(value)); + return value; + } + }); +} +