diff --git a/ChangeLog b/ChangeLog index b5e489b02..cb659ba13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2010-08-06 Wolfgang Sourdeau + * UI/WebServerResources/MailerUI.js: (initMailboxTree): make use + of the new class below and drop all code related to keeping track + of active requests. + * UI/WebServerResources/generic.js: (AjaxRequestsChain): new class that implements the chaining of ajax requests. diff --git a/UI/WebServerResources/MailerUI.js b/UI/WebServerResources/MailerUI.js index bbe979e79..e92ead5ac 100644 --- a/UI/WebServerResources/MailerUI.js +++ b/UI/WebServerResources/MailerUI.js @@ -1787,11 +1787,34 @@ function initMailboxTree() { mailboxTree.add(0, -1, ''); - mailboxTree.pendingRequests = mailAccounts.length; - activeAjaxRequests += mailAccounts.length; + var chainRq = new AjaxRequestsChain(initMailboxTreeCB); for (var i = 0; i < mailAccounts.length; i++) { var url = ApplicationBaseURL + i + "/mailboxes"; - triggerAjaxRequest(url, onLoadMailboxesCallback, i); + chainRq.requests.push([url, onLoadMailboxesCallback, i]); + } + chainRq.start(); +} + +function initMailboxTreeCB() { + updateMailboxTreeInPage(); + updateMailboxMenus(); + getStatusFolders(); + checkAjaxRequestsState(); + getFoldersState(); + configureDroppables(); +} + +function onLoadMailboxesCallback(http) { + if (http.status == 200) { + checkAjaxRequestsState(); + if (http.responseText.length > 0) { + var accountIdx = http.callbackData; + var newAccount = buildMailboxes(accountIdx, http.responseText); + accounts[accountIdx] = newAccount; + mailboxTree.addMailAccount(newAccount); + } + else + log ("onLoadMailboxesCallback " + http.status); } } @@ -1945,30 +1968,6 @@ function updateMailboxMenus() { } } -function onLoadMailboxesCallback(http) { - if (http.status == 200) { - checkAjaxRequestsState(); - if (http.responseText.length > 0) { - var accountIdx = parseInt(http.callbackData); - var newAccount = buildMailboxes(accountIdx, http.responseText); - accounts[accountIdx] = newAccount; - mailboxTree.addMailAccount(newAccount); - mailboxTree.pendingRequests--; - activeAjaxRequests--; - if (!mailboxTree.pendingRequests) { - updateMailboxTreeInPage(); - updateMailboxMenus(); - getStatusFolders(); - checkAjaxRequestsState(); - getFoldersState(); - configureDroppables(); - } - } - else - log ("onLoadMailboxesCallback " + http.status); - } -} - function buildMailboxes(accountIdx, encoded) { var account = new Mailbox("account", "" + accountIdx, undefined, //necessary, null will cause issues