From 23a718ab1d0c05ecfb6b4434a77cede13d68d21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 14 Aug 2023 09:56:36 +0200 Subject: [PATCH] Do not render deactivated actions in completion The disabled attribute is not enough to prevent the click event. So it is simpler to not render the action that are not supported like tryton does. Closes #12470 --- sao/src/common.js | 19 ++++++++++--------- sao/src/view/form.js | 34 +++++++++++++--------------------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/sao/src/common.js b/sao/src/common.js index 49f741eb62..0d7160c294 100644 --- a/sao/src/common.js +++ b/sao/src/common.js @@ -3745,10 +3745,17 @@ Sao.common.set_overflow(this.input, 'show'); }); }, - set_actions: function(actions, action_activated) { + set_actions: function(action_activated, search, create) { if (action_activated !== undefined) { this.action_activated = action_activated; } + var actions = []; + if (search || search == undefined) { + actions.push(['search', Sao.i18n.gettext('Search...')]); + } + if (create || create == undefined) { + actions.push(['create', Sao.i18n.gettext('Create...')]); + } this.menu.find('li.action').remove(); if (jQuery.isEmptyObject(actions)) { this.separator.hide(); @@ -3845,15 +3852,9 @@ var completion = new Sao.common.InputCompletion( el, source, match_selected, format); if (action_activated) { - var actions = []; - if (search || search == undefined) { - actions.push(['search', Sao.i18n.gettext('Search...')]); - } - if (create || create == undefined) { - actions.push(['create', Sao.i18n.gettext('Create...')]); - } - completion.set_actions(actions, action_activated); + completion.set_actions(action_activated, search, create); } + return completion; }; Sao.common.update_completion = function( diff --git a/sao/src/view/form.js b/sao/src/view/form.js index 25f0371c38..6cdad76199 100644 --- a/sao/src/view/form.js +++ b/sao/src/view/form.js @@ -2471,11 +2471,10 @@ function eval_pyson(value){ this.entry.on('keydown', this.key_press.bind(this)); if (!attributes.completion || attributes.completion == "1") { - Sao.common.get_completion(group, + this.wid_completion = Sao.common.get_completion( + group, this._update_completion.bind(this), - this._completion_match_selected.bind(this), - this._completion_action_activated.bind(this)); - this.wid_completion = true; + this._completion_match_selected.bind(this)); } this.el.change(this.focus_out.bind(this)); this._readonly = false; @@ -2837,17 +2836,10 @@ function eval_pyson(value){ } }, _set_completion: function() { - var search = this.el.find('.action-search'); - if (this.read_access) { - search.removeClass('disabled'); - } else { - search.addClass('disabled'); - } - var create = this.el.find('.action-create'); - if (this.create_access) { - create.removeClass('disabled'); - } else { - create.addClass('disabled'); + if (this.wid_completion) { + this.wid_completion.set_actions( + this._completion_action_activated.bind(this), + this.read_access, this.create_access); } }, _update_completion: function(text) { @@ -3143,12 +3135,12 @@ function eval_pyson(value){ }).appendTo(group); if (!attributes.completion || attributes.completion == '1') { - Sao.common.get_completion(this.wid_text, + this.wid_completion = Sao.common.get_completion( + this.wid_text, this._update_completion.bind(this), this._completion_match_selected.bind(this), this._completion_action_activated.bind(this), this.read_access, this.create_access); - this.wid_completion = true; } buttons = jQuery('
', { @@ -3759,12 +3751,12 @@ function eval_pyson(value){ this.entry.on('keydown', this.key_press.bind(this)); if (!attributes.completion || attributes.completion == '1') { - Sao.common.get_completion(group, + this.wid_completion = Sao.common.get_completion( + group, this._update_completion.bind(this), this._completion_match_selected.bind(this), this._completion_action_activated.bind(this), this.read_access, this.create_access); - this.wid_completion = true; } var buttons = jQuery('
', { @@ -4707,10 +4699,10 @@ function eval_pyson(value){ }).appendTo(group); if (!attributes.completion || attributes.completion == '1') { - Sao.common.get_completion(group, + this.wid_completion = Sao.common.get_completion( + group, this._update_completion.bind(this), this._completion_match_selected.bind(this)); - this.wid_completion = true; } this.but_add = jQuery('