From 8645f85905a86c2a0ea4c01f6469d5e833c7758f Mon Sep 17 00:00:00 2001 From: ahiexp Date: Thu, 29 May 2025 10:55:53 +0400 Subject: [PATCH] [SOLVED] remove duplicate on rendering --- .../static/src/js/hide_export.js | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/odex25_base/simplify_access_management/static/src/js/hide_export.js b/odex25_base/simplify_access_management/static/src/js/hide_export.js index 1854c56bc..5408ee753 100644 --- a/odex25_base/simplify_access_management/static/src/js/hide_export.js +++ b/odex25_base/simplify_access_management/static/src/js/hide_export.js @@ -10,31 +10,49 @@ odoo.define('simplify_access_management.hide_export', function (require) { _render: function () { const res = this._super.apply(this, arguments); const self = this; - this._super.apply(this, arguments); - + // this._super.apply(this, arguments); + var hash = window.location.hash.replace("#", '').split("&"); let cids; - if(hash.findIndex(ele => ele.includes("cid")) == -1) + if (hash.findIndex(ele => ele.includes("cid")) == -1) cids = session.company_id; else { cids = hash.filter(ele => ele.includes("cid"))[0].split("=")[1].split(","); - cids = cids.length > 0? parseInt(cids[0]): session.company_id; + cids = cids.length > 0 ? parseInt(cids[0]) : session.company_id; } - let model = hash.filter(ele=>ele.includes("model"))?.[0]; - model = model? model.split("=")?.[1].split(",")?.[0]: model; - if(cids && model) { + let model = hash.filter(ele => ele.includes("model"))?.[0]; + model = model ? model.split("=")?.[1].split(",")?.[0] : model; + if (cids && model) { rpc.query({ - model:'access.management', + model: 'access.management', method: 'is_export_hide', args: [cids, model] - }).then(function(result){ - if(result) { - var btn1 = setInterval(function() { - if ($('.o_list_export_xlsx').length) { - $('.o_list_export_xlsx').remove(); - clearInterval(btn1); - } - }, 50); + }).then(function (result) { + if (result) { + // dump code + // var btn1 = setInterval(function () { + // if ($('.o_list_export_xlsx').length) { + // $('.o_list_export_xlsx').remove(); + // clearInterval(btn1); + // } + // }, 50); + + // replace setInterval by MutationObserver + // It reacts only when changes actually happen in the DOM + // Cleaner logic and easier to control when disconnecting + const observer = new MutationObserver(function (mutations, obs) { + const exportBtn = document.querySelector('.o_list_export_xlsx'); + if (exportBtn) { + exportBtn.remove(); + obs.disconnect(); // Stop observing once the button is removed + } + }); + + // Start observing the body (or a more specific container) + observer.observe(document.body, { + childList: true, + subtree: true + }); } }); }