@ -49,12 +49,32 @@ odoo.define('web_ckeditor4', function(require){
init : function ( ) {
init : function ( ) {
this . _super . apply ( this , arguments ) ;
this . _super . apply ( this , arguments ) ;
this . editor_lang = session . user_context . lang . split ( '_' ) [ 0 ] ;
this . editor_lang = session . user_context . lang . split ( '_' ) [ 0 ] ;
this . view . on ( "load_record" , this , this . _on_load_record ) ;
} ,
} ,
start : function ( )
start : function ( )
{
{
this . _super . apply ( this , arguments ) ;
this . _super . apply ( this , arguments ) ;
CKEDITOR . lang . load ( this . editor_lang , 'en' , function ( ) { } ) ;
CKEDITOR . lang . load ( this . editor_lang , 'en' , function ( ) { } ) ;
} ,
} ,
_on_load_record : function ( ) {
/ * F i x w i d g e t n o t r e - i n i t i a l i z e d o n f o r m d i s c a r d .
When you hit "cancel" button or when you navigate away
from the form , for instance by clicking on the breadcrumb
or on "edit translations" , we have to remove the CKEditor widget .
BUT then if you hit "create" Odoo ' s form machinery is not initializing
the widget anymore ( which really sounds inconsistent ) .
If the widget is not initialized again it means that if CKEditor
got destroyed there ' s no way to re - init again .
Here we make sure that on create ( no id on datarecord )
if the editor is not initialized yet we force it .
* /
if ( ! this . view . datarecord . id && ! this . editor ) {
this . initialize_content ( ) ;
}
} ,
initialize_content : function ( )
initialize_content : function ( )
{
{
var self = this ;
var self = this ;
@ -62,8 +82,7 @@ odoo.define('web_ckeditor4', function(require){
if ( ! this . $el )
if ( ! this . $el )
{
{
return ;
return ;
} else if ( ! this . get ( 'effective_readonly' ) ) {
} else if ( ! this . get ( 'effective_readonly' ) && ! this . editor ) {
this . editor = CKEDITOR . replace ( this . $el . get ( 0 ) ,
this . editor = CKEDITOR . replace ( this . $el . get ( 0 ) ,
_ . extend (
_ . extend (
{
{
@ -116,6 +135,9 @@ odoo.define('web_ckeditor4', function(require){
}
}
}
}
} ,
} ,
destroy_content : function ( ) {
this . _cleanup_editor ( ) ;
} ,
undelegateEvents : function ( )
undelegateEvents : function ( )
{
{
this . _cleanup_editor ( ) ;
this . _cleanup_editor ( ) ;
@ -123,35 +145,35 @@ odoo.define('web_ckeditor4', function(require){
} ,
} ,
_cleanup_editor : function ( )
_cleanup_editor : function ( )
{
{
if ( this . editor && this . editor . status != 'unloaded ')
if ( this . editor && this . editor . status == 'ready ')
{
{
var id = this . editor . id
CKEDITOR . remove ( this . editor . name ) ;
$ ( '#cke_' + this . editor . name ) . remove ( ) ;
this . editor . removeAllListeners ( ) ;
this . editor . removeAllListeners ( ) ;
this . editor . destroy ( ) ;
this . editor . destroy ( ) ;
this . editor = null ;
this . editor = null ;
$ ( '.' + id ) . remove ( ) ;
}
}
} ,
} ,
destroy : function ( )
destroy : function ( )
{
{
this . view . off ( "load_record" , this , this . _on_load_record ) ;
this . _cleanup_editor ( ) ;
this . _cleanup_editor ( ) ;
this . _super ( ) ;
this . _super ( ) ;
} ,
destroy_content : function ( )
{
this . _cleanup_editor ( ) ;
}
}
} ) ;
} ) ;
var FieldCKEditor4Raw = FieldCKEditor4 . extend ( {
var FieldCKEditor4Raw = FieldCKEditor4 . extend ( {
filter_html : function ( value )
filter_html : function ( value )
{
{
return value ;
return value ;
}
}
} ) ;
} ) ;
core . form_widget_registry . add ( 'text_ckeditor4' , FieldCKEditor4 ) ;
core . form_widget_registry . add ( 'text_ckeditor4' , FieldCKEditor4 ) ;
core . form_widget_registry . add ( 'text_ckeditor4_raw' , FieldCKEditor4Raw ) ;
core . form_widget_registry . add ( 'text_ckeditor4_raw' , FieldCKEditor4Raw ) ;
core . form_widget_registry . add ( 'text_html' , FieldCKEditor4 ) ;
core . form_widget_registry . add ( 'text_html' , FieldCKEditor4 ) ;
core . form_widget_registry . add ( 'html' , FieldCKEditor4 ) ;
core . form_widget_registry . add ( 'html' , FieldCKEditor4 ) ;
return {
return {
'FieldCKEditor4' : FieldCKEditor4 ,
'FieldCKEditor4' : FieldCKEditor4 ,
'FieldCKEditor4Raw' : FieldCKEditor4Raw
'FieldCKEditor4Raw' : FieldCKEditor4Raw