]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Refactor retry loop into FooTable event
authorAlexander Moisseev <moiseev@mezonplus.ru>
Fri, 12 Dec 2025 15:29:46 +0000 (18:29 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Fri, 12 Dec 2025 15:29:46 +0000 (18:29 +0300)
Use postinit.ft.table event instead of polling

interface/js/app/libft.js

index bf4286c0ad898c8a4e4c33a3c3413eff4cf5a14f..0d5ddb3c5c4f7f7c27f6e71ebeda4660b9b467f2 100644 (file)
@@ -7,7 +7,6 @@ define(["jquery", "app/common", "footable"],
         const columnsCustom = JSON.parse(localStorage.getItem("columns")) || {};
 
         let pageSizeTimerId = null;
-        let pageSizeInvocationCounter = 0;
 
         function get_compare_function(table) {
             const compare_functions = {
@@ -194,15 +193,17 @@ define(["jquery", "app/common", "footable"],
 
                 if (changeTablePageSize &&
                     $("#historyTable_" + table + " tbody").is(":parent")) { // Table is not empty
-                    clearTimeout(pageSizeTimerId);
-                    const t = FooTable.get("#historyTable_" + table);
-                    if (t) {
-                        pageSizeInvocationCounter = 0;
-                        // Wait for input finish
-                        pageSizeTimerId = setTimeout(() => t.pageSize(n), 1000);
-                    } else if (++pageSizeInvocationCounter < 10) {
-                        // Wait for FooTable instance ready
-                        pageSizeTimerId = setTimeout(() => ui.set_page_size(table, n, true), 1000);
+                    if (common.tables[table]) {
+                        // Table exists - debounce rapid changes (e.g., spin button clicks)
+                        clearTimeout(pageSizeTimerId);
+                        pageSizeTimerId = setTimeout(() => {
+                            common.tables[table]?.pageSize(n);
+                        }, 1000);
+                    } else {
+                        // Table doesn't exist - wait for initialization with event
+                        $("#historyTable_" + table).one("postinit.ft.table", () => {
+                            common.tables[table]?.pageSize(n);
+                        });
                     }
                 }
             }