Merge lp:~therp-nl/web-addons/7.0_web_ckeditor into lp:~webaddons-core-editors/web-addons/7.0

Proposed by Holger Brunn (Therp)
Status: Merged
Merged at revision: 14
Proposed branch: lp:~therp-nl/web-addons/7.0_web_ckeditor
Merge into: lp:~webaddons-core-editors/web-addons/7.0
Prerequisite: lp:~therp-nl/web-addons/7.0_web_ckeditor_ckeditor
Diff against target: 390 lines (+360/-0)
5 files modified
web_ckeditor4/__init__.py (+22/-0)
web_ckeditor4/__openerp__.py (+114/-0)
web_ckeditor4/static/src/css/web_ckeditor4.css (+6/-0)
web_ckeditor4/static/src/js/ckeditor_basepath.js (+1/-0)
web_ckeditor4/static/src/js/web_ckeditor4.js (+217/-0)
To merge this branch: bzr merge lp:~therp-nl/web-addons/7.0_web_ckeditor
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review, test Approve
Stefan Rijnhart (Opener) Approve
Review via email: mp+200564@code.launchpad.net

Commit message

[ADD] web_ckeditor4

Description of the change

This adds the 7.0 version of the ckeditor4 widget.

Why do we want that? OpenERP's standard HTML editor (cleditor) has problems with complex layouts, doesn't support a simple way to 'upload' images into a data URL and possibly some users are simply more comfortable with ckeditor.

Note: I put the branch containing the lib/ckeditor directory into its own branch (added as prerequisite). This is to avoid noise in the diff. It's ckeditor 4.3.1 as you can download it today.

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Much interesting! Thanks

I have an error when activating the spellchecker (Enable SCAYT) then click on a spellcheck menu (dictionaries or languages) on chromium: Cannot read property 'filebrowser' of undefined on this line "if(element.filebrowser!='uploadButton')"

review: Needs Fixing
16. By Holger Brunn (Therp)

[FIX] accessing undefined variable

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

Thanks!

I can't really reproduce this, but the last commit should fix it anyway.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks! I compared this version with the 6.1 version and the changes in the OpenERP part make sense. Also gave it a test run. It works pretty neat. Could not reproduce the error with SCAYT spell checking.

review: Approve
Revision history for this message
Sylvain LE GAL (GRAP) (sylvain-legal) wrote :

Thanks !

LGTM.

review: Approve (functional test)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Sorry for blocking this proposal for so long. I retested and it works flawlessly since ou.

Thanks!

review: Approve (code review, test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'web_ckeditor4/__init__.py'
2--- web_ckeditor4/__init__.py 1970-01-01 00:00:00 +0000
3+++ web_ckeditor4/__init__.py 2014-01-31 16:58:41 +0000
4@@ -0,0 +1,22 @@
5+# -*- encoding: utf-8 -*-
6+##############################################################################
7+#
8+# OpenERP, Open Source Management Solution
9+# This module copyright (C) 2013 Therp BV (<http://therp.nl>)
10+# All Rights Reserved
11+#
12+# This program is free software: you can redistribute it and/or modify
13+# it under the terms of the GNU Affero General Public License as
14+# published by the Free Software Foundation, either version 3 of the
15+# License, or (at your option) any later version.
16+#
17+# This program is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU Affero General Public License for more details.
21+#
22+# You should have received a copy of the GNU Affero General Public License
23+# along with this program. If not, see <http://www.gnu.org/licenses/>.
24+#
25+##############################################################################
26+
27
28=== added file 'web_ckeditor4/__openerp__.py'
29--- web_ckeditor4/__openerp__.py 1970-01-01 00:00:00 +0000
30+++ web_ckeditor4/__openerp__.py 2014-01-31 16:58:41 +0000
31@@ -0,0 +1,114 @@
32+# -*- encoding: utf-8 -*-
33+##############################################################################
34+#
35+# OpenERP, Open Source Management Solution
36+# This module copyright (C) 2013 Therp BV (<http://therp.nl>)
37+# All Rights Reserved
38+#
39+# This program is free software: you can redistribute it and/or modify
40+# it under the terms of the GNU Affero General Public License as
41+# published by the Free Software Foundation, either version 3 of the
42+# License, or (at your option) any later version.
43+#
44+# This program is distributed in the hope that it will be useful,
45+# but WITHOUT ANY WARRANTY; without even the implied warranty of
46+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47+# GNU Affero General Public License for more details.
48+#
49+# You should have received a copy of the GNU Affero General Public License
50+# along with this program. If not, see <http://www.gnu.org/licenses/>.
51+#
52+##############################################################################
53+
54+{
55+ 'name': 'CKEditor 4.x widget',
56+ 'version': '1.0',
57+ 'description': """
58+ This addon provides a widget for editing html fields via CKEditor 4.x
59+
60+ Use widget="text_html" if you need just html display. In the unlikely case
61+ you need specific features of ckeditor, use widget="text_ckeditor4".
62+ """,
63+ 'author': 'Therp BV',
64+ 'website': 'http://www.therp.nl',
65+ "category": "Tools",
66+ "depends": [
67+ 'web',
68+ ],
69+ 'css': [
70+ 'static/src/css/web_ckeditor4.css',
71+ ],
72+ 'data': [
73+ ],
74+ 'js': [
75+ 'static/src/js/ckeditor_basepath.js',
76+ 'static/lib/ckeditor/ckeditor.js',
77+ 'static/lib/ckeditor/config.js',
78+ #to debug ckeditor, comment the lines above,
79+ #do a
80+ #cd static/lib
81+ #git clone https://github.com/ckeditor/ckeditor-dev.git trunk
82+ #cd trunk
83+ #git checkout remotes/origin/release/4.1.x
84+ #and uncomment the lines below
85+# 'static/lib/trunk/ckeditor.js',
86+# 'static/lib/trunk/core/event.js',
87+# 'static/lib/trunk/core/editor_basic.js',
88+# 'static/lib/trunk/core/env.js',
89+# 'static/lib/trunk/core/ckeditor_basic.js',
90+# 'static/lib/trunk/core/dom.js',
91+# 'static/lib/trunk/core/tools.js',
92+# 'static/lib/trunk/core/dtd.js',
93+# 'static/lib/trunk/core/dom/event.js',
94+# 'static/lib/trunk/core/dom/domobject.js',
95+# 'static/lib/trunk/core/dom/node.js',
96+# 'static/lib/trunk/core/dom/window.js',
97+# 'static/lib/trunk/core/dom/document.js',
98+# 'static/lib/trunk/core/dom/nodelist.js',
99+# 'static/lib/trunk/core/dom/element.js',
100+# 'static/lib/trunk/core/dom/documentfragment.js',
101+# 'static/lib/trunk/core/dom/walker.js',
102+# 'static/lib/trunk/core/dom/range.js',
103+# 'static/lib/trunk/core/dom/iterator.js',
104+# 'static/lib/trunk/core/command.js',
105+# 'static/lib/trunk/core/ckeditor_base.js',
106+# 'static/lib/trunk/core/config.js',
107+# 'static/lib/trunk/core/filter.js',
108+# 'static/lib/trunk/core/focusmanager.js',
109+# 'static/lib/trunk/core/keystrokehandler.js',
110+# 'static/lib/trunk/core/lang.js',
111+# 'static/lib/trunk/core/scriptloader.js',
112+# 'static/lib/trunk/core/resourcemanager.js',
113+# 'static/lib/trunk/core/plugins.js',
114+# 'static/lib/trunk/core/ui.js',
115+# 'static/lib/trunk/core/editor.js',
116+# 'static/lib/trunk/core/htmlparser.js',
117+# 'static/lib/trunk/core/htmlparser/basicwriter.js',
118+# 'static/lib/trunk/core/htmlparser/node.js',
119+# 'static/lib/trunk/core/htmlparser/comment.js',
120+# 'static/lib/trunk/core/htmlparser/text.js',
121+# 'static/lib/trunk/core/htmlparser/cdata.js',
122+# 'static/lib/trunk/core/htmlparser/fragment.js',
123+# 'static/lib/trunk/core/htmlparser/filter.js',
124+# 'static/lib/trunk/core/htmldataprocessor.js',
125+# 'static/lib/trunk/core/htmlparser/element.js',
126+# 'static/lib/trunk/core/template.js',
127+# 'static/lib/trunk/core/ckeditor.js',
128+# 'static/lib/trunk/core/creators/inline.js',
129+# 'static/lib/trunk/core/creators/themedui.js',
130+# 'static/lib/trunk/core/editable.js',
131+# 'static/lib/trunk/core/selection.js',
132+# 'static/lib/trunk/core/style.js',
133+# 'static/lib/trunk/core/dom/comment.js',
134+# 'static/lib/trunk/core/dom/elementpath.js',
135+# 'static/lib/trunk/core/dom/text.js',
136+# 'static/lib/trunk/core/dom/rangelist.js',
137+# 'static/lib/trunk/core/skin.js',
138+# 'static/lib/trunk/core/_bootstrap.js',
139+ #end of ckeditor debug
140+ 'static/src/js/web_ckeditor4.js',
141+ ],
142+ 'installable': True,
143+ 'auto_install': False,
144+ 'certificate': '',
145+}
146
147=== added directory 'web_ckeditor4/static/src'
148=== added directory 'web_ckeditor4/static/src/css'
149=== added file 'web_ckeditor4/static/src/css/web_ckeditor4.css'
150--- web_ckeditor4/static/src/css/web_ckeditor4.css 1970-01-01 00:00:00 +0000
151+++ web_ckeditor4/static/src/css/web_ckeditor4.css 2014-01-31 16:58:41 +0000
152@@ -0,0 +1,6 @@
153+.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 {
154+ /* here we need to reset openerp's styles to
155+ * have the HTML display as (probably) intended
156+ */
157+ white-space: normal;
158+}
159
160=== added directory 'web_ckeditor4/static/src/img'
161=== added file 'web_ckeditor4/static/src/img/icon.png'
162Binary files web_ckeditor4/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and web_ckeditor4/static/src/img/icon.png 2014-01-31 16:58:41 +0000 differ
163=== added directory 'web_ckeditor4/static/src/js'
164=== added file 'web_ckeditor4/static/src/js/ckeditor_basepath.js'
165--- web_ckeditor4/static/src/js/ckeditor_basepath.js 1970-01-01 00:00:00 +0000
166+++ web_ckeditor4/static/src/js/ckeditor_basepath.js 2014-01-31 16:58:41 +0000
167@@ -0,0 +1,1 @@
168+CKEDITOR_BASEPATH='/web_ckeditor4/static/lib/ckeditor/'
169
170=== added file 'web_ckeditor4/static/src/js/web_ckeditor4.js'
171--- web_ckeditor4/static/src/js/web_ckeditor4.js 1970-01-01 00:00:00 +0000
172+++ web_ckeditor4/static/src/js/web_ckeditor4.js 2014-01-31 16:58:41 +0000
173@@ -0,0 +1,217 @@
174+/* -*- encoding: utf-8 -*-
175+##############################################################################
176+#
177+# OpenERP, Open Source Management Solution
178+# This module copyright (C) 2013 Therp BV (<http://therp.nl>)
179+# All Rights Reserved
180+#
181+# This program is free software: you can redistribute it and/or modify
182+# it under the terms of the GNU Affero General Public License as
183+# published by the Free Software Foundation, either version 3 of the
184+# License, or (at your option) any later version.
185+#
186+# This program is distributed in the hope that it will be useful,
187+# but WITHOUT ANY WARRANTY; without even the implied warranty of
188+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
189+# GNU Affero General Public License for more details.
190+#
191+# You should have received a copy of the GNU Affero General Public License
192+# along with this program. If not, see <http://www.gnu.org/licenses/>.
193+#
194+############################################################################*/
195+
196+openerp.web_ckeditor4 = function(openerp)
197+{
198+ var ckeditor_addFunction_org = CKEDITOR.tools.addFunction;
199+ //this is a quite complicated way to kind of monkey patch the private
200+ //method onDomReady of ckeditor's plugin wysiwigarea, which causes problems
201+ //when the editor is about to be destroyed but because of OpenERP's
202+ //architecture updated one last time with its current value
203+ CKEDITOR.tools.addFunction = function(fn, scope)
204+ {
205+ if(scope && scope._ && scope._.attrChanges && scope._.detach)
206+ {
207+ var scope_reference = scope;
208+ return ckeditor_addFunction_org(function()
209+ {
210+ var self = this,
211+ self_arguments=arguments;
212+ setTimeout(function()
213+ {
214+ if(CKEDITOR.instances[self.editor.name])
215+ {
216+ fn.apply(self, self_arguments);
217+ }
218+ }, 0);
219+ }, scope);
220+ }
221+ return ckeditor_addFunction_org(fn, scope);
222+ };
223+
224+ CKEDITOR.on('dialogDefinition', function(e)
225+ {
226+ _.each(e.data.definition.contents, function(element)
227+ {
228+ if(!element || element.filebrowser!='uploadButton')
229+ {
230+ return
231+ }
232+ _.each(element.elements, function(element)
233+ {
234+ if(!element.onClick || element.type!='fileButton')
235+ {
236+ return
237+ }
238+ var onClick_org = element.onClick;
239+ element.onClick = function(e1)
240+ {
241+ onClick_org.apply(this, arguments);
242+ _.each(jQuery('#'+this.domId).closest('table')
243+ .find('iframe').contents().find(':file')
244+ .get(0).files,
245+ function(file)
246+ {
247+ var reader = new FileReader();
248+ reader.onload = function(load_event)
249+ {
250+ CKEDITOR.tools.callFunction(
251+ e.editor._.filebrowserFn,
252+ load_event.target.result,
253+ '');
254+ }
255+ reader.readAsDataURL(file);
256+ });
257+ return false;
258+ }
259+ });
260+ });
261+ });
262+
263+ openerp.web.form.widgets.add('text_ckeditor4',
264+ 'openerp.web_ckeditor4.FieldCKEditor4');
265+ openerp.web.form.widgets.add('text_ckeditor4_raw',
266+ 'openerp.web_ckeditor4.FieldCKEditor4Raw');
267+ openerp.web.form.widgets.add('text_html',
268+ 'openerp.web_ckeditor4.FieldCKEditor4');
269+ openerp.web.form.widgets.add('html',
270+ 'openerp.web_ckeditor4.FieldCKEditor4');
271+
272+ function filter_html(value, ckeditor_filter, ckeditor_writer)
273+ {
274+ var fragment = CKEDITOR.htmlParser.fragment.fromHtml(value);
275+ ckeditor_filter.applyTo(fragment);
276+ ckeditor_writer.reset();
277+ fragment.writeHtml(ckeditor_writer);
278+ return ckeditor_writer.getHtml();
279+ };
280+
281+ default_ckeditor_filter = new CKEDITOR.filter(
282+ {
283+ '*':
284+ {
285+ attributes: 'href,src,style,alt,width,height,dir',
286+ styles: '*',
287+ classes: '*',
288+ },
289+ '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,
290+ });
291+ default_ckeditor_writer = new CKEDITOR.htmlParser.basicWriter();
292+
293+ openerp.web_ckeditor4.FieldCKEditor4 = openerp.web.form.FieldText.extend({
294+ ckeditor_config: {
295+ removePlugins: 'iframe,flash,forms,smiley,pagebreak,stylescombo',
296+ filebrowserImageUploadUrl: 'dummy',
297+ extraPlugins: 'filebrowser',
298+ },
299+ ckeditor_filter: default_ckeditor_filter,
300+ ckeditor_writer: default_ckeditor_writer,
301+ start: function()
302+ {
303+ this._super.apply(this, arguments);
304+
305+ CKEDITOR.lang.load(openerp.session.user_context.lang.split('_')[0], 'en', function() {});
306+ },
307+ initialize_content: function()
308+ {
309+ var self = this;
310+ this._super.apply(this, arguments);
311+ if(!this.$textarea)
312+ {
313+ return;
314+ }
315+ this.editor = CKEDITOR.replace(this.$textarea.get(0),
316+ _.extend(
317+ {
318+ language: openerp.session.user_context.lang.split('_')[0],
319+ on:
320+ {
321+ 'change': function()
322+ {
323+ self.store_dom_value();
324+ },
325+ },
326+ },
327+ this.ckeditor_config));
328+ },
329+ store_dom_value: function()
330+ {
331+ this.internal_set_value(this.editor ? this.editor.getData() : openerp.web.parse_value(this.get('value'), this));
332+ },
333+ filter_html: function(value)
334+ {
335+ return filter_html(value, this.ckeditor_filter, this.ckeditor_writer);
336+ },
337+ render_value: function()
338+ {
339+ if(this.get("effective_readonly"))
340+ {
341+ this.$el.html(this.filter_html(this.get('value')));
342+ }
343+ else
344+ {
345+ if(this.editor)
346+ {
347+ var self = this;
348+ if(this.editor.status != 'ready')
349+ {
350+ var instanceReady = function()
351+ {
352+ self.editor.setData(self.get('value') || '');
353+ self.editor.removeListener('instanceReady', instanceReady);
354+ };
355+ this.editor.on('instanceReady', instanceReady);
356+ }
357+ else
358+ {
359+ self.editor.setData(self.get('value') || '');
360+ }
361+ }
362+ }
363+ },
364+ undelegateEvents: function()
365+ {
366+ this._cleanup_editor();
367+ return this._super.apply(this, arguments);
368+ },
369+ _cleanup_editor: function()
370+ {
371+ if(this.editor)
372+ {
373+ CKEDITOR.remove(this.editor);
374+ this.editor.removeAllListeners();
375+ this.editor = null;
376+ }
377+ },
378+ destroy_content: function()
379+ {
380+ this._cleanup_editor();
381+ }
382+ });
383+ openerp.web_ckeditor4.FieldCKEditor4Raw = openerp.web_ckeditor4.FieldCKEditor4.extend({
384+ filter_html: function(value)
385+ {
386+ return value;
387+ }
388+ });
389+}
390+

Subscribers

People subscribed via source and target branches