[IMP] mail: add a node option for custom onchange debounce delay

This commit introduces a node option 'keydown_debounce_delay' on the
character field and on emoji mixin, so that use can define the custom
debounce delay (in milliseconds) instead of fixed 2000 ms for
triggering an onchange on the field. Note that this delay will be
applied only when 'onchange_on_keydown' node option is also provided.

Also, we've utilized the odoo's debounce instead of the one provided by
underscore js, for 2 reasons:

1 - odoo's debounce is already well tested (see the file
    /web/static/tests/core/utils/timing_tests.js)
2 - to take a step forward for reducing external lib dependency

task-2821978

closes odoo/odoo#94486

X-original-commit: ab80cdc0809e1347d201f21ac9474e66e9270f94
Related: odoo/enterprise#28822
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Nikunj Ladava
2022-06-24 10:30:00 +02:00
committed by Thibault Delavallée
parent dd87eb77f3
commit 261fd732f8
2 changed files with 14 additions and 5 deletions
+8 -3
View File
@@ -1,5 +1,6 @@
/** @odoo-module **/
import { debounce } from "@web/core/utils/timing";
import { FieldChar } from 'web.basic_fields';
FieldChar.include({
@@ -10,12 +11,16 @@ FieldChar.include({
/**
* Support a key-based onchange in text field.
* The _triggerOnchange method is debounced to run 2 seconds after typing ends.
* The _triggerOnchange method is debounced to run after given debouce delay
* (or 2 seconds by default) on typing ends.
*
*/
init: function () {
this._super.apply(this, arguments);
this._triggerOnchange = _.debounce(this._triggerOnchange, 2000);
if (this.nodeOptions.keydown_debounce_delay === undefined) {
this.nodeOptions.keydown_debounce_delay = 2000;
}
this._triggerOnchange = debounce(this._triggerOnchange, this.nodeOptions.keydown_debounce_delay);
},
@@ -44,7 +49,7 @@ FieldChar.include({
/**
* Triggers the 'change' event to refresh the value.
* This method is debounced to run 2 seconds after typing ends.
* This method is debounced to run after given debouce delay on typing ends.
* (to avoid spamming the server while the user is typing their message)
*
* @private
@@ -1,5 +1,6 @@
/** @odoo-module **/
import { debounce } from "@web/core/utils/timing";
import emojis from '@mail/js/emojis';
import MailEmojisMixin from '@mail/js/emojis_mixin';
import core from 'web.core';
@@ -17,7 +18,10 @@ var FieldEmojiCommon = {
*/
init: function () {
this._super.apply(this, arguments);
this._triggerOnchange = _.debounce(this._triggerOnchange, 2000);
if (this.nodeOptions.keydown_debounce_delay === undefined) {
this.nodeOptions.keydown_debounce_delay = 2000;
}
this._triggerOnchange = debounce(this._triggerOnchange, this.nodeOptions.keydown_debounce_delay);
this.emojis = emojis;
},
@@ -89,7 +93,7 @@ var FieldEmojiCommon = {
/**
* Triggers the 'change' event to refresh the value.
* This method is debounced to run 2 seconds after typing ends.
* This method is debounced to run after given debouce delay on typing ends.
* (to avoid spamming the server while the user is typing their message)
*
* @private