|
|
@ -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 |
|
|
|
} |
|
|
|
|
|
|
|
}); |