Browse Source

[FIX] introduce widget text_ckeditor4_raw to display unfiltered html

[IMP] filter html in text_ckeditor4
[FIX] only detach textarea on stop to circumvent issues with jquery
dialog
pull/2/head
Holger Brunn 12 years ago
parent
commit
c7adb6e405
  1. 2
      web_ckeditor4/static/src/css/web_ckeditor4.css
  2. 65
      web_ckeditor4/static/src/js/web_ckeditor4.js

2
web_ckeditor4/static/src/css/web_ckeditor4.css

@ -1,4 +1,4 @@
.openerp .oe_form_field_text_ckeditor4.disabled, .openerp td.oe_form_field_text_ckeditor4 {
.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
* have the HTML display as (probably) intended
*/

65
web_ckeditor4/static/src/js/web_ckeditor4.js

@ -28,21 +28,39 @@ openerp.web_ckeditor4 = function(openerp)
'openerp.web_ckeditor4.FieldCKEditor4');
openerp.web.page.readonly.add('text_ckeditor4',
'openerp.web_ckeditor4.FieldCKEditor4Readonly');
openerp.web.form.widgets.add('text_ckeditor4_raw',
'openerp.web_ckeditor4.FieldCKEditor4Raw');
openerp.web.page.readonly.add('text_ckeditor4_raw',
'openerp.web_ckeditor4.FieldCKEditor4ReadonlyRaw');
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)
function filter_html(value, ckeditor_filter, ckeditor_writer)
{
//TODO: it should be possible to use ckeditor to do the filtering
return value;
}
var fragment = CKEDITOR.htmlParser.fragment.fromHtml(value);
ckeditor_filter.applyTo(fragment);
ckeditor_writer.reset();
fragment.writeHtml(ckeditor_writer);
return ckeditor_writer.getHtml();
};
default_ckeditor_filter = new CKEDITOR.filter(
{
'*':
{
attributes: 'href,src,style,alt,width,height',
},
'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': true,
});
default_ckeditor_writer = new CKEDITOR.htmlParser.basicWriter();
openerp.web_ckeditor4.FieldCKEditor4 = openerp.web.form.FieldText.extend({
ckeditor_config: {
removePlugins: 'iframe,flash,forms,smiley,pagebreak,stylescombo',
},
ckeditor_filter: default_ckeditor_filter,
ckeditor_writer: default_ckeditor_writer,
start: function()
{
var self = this;
@ -57,21 +75,34 @@ openerp.web_ckeditor4 = function(openerp)
_.extend(
{
language: openerp.connection.user_context.lang.split('_')[0],
on:
{
'beforeUndoImage': function()
{
if(!self.is_dirty())
{
self.on_ui_change();
}
},
},
},
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;
},
filter_html: function(value)
{
return filter_html(value, this.ckeditor_filter, this.ckeditor_writer);
},
set_value: function(value)
{
if(this.modifiers.readonly)
{
this._super.apply(this, [value]);
this.$element.html(filter_html(value));
this.$element.html(this.filter_html(value));
return value;
}
else
@ -100,18 +131,34 @@ openerp.web_ckeditor4 = function(openerp)
{
if(this.editor)
{
this.editor.destroy(true);
this.editor = null;
this.$element.find('textarea').detach();
}
return this._super.apply(this, arguments);
}
});
openerp.web_ckeditor4.FieldCKEditor4Raw = openerp.web_ckeditor4.FieldCKEditor4.extend({
filter_html: function(value)
{
return value;
}
});
openerp.web_ckeditor4.FieldCKEditor4ReadonlyRaw = openerp.web.page.FieldCharReadonly.extend({
set_value: function (value)
{
this._super.apply(this, arguments);
this.$element.find('div').html(value);
return value;
}
});
openerp.web_ckeditor4.FieldCKEditor4Readonly = openerp.web.page.FieldCharReadonly.extend({
ckeditor_filter: default_ckeditor_filter,
ckeditor_writer: default_ckeditor_writer,
set_value: function (value)
{
this._super.apply(this, arguments);
this.$element.find('div').html(filter_html(value));
this.$element.find('div').html(filter_html(value, this.ckeditor_filter, this.ckeditor_writer));
return value;
}
});

Loading…
Cancel
Save