mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[PORT] Port web_ckeditor4 to 10.0
This commit is contained in:
committed by
Holger Brunn
parent
91bb28318e
commit
3371fe5f6b
@@ -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;
|
||||
|
||||
@@ -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
|
||||
@@ -33,17 +37,17 @@ openerp.web_ckeditor4 = function(instance)
|
||||
{
|
||||
var scope_reference = scope;
|
||||
return ckeditor_addFunction_org(function()
|
||||
{
|
||||
var self = this,
|
||||
self_arguments=arguments;
|
||||
setTimeout(function()
|
||||
{
|
||||
var self = this,
|
||||
self_arguments=arguments;
|
||||
setTimeout(function()
|
||||
{
|
||||
if(self.editor)
|
||||
{
|
||||
fn.apply(self, self_arguments);
|
||||
}
|
||||
}, 0);
|
||||
}, scope);
|
||||
}, scope);
|
||||
}
|
||||
return ckeditor_addFunction_org(fn, scope);
|
||||
};
|
||||
@@ -51,51 +55,41 @@ openerp.web_ckeditor4 = function(instance)
|
||||
CKEDITOR.on('dialogDefinition', function(e)
|
||||
{
|
||||
_.each(e.data.definition.contents, function(element)
|
||||
{
|
||||
if(!element || element.filebrowser!='uploadButton')
|
||||
{
|
||||
return
|
||||
}
|
||||
_.each(element.elements, function(element)
|
||||
{
|
||||
if(!element.onClick || element.type!='fileButton')
|
||||
if(!element || element.filebrowser!='uploadButton')
|
||||
{
|
||||
return
|
||||
}
|
||||
var onClick_org = element.onClick;
|
||||
element.onClick = function(e1)
|
||||
{
|
||||
onClick_org.apply(this, arguments);
|
||||
_.each(jQuery('#'+this.domId).closest('table')
|
||||
.find('iframe').contents().find(':file')
|
||||
.get(0).files,
|
||||
function(file)
|
||||
_.each(element.elements, function(element)
|
||||
{
|
||||
if(!element.onClick || element.type!='fileButton')
|
||||
{
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(load_event)
|
||||
{
|
||||
CKEDITOR.tools.callFunction(
|
||||
e.editor._.filebrowserFn,
|
||||
load_event.target.result,
|
||||
'');
|
||||
}
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
return
|
||||
}
|
||||
var onClick_org = element.onClick;
|
||||
element.onClick = function(e1)
|
||||
{
|
||||
onClick_org.apply(this, arguments);
|
||||
_.each(jQuery('#'+this.domId).closest('table')
|
||||
.find('iframe').contents().find(':file')
|
||||
.get(0).files,
|
||||
function(file)
|
||||
{
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(load_event)
|
||||
{
|
||||
CKEDITOR.tools.callFunction(
|
||||
e.editor._.filebrowserFn,
|
||||
load_event.target.result,
|
||||
'');
|
||||
}
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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,59 +99,70 @@ openerp.web_ckeditor4 = function(instance)
|
||||
return ckeditor_writer.getHtml();
|
||||
};
|
||||
|
||||
default_ckeditor_filter = new CKEDITOR.filter(
|
||||
var default_ckeditor_filter = new CKEDITOR.filter(
|
||||
{
|
||||
'*':
|
||||
{
|
||||
'*':
|
||||
{
|
||||
attributes: 'href,src,style,alt,width,height,dir',
|
||||
styles: '*',
|
||||
classes: '*',
|
||||
},
|
||||
'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',
|
||||
filebrowserImageUploadUrl: 'dummy',
|
||||
extraPlugins: 'filebrowser',
|
||||
// this is '#39' per default which screws up single quoted text in ${}
|
||||
entities_additional: '',
|
||||
attributes: 'href,src,style,alt,width,height,dir',
|
||||
styles: '*',
|
||||
classes: '*',
|
||||
},
|
||||
'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,
|
||||
});
|
||||
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: ''
|
||||
};
|
||||
},
|
||||
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),
|
||||
_.extend(
|
||||
{
|
||||
language: instance.session.user_context.lang.split('_')[0],
|
||||
on:
|
||||
} else if (!this.get('effective_readonly')) {
|
||||
|
||||
this.editor = CKEDITOR.replace(this.$el.get(0),
|
||||
_.extend(
|
||||
{
|
||||
'change': function()
|
||||
language: session.user_context.lang.split('_')[0],
|
||||
on:
|
||||
{
|
||||
self.store_dom_value();
|
||||
'change': function()
|
||||
{
|
||||
self.store_dom_value();
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
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,28 +202,37 @@ 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._super();
|
||||
this._cleanup_editor();
|
||||
this._super();
|
||||
},
|
||||
destroy_content: function()
|
||||
{
|
||||
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
Normal file
25
web_ckeditor4/static/src/js/web_ckeditor4_formview.js
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user