Browse Source

[ADD] web_ckeditor4

pull/2/head
Holger Brunn 12 years ago
parent
commit
be6498a0c9
  1. 22
      web_ckeditor4/__init__.py
  2. 49
      web_ckeditor4/__openerp__.py
  3. 6
      web_ckeditor4/static/src/css/web_ckeditor4.css
  4. 1
      web_ckeditor4/static/src/js/ckeditor_basepath.js
  5. 119
      web_ckeditor4/static/src/js/web_ckeditor4.js

22
web_ckeditor4/__init__.py

@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Therp BV (<http://therp.nl>)
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################

49
web_ckeditor4/__openerp__.py

@ -0,0 +1,49 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Therp BV (<http://therp.nl>)
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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': '',
}

6
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;
}

1
web_ckeditor4/static/src/js/ckeditor_basepath.js

@ -0,0 +1 @@
CKEDITOR_BASEPATH='/web_ckeditor4/static/lib/ckeditor/'

119
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 (<http://therp.nl>)
# 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 <http://www.gnu.org/licenses/>.
#
############################################################################*/
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;
}
});
}
Loading…
Cancel
Save