From 8f9ba568155ee7dcd3507ec7aff5ab382e2e8db2 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Mon, 7 Apr 2025 14:43:00 +0500 Subject: [PATCH] add wp loader --- .../websiteFunctions/websiteFunctions.js | 89 +++++++++++-------- .../websiteFunctions/listWebsites.html | 1 + 2 files changed, 53 insertions(+), 37 deletions(-) diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index d7ce2e2a4..9b703d1b9 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -10354,44 +10354,59 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind console.error('Domain is undefined'); return; } - - var url = '/websites/fetchWPDetails'; - var data = { - domain: domain - }; - - console.log('Making request to:', url, 'with data:', data); - - $http({ - method: 'POST', - url: url, - data: $.param(data), - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'X-CSRFToken': getCookie('csrftoken') - } - }).then(function(response) { - console.log('Response received:', response); - if (response.data.status === 1 && response.data.fetchStatus === 1) { - // Find the website in the list and update its properties - $scope.WebSitesList.forEach(function(website) { - if (website.domain === domain) { - website.wp_sites = response.data.sites; - website.showWPSites = true; - console.log('Updated website:', website); - } - }); - $("#listFail").hide(); - } else { - $("#listFail").fadeIn(); - $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; - console.error('Error in response:', response.data.error_message); - } - }).catch(function(error) { - $("#listFail").fadeIn(); - $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; - console.error('Request failed:', error); + + // Find the website in the list and set loading state + var site = $scope.WebSitesList.find(function(website) { + return website.domain === domain; }); + + if (!site) { + console.error('Website not found:', domain); + return; + } + + // Toggle visibility and handle loading state + site.showWPSites = !site.showWPSites; + + // Only fetch if we're showing and don't have data yet + if (site.showWPSites && (!site.wp_sites || !site.wp_sites.length)) { + // Set loading state + site.loadingWPSites = true; + + var url = '/websites/fetchWPDetails'; + var data = { + domain: domain + }; + + console.log('Making request to:', url, 'with data:', data); + + $http({ + method: 'POST', + url: url, + data: $.param(data), + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'X-CSRFToken': getCookie('csrftoken') + } + }).then(function(response) { + console.log('Response received:', response); + if (response.data.status === 1 && response.data.fetchStatus === 1) { + site.wp_sites = response.data.sites; + $("#listFail").hide(); + } else { + $("#listFail").fadeIn(); + $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; + console.error('Error in response:', response.data.error_message); + } + }).catch(function(error) { + $("#listFail").fadeIn(); + $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; + console.error('Request failed:', error); + }).finally(function() { + // Clear loading state when done + site.loadingWPSites = false; + }); + } }; $scope.updateSetting = function(wp, setting) { diff --git a/websiteFunctions/templates/websiteFunctions/listWebsites.html b/websiteFunctions/templates/websiteFunctions/listWebsites.html index 108014444..af1f83c41 100755 --- a/websiteFunctions/templates/websiteFunctions/listWebsites.html +++ b/websiteFunctions/templates/websiteFunctions/listWebsites.html @@ -139,6 +139,7 @@ {$ web.wp_sites.length $} WordPress Sites +