From fb1076416768557ad2b55aa409eac837fe7d329d Mon Sep 17 00:00:00 2001 From: Marco Jarjour Date: Wed, 27 Apr 2022 15:57:53 +0200 Subject: [PATCH 1/2] Execute API calls only when needed --- data/web/js/site/mailbox.js | 100 +++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/data/web/js/site/mailbox.js b/data/web/js/site/mailbox.js index 745c4f218..535ebaaec 100644 --- a/data/web/js/site/mailbox.js +++ b/data/web/js/site/mailbox.js @@ -99,37 +99,6 @@ $(document).ready(function() { }); auto_fill_quota($('#addSelectDomain').val()); - // Read bcc local dests - // Using ajax to not be a blocking moo - $.get("/api/v1/get/bcc-destination-options", function(data){ - // Domains - var optgroup = ""; - $.each(data.domains, function(index, domain){ - optgroup += "" - }); - optgroup += "" - $('#bcc-local-dest').append(optgroup); - // Alias domains - var optgroup = ""; - $.each(data.alias_domains, function(index, alias_domain){ - optgroup += "" - }); - optgroup += "" - $('#bcc-local-dest').append(optgroup); - // Mailboxes and aliases - $.each(data.mailboxes, function(mailbox, aliases){ - var optgroup = ""; - $.each(aliases, function(index, alias){ - optgroup += "" - }); - optgroup += "" - $('#bcc-local-dest').append(optgroup); - }); - // Finish - $('#bcc-local-dest').find('option:selected').remove(); - $('#bcc-local-dest').selectpicker('refresh'); - }); - $(".goto_checkbox").click(function( event ) { $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false); if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) { @@ -610,6 +579,37 @@ jQuery(function($){ }); } function draw_bcc_table() { + // Read bcc local dests + // Using ajax to not be a blocking moo + $.get("/api/v1/get/bcc-destination-options", function(data){ + // Domains + var optgroup = ""; + $.each(data.domains, function(index, domain){ + optgroup += "" + }); + optgroup += "" + $('#bcc-local-dest').append(optgroup); + // Alias domains + var optgroup = ""; + $.each(data.alias_domains, function(index, alias_domain){ + optgroup += "" + }); + optgroup += "" + $('#bcc-local-dest').append(optgroup); + // Mailboxes and aliases + $.each(data.mailboxes, function(mailbox, aliases){ + var optgroup = ""; + $.each(aliases, function(index, alias){ + optgroup += "" + }); + optgroup += "" + $('#bcc-local-dest').append(optgroup); + }); + // Finish + $('#bcc-local-dest').find('option:selected').remove(); + $('#bcc-local-dest').selectpicker('refresh'); + }); + ft_bcc_table = FooTable.init('#bcc_table', { "columns": [ {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"}, @@ -1147,15 +1147,33 @@ jQuery(function($){ event.stopPropagation(); }) - draw_domain_table(); - draw_mailbox_table(); - draw_resource_table(); - draw_alias_table(); - draw_aliasdomain_table(); - draw_sync_job_table(); - draw_filter_table(); - draw_bcc_table(); - draw_recipient_map_table(); - draw_tls_policy_table(); + // detect element visibility changes + function onVisible(element, callback) { + $(element).ready(function() { + element_object = document.querySelector(element) + new IntersectionObserver((entries, observer) => { + entries.forEach(entry => { + if(entry.intersectionRatio > 0) { + callback(element_object); + observer.disconnect(); + } + }); + }).observe(element_object); + }); + } + + // Load only if the tab is visible + onVisible("#tab-domains", () => draw_domain_table()); + onVisible("#tab-mailboxes", () => draw_mailbox_table()); + onVisible("#tab-resources", () => draw_resource_table()); + onVisible("#tab-mbox-aliases", () => draw_alias_table()); + onVisible("#tab-domain-aliases", () => draw_aliasdomain_table()); + onVisible("#tab-syncjobs", () => draw_sync_job_table()); + onVisible("#tab-filters", () => draw_filter_table()); + onVisible("#tab-bcc", () => { + draw_bcc_table(); + draw_recipient_map_table(); + }); + onVisible("#tab-tls-policy", () => draw_tls_policy_table()); }); From 003a6342a51a3af39ae283c70af346ff68f15f5f Mon Sep 17 00:00:00 2001 From: Marco Jarjour Date: Wed, 27 Apr 2022 17:43:40 +0200 Subject: [PATCH 2/2] Match also mobile id's --- data/web/js/site/mailbox.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/data/web/js/site/mailbox.js b/data/web/js/site/mailbox.js index 535ebaaec..e438c29ac 100644 --- a/data/web/js/site/mailbox.js +++ b/data/web/js/site/mailbox.js @@ -1163,17 +1163,17 @@ jQuery(function($){ } // Load only if the tab is visible - onVisible("#tab-domains", () => draw_domain_table()); - onVisible("#tab-mailboxes", () => draw_mailbox_table()); - onVisible("#tab-resources", () => draw_resource_table()); - onVisible("#tab-mbox-aliases", () => draw_alias_table()); - onVisible("#tab-domain-aliases", () => draw_aliasdomain_table()); - onVisible("#tab-syncjobs", () => draw_sync_job_table()); - onVisible("#tab-filters", () => draw_filter_table()); - onVisible("#tab-bcc", () => { + onVisible("[id^=tab-domains]", () => draw_domain_table()); + onVisible("[id^=tab-mailboxes]", () => draw_mailbox_table()); + onVisible("[id^=tab-resources]", () => draw_resource_table()); + onVisible("[id^=tab-mbox-aliases]", () => draw_alias_table()); + onVisible("[id^=tab-domain-aliases]", () => draw_aliasdomain_table()); + onVisible("[id^=tab-syncjobs]", () => draw_sync_job_table()); + onVisible("[id^=tab-filters]", () => draw_filter_table()); + onVisible("[id^=tab-bcc]", () => { draw_bcc_table(); draw_recipient_map_table(); }); - onVisible("#tab-tls-policy", () => draw_tls_policy_table()); + onVisible("[id^=tab-tls-policy]", () => draw_tls_policy_table()); });