mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[IMP] web_ckeditor4: pre-commit execution
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
.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 {
|
||||
.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
|
||||
*/
|
||||
|
||||
@@ -1 +1 @@
|
||||
CKEDITOR_BASEPATH='/web_ckeditor4/static/lib/ckeditor/'
|
||||
CKEDITOR_BASEPATH = "/web_ckeditor4/static/lib/ckeditor/";
|
||||
|
||||
@@ -20,43 +20,42 @@
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
odoo.define('web_ckeditor4', function(require){
|
||||
odoo.define("web_ckeditor4", function (require) {
|
||||
"use strict";
|
||||
var core = require('web.core');
|
||||
var session = require('web.session');
|
||||
var formats = require('web.formats');
|
||||
var ckconfig = require('web_ckeditor4.config');
|
||||
var core = require("web.core");
|
||||
var session = require("web.session");
|
||||
var formats = require("web.formats");
|
||||
var ckconfig = require("web_ckeditor4.config");
|
||||
|
||||
var FieldCKEditor4 = core.form_widget_registry.get('text').extend({
|
||||
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: ''
|
||||
filebrowserImageUploadUrl: "dummy",
|
||||
extraPlugins: "filebrowser",
|
||||
// This is '#39' per default which screws up single quoted text in ${}
|
||||
entities_additional: "",
|
||||
};
|
||||
},
|
||||
ckeditor_filter: ckconfig.default_ckeditor_filter,
|
||||
ckeditor_writer: ckconfig.default_ckeditor_writer,
|
||||
_getRemovePlugins: function () {
|
||||
return 'iframe,flash,forms,smiley,pagebreak,stylescombo';
|
||||
return "iframe,flash,forms,smiley,pagebreak,stylescombo";
|
||||
},
|
||||
_getRemoveButtons: function () {
|
||||
return '';
|
||||
return "";
|
||||
},
|
||||
init: function () {
|
||||
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);
|
||||
CKEDITOR.lang.load(this.editor_lang, 'en', function() {});
|
||||
CKEDITOR.lang.load(this.editor_lang, "en", function () {});
|
||||
},
|
||||
_on_load_record: function() {
|
||||
_on_load_record: function () {
|
||||
/* Fix widget not re-initialized on form discard.
|
||||
|
||||
When you hit "cancel" button or when you navigate away
|
||||
@@ -75,22 +74,19 @@ odoo.define('web_ckeditor4', function(require){
|
||||
this.initialize_content();
|
||||
}
|
||||
},
|
||||
initialize_content: function()
|
||||
{
|
||||
initialize_content: function () {
|
||||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
if(!this.$el)
|
||||
{
|
||||
if (!this.$el) {
|
||||
return;
|
||||
} else if (!this.get('effective_readonly') && !this.editor) {
|
||||
this.editor = CKEDITOR.replace(this.$el.get(0),
|
||||
} else if (!this.get("effective_readonly") && !this.editor) {
|
||||
this.editor = CKEDITOR.replace(
|
||||
this.$el.get(0),
|
||||
_.extend(
|
||||
{
|
||||
language: this.editor_lang,
|
||||
on:
|
||||
{
|
||||
'change': function()
|
||||
{
|
||||
on: {
|
||||
change: function () {
|
||||
self.store_dom_value();
|
||||
},
|
||||
},
|
||||
@@ -100,82 +96,72 @@ odoo.define('web_ckeditor4', function(require){
|
||||
);
|
||||
}
|
||||
},
|
||||
store_dom_value: function()
|
||||
{
|
||||
this.internal_set_value(this.editor ? this.editor.getData() : formats.parse_value(this.get('value'), this));
|
||||
store_dom_value: function () {
|
||||
this.internal_set_value(
|
||||
this.editor
|
||||
? this.editor.getData()
|
||||
: formats.parse_value(this.get("value"), this)
|
||||
);
|
||||
},
|
||||
filter_html: function(value)
|
||||
{
|
||||
return ckconfig.filter_html(value, this.ckeditor_filter, this.ckeditor_writer);
|
||||
filter_html: function (value) {
|
||||
return ckconfig.filter_html(
|
||||
value,
|
||||
this.ckeditor_filter,
|
||||
this.ckeditor_writer
|
||||
);
|
||||
},
|
||||
render_value: function()
|
||||
{
|
||||
if(this.get("effective_readonly"))
|
||||
{
|
||||
this.$el.html(this.filter_html(this.get('value')));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this.editor)
|
||||
{
|
||||
render_value: function () {
|
||||
if (this.get("effective_readonly")) {
|
||||
this.$el.html(this.filter_html(this.get("value")));
|
||||
} else if (this.editor) {
|
||||
var self = this;
|
||||
if(this.editor.status != 'ready')
|
||||
{
|
||||
var instanceReady = function()
|
||||
{
|
||||
self.editor.setData(self.get('value') || '');
|
||||
self.editor.removeListener('instanceReady', instanceReady);
|
||||
if (this.editor.status != "ready") {
|
||||
var instanceReady = function () {
|
||||
self.editor.setData(self.get("value") || "");
|
||||
self.editor.removeListener("instanceReady", instanceReady);
|
||||
};
|
||||
this.editor.on('instanceReady', instanceReady);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.editor.setData(self.get('value') || '');
|
||||
this.editor.on("instanceReady", instanceReady);
|
||||
} else {
|
||||
self.editor.setData(self.get("value") || "");
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
destroy_content: function () {
|
||||
this._cleanup_editor();
|
||||
},
|
||||
undelegateEvents: function()
|
||||
{
|
||||
undelegateEvents: function () {
|
||||
this._cleanup_editor();
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
_cleanup_editor: function()
|
||||
{
|
||||
if(this.editor && this.editor.status == 'ready')
|
||||
{
|
||||
_cleanup_editor: function () {
|
||||
if (this.editor && this.editor.status == "ready") {
|
||||
CKEDITOR.remove(this.editor.name);
|
||||
$('#cke_' + this.editor.name).remove();
|
||||
$("#cke_" + this.editor.name).remove();
|
||||
this.editor.removeAllListeners();
|
||||
this.editor.destroy();
|
||||
this.editor = null;
|
||||
}
|
||||
},
|
||||
destroy: function()
|
||||
{
|
||||
destroy: function () {
|
||||
this.view.off("load_record", this, this._on_load_record);
|
||||
this._cleanup_editor();
|
||||
this._super();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
var FieldCKEditor4Raw = FieldCKEditor4.extend({
|
||||
filter_html: function(value)
|
||||
{
|
||||
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);
|
||||
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
|
||||
}
|
||||
FieldCKEditor4: FieldCKEditor4,
|
||||
FieldCKEditor4Raw: FieldCKEditor4Raw,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
odoo.define('web_ckeditor4.config', function (require) {
|
||||
odoo.define("web_ckeditor4.config", function (require) {
|
||||
"use strict";
|
||||
|
||||
var ckeditor_addFunction_org = CKEDITOR.tools.addFunction;
|
||||
// this is a quite complicated way to kind of monkey patch the private
|
||||
// This is a quite complicated way to kind of monkey patch the private
|
||||
// method onDomReady of ckeditor's plugin wysiwigarea, which causes problems
|
||||
// when the editor is about to be destroyed but because of OpenERP's
|
||||
// architecture updated one last time with its current value
|
||||
@@ -43,33 +43,39 @@ odoo.define('web_ckeditor4.config', function (require) {
|
||||
return ckeditor_addFunction_org(fn, scope);
|
||||
};
|
||||
|
||||
CKEDITOR.on('dialogDefinition', function (e) {
|
||||
CKEDITOR.on("dialogDefinition", function (e) {
|
||||
_.each(e.data.definition.contents, function (element) {
|
||||
if (!element || element.filebrowser != 'uploadButton') {
|
||||
return
|
||||
if (!element || element.filebrowser != "uploadButton") {
|
||||
return;
|
||||
}
|
||||
_.each(element.elements, function (element) {
|
||||
if (!element.onClick || element.type != 'fileButton') {
|
||||
return
|
||||
if (!element.onClick || element.type != "fileButton") {
|
||||
return;
|
||||
}
|
||||
var onClick_org = element.onClick;
|
||||
element.onClick = function (e1) {
|
||||
onClick_org.apply(this, arguments);
|
||||
_.each($('#' + this.domId).closest('table')
|
||||
.find('iframe').contents().find(':file')
|
||||
.get(0).files,
|
||||
_.each(
|
||||
$("#" + 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;
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -82,18 +88,17 @@ odoo.define('web_ckeditor4.config', function (require) {
|
||||
};
|
||||
|
||||
var default_ckeditor_filter = new CKEDITOR.filter({
|
||||
'*':
|
||||
{
|
||||
attributes: 'href,src,style,alt,width,height,dir',
|
||||
styles: '*',
|
||||
classes: '*',
|
||||
"*": {
|
||||
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,
|
||||
"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();
|
||||
return {
|
||||
'filter_html': filter_html,
|
||||
'default_ckeditor_filter': default_ckeditor_filter,
|
||||
'default_ckeditor_writer': default_ckeditor_writer
|
||||
}
|
||||
filter_html: filter_html,
|
||||
default_ckeditor_filter: default_ckeditor_filter,
|
||||
default_ckeditor_writer: default_ckeditor_writer,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
odoo.define('web_ckeditor4.FormView', function(require) {
|
||||
"use strict";
|
||||
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;
|
||||
}
|
||||
|
||||
});
|
||||
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