3
0
Fork 0

[IMP] web_widget_ck_editor: pre-commit stuff

13.0
Justine Doutreloux 2023-10-25 11:24:08 +02:00
parent 97e1bdbb46
commit 16199d63a2
4 changed files with 32 additions and 20 deletions

View File

@ -0,0 +1 @@
../../../../web_widget_ckeditor

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@ -3,7 +3,7 @@
@author Iván Todorovich <ivan.todorovich@camptocamp.com> @author Iván Todorovich <ivan.todorovich@camptocamp.com>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
*/ */
odoo.define("web_widget_ckeditor.field_ckeditor", function (require) { odoo.define("web_widget_ckeditor.field_ckeditor", function(require) {
"use strict"; "use strict";
const core = require("web.core"); const core = require("web.core");
@ -49,7 +49,7 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
/** /**
* @override * @override
*/ */
willStart: function () { willStart: function() {
return Promise.all([ return Promise.all([
this._super.apply(this, arguments), this._super.apply(this, arguments),
loadCKEditorLanguagePromise, loadCKEditorLanguagePromise,
@ -59,7 +59,7 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
/** /**
* @override * @override
*/ */
destroy: function () { destroy: function() {
if (this.ckeditor) { if (this.ckeditor) {
this.ckeditor.destroy(); this.ckeditor.destroy();
this.ckeditor = undefined; this.ckeditor = undefined;
@ -74,7 +74,7 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
/** /**
* @override * @override
*/ */
activate: function () { activate: function() {
if (this.ckeditor) { if (this.ckeditor) {
this.ckeditor.focus(); this.ckeditor.focus();
return true; return true;
@ -85,11 +85,14 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
* *
* @override * @override
*/ */
isSet: function () { isSet: function() {
// Removing spaces & html spaces // Removing spaces & html spaces
const value = const value =
this.value && this.value &&
this.value.split("&nbsp;").join("").replace(/\s/g, ""); this.value
.split("&nbsp;")
.join("")
.replace(/\s/g, "");
return ( return (
value && value &&
value !== "<p></p>" && value !== "<p></p>" &&
@ -102,7 +105,7 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
* *
* @override * @override
*/ */
getFocusableElement: function () { getFocusableElement: function() {
return this.$target || $(); return this.$target || $();
}, },
/** /**
@ -111,7 +114,7 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
* *
* @override * @override
*/ */
reset: function (record, event) { reset: function(record, event) {
this._reset(record, event); this._reset(record, event);
const value = this._textToHtml(this.value); const value = this._textToHtml(this.value);
if (!event || event.target !== this) { if (!event || event.target !== this) {
@ -131,7 +134,7 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
/** /**
* @override * @override
*/ */
_getValue: function () { _getValue: function() {
if (this.mode === "edit" && this.ckeditor) { if (this.mode === "edit" && this.ckeditor) {
return this.ckeditor.getData(); return this.ckeditor.getData();
} }
@ -141,11 +144,11 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
* Gets the CKEditor toolbar items configuration. * Gets the CKEditor toolbar items configuration.
* If not found, returns the default configuration. * If not found, returns the default configuration.
*/ */
_getCKEditorToolbarItems: async function () { _getCKEditorToolbarItems: async function() {
try { try {
const ckconfig = await getCKEditorConfigPromise; const ckconfig = await getCKEditorConfigPromise;
if (ckconfig.toolbar) { if (ckconfig.toolbar) {
return ckconfig.toolbar.split(/[\s,]+/).filter((item) => item); return ckconfig.toolbar.split(/[\s,]+/).filter(item => item);
} }
} catch (error) { } catch (error) {
console.warn( console.warn(
@ -193,7 +196,7 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
* *
* @returns EditorConfig * @returns EditorConfig
*/ */
_getCKEditorConfig: async function () { _getCKEditorConfig: async function() {
const res = { const res = {
toolbar: { toolbar: {
items: await this._getCKEditorToolbarItems(), items: await this._getCKEditorToolbarItems(),
@ -231,7 +234,7 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
* @private * @private
* @returns {$.Promise} * @returns {$.Promise}
*/ */
_createCKEditorIntance: async function () { _createCKEditorIntance: async function() {
const editorConfig = await this._getCKEditorConfig(); const editorConfig = await this._getCKEditorConfig();
this.ckeditor = await window.ClassicEditor.create( this.ckeditor = await window.ClassicEditor.create(
this.$target.get(0), this.$target.get(0),
@ -248,16 +251,18 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
/** /**
* @override * @override
*/ */
_renderEdit: function () { _renderEdit: function() {
const value = this._textToHtml(this.value); const value = this._textToHtml(this.value);
this.$target = $("<textarea>").val(value).hide(); this.$target = $("<textarea>")
.val(value)
.hide();
this.$target.appendTo(this.$el); this.$target.appendTo(this.$el);
return this._createCKEditorIntance(); return this._createCKEditorIntance();
}, },
/** /**
* @override * @override
*/ */
_renderReadonly: function () { _renderReadonly: function() {
const value = this._textToHtml(this.value); const value = this._textToHtml(this.value);
this.$el.empty(); this.$el.empty();
this.$content = $('<div class="o_readonly"/>').html(value); this.$content = $('<div class="o_readonly"/>').html(value);
@ -270,7 +275,7 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
* @param {String} text * @param {String} text
* @returns {String} the text converted to html * @returns {String} the text converted to html
*/ */
_textToHtml: function (text) { _textToHtml: function(text) {
let value = text || ""; let value = text || "";
try { try {
// Crashes if text isn't html // Crashes if text isn't html
@ -302,7 +307,7 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
* *
* @private * @private
*/ */
_onLoadCKEditor: function () { _onLoadCKEditor: function() {
const $button = this._renderTranslateButton(); const $button = this._renderTranslateButton();
$button.css({ $button.css({
"font-size": "15px", "font-size": "15px",
@ -318,7 +323,7 @@ odoo.define("web_widget_ckeditor.field_ckeditor", function (require) {
* @private * @private
* @param {OdooEvent} ev * @param {OdooEvent} ev
*/ */
_onChange: function () { _onChange: function() {
this._doDebouncedAction.apply(this, arguments); this._doDebouncedAction.apply(this, arguments);
}, },
} }

View File

@ -3,7 +3,7 @@
@author Iván Todorovich <ivan.todorovich@camptocamp.com> @author Iván Todorovich <ivan.todorovich@camptocamp.com>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
*/ */
odoo.define("web_widget_ckeditor.field_html_override", function (require) { odoo.define("web_widget_ckeditor.field_html_override", function(require) {
"use strict"; "use strict";
const FieldHtml = require("web_editor.field.html"); const FieldHtml = require("web_editor.field.html");