From b0f81552962ba6ed742ff6c46e59b1051d1a6cb9 Mon Sep 17 00:00:00 2001 From: Ramon Van Gorkom Date: Mon, 6 Jan 2025 21:20:10 +0100 Subject: [PATCH] luci-base: Generate cbi-dynlist-change event after drag/touch end Signed-off-by: Ramon Van Gorkom --- .../htdocs/luci-static/resources/ui.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/ui.js b/modules/luci-base/htdocs/luci-static/resources/ui.js index e9efe9b1934e..f077b41253f1 100644 --- a/modules/luci-base/htdocs/luci-static/resources/ui.js +++ b/modules/luci-base/htdocs/luci-static/resources/ui.js @@ -2320,6 +2320,7 @@ const UIDynamicList = UIElement.extend(/** @lends LuCI.ui.DynamicList.prototype e.target.classList.remove('drag-over'); const target = e.target.classList.contains('item') ? e.target : dl.querySelector('.add-item'); dl.insertBefore(draggedItem, target); + this.dispatchCbiDynlistChange(dl, draggedItem.value); }); dl.addEventListener('click', (e) => { @@ -2376,6 +2377,7 @@ const UIDynamicList = UIElement.extend(/** @lends LuCI.ui.DynamicList.prototype dl.insertBefore(draggedItem, placeholder); draggedItem.classList.remove('dragging') placeholder.parentNode.removeChild(placeholder); + this.dispatchCbiDynlistChange(dl, draggedItem.value); placeholder = null; draggedItem = null; } @@ -2427,6 +2429,11 @@ const UIDynamicList = UIElement.extend(/** @lends LuCI.ui.DynamicList.prototype ai.parentNode.insertBefore(new_item, ai); } + this.dispatchCbiDynlistChange(dl,value); + }, + + /** @private */ + dispatchCbiDynlistChange(dl,value) { dl.dispatchEvent(new CustomEvent('cbi-dynlist-change', { bubbles: true, detail: { @@ -2454,15 +2461,7 @@ const UIDynamicList = UIElement.extend(/** @lends LuCI.ui.DynamicList.prototype item.parentNode.removeChild(item); - dl.dispatchEvent(new CustomEvent('cbi-dynlist-change', { - bubbles: true, - detail: { - instance: this, - element: dl, - value: value, - remove: true - } - })); + this.dispatchCbiDynlistChange(dl, value); }, /** @private */