From 53789e7beb7ea8bcc162ec9f5ab0b1e7306a9266 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Tue, 8 Apr 2025 23:38:54 +0500 Subject: [PATCH] add loader --- .../websiteFunctions/websiteFunctions.js | 276 ++++++++++++------ .../websiteFunctions/listWebsites.html | 13 +- 2 files changed, 190 insertions(+), 99 deletions(-) diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index b4a4e8bad..c8ab7ae89 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -2631,7 +2631,6 @@ app.controller('listWebsites', function ($scope, $http, $window) { $scope.getFurtherWebsitesFromDB(); $scope.showWPSites = function(domain) { - $scope.loading = true; console.log('showWPSites called for domain:', domain); // Make sure domain is defined @@ -2640,6 +2639,32 @@ app.controller('listWebsites', function ($scope, $http, $window) { return; } + // Find the website in the list + var website = $scope.WebSitesList.find(function(site) { + return site.domain === domain; + }); + + if (!website) { + console.error('Website not found'); + return; + } + + // Toggle WordPress sites visibility + website.showWPSites = !website.showWPSites; + + // If we're hiding the section, return early + if (!website.showWPSites) { + return; + } + + // If we already have the data, no need to fetch again + if (website.wp_sites && website.wp_sites.length > 0) { + return; + } + + // Set loading state + website.loadingWP = true; + var url = '/websites/fetchWPDetails'; var data = { domain: domain @@ -2656,28 +2681,25 @@ app.controller('listWebsites', function ($scope, $http, $window) { 'X-CSRFToken': getCookie('csrftoken') } }).then(function(response) { - $scope.loading = false; 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(); + website.wp_sites = response.data.data; } else { - $("#listFail").fadeIn(); - $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; - console.error('Error in response:', response.data.error_message); + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message || 'Failed to fetch WordPress sites', + type: 'error' + }); } }).catch(function(error) { - $scope.loading = true; - $("#listFail").fadeIn(); - $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; - console.error('Request failed:', error); + console.error('Error:', error); + new PNotify({ + title: 'Operation Failed!', + text: 'Could not fetch WordPress sites. Please try again.', + type: 'error' + }); + }).finally(function() { + website.loadingWP = false; }); }; @@ -5747,6 +5769,32 @@ app.controller('listWebsites', function ($scope, $http, $window) { return; } + // Find the website in the list + var website = $scope.WebSitesList.find(function(site) { + return site.domain === domain; + }); + + if (!website) { + console.error('Website not found'); + return; + } + + // Toggle WordPress sites visibility + website.showWPSites = !website.showWPSites; + + // If we're hiding the section, return early + if (!website.showWPSites) { + return; + } + + // If we already have the data, no need to fetch again + if (website.wp_sites && website.wp_sites.length > 0) { + return; + } + + // Set loading state + website.loadingWP = true; + var url = '/websites/fetchWPDetails'; var data = { domain: domain @@ -5765,24 +5813,23 @@ app.controller('listWebsites', function ($scope, $http, $window) { }).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(); + website.wp_sites = response.data.data; } else { - $("#listFail").fadeIn(); - $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; - console.error('Error in response:', response.data.error_message); + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message || 'Failed to fetch WordPress sites', + type: 'error' + }); } }).catch(function(error) { - $("#listFail").fadeIn(); - $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; - console.error('Request failed:', error); + console.error('Error:', error); + new PNotify({ + title: 'Operation Failed!', + text: 'Could not fetch WordPress sites. Please try again.', + type: 'error' + }); + }).finally(function() { + website.loadingWP = false; }); }; @@ -9426,6 +9473,32 @@ app.controller('listWebsites', function ($scope, $http, $window) { return; } + // Find the website in the list + var website = $scope.WebSitesList.find(function(site) { + return site.domain === domain; + }); + + if (!website) { + console.error('Website not found'); + return; + } + + // Toggle WordPress sites visibility + website.showWPSites = !website.showWPSites; + + // If we're hiding the section, return early + if (!website.showWPSites) { + return; + } + + // If we already have the data, no need to fetch again + if (website.wp_sites && website.wp_sites.length > 0) { + return; + } + + // Set loading state + website.loadingWP = true; + var url = '/websites/fetchWPDetails'; var data = { domain: domain @@ -9444,24 +9517,23 @@ app.controller('listWebsites', function ($scope, $http, $window) { }).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(); + website.wp_sites = response.data.data; } else { - $("#listFail").fadeIn(); - $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; - console.error('Error in response:', response.data.error_message); + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message || 'Failed to fetch WordPress sites', + type: 'error' + }); } }).catch(function(error) { - $("#listFail").fadeIn(); - $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; - console.error('Request failed:', error); + console.error('Error:', error); + new PNotify({ + title: 'Operation Failed!', + text: 'Could not fetch WordPress sites. Please try again.', + type: 'error' + }); + }).finally(function() { + website.loadingWP = false; }); }; @@ -13469,59 +13541,69 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind console.error('Domain is undefined'); return; } - - // Find the website in the list and set loading state - var site = $scope.WebSitesList.find(function(website) { - return website.domain === domain; + + // Find the website in the list + var website = $scope.WebSitesList.find(function(site) { + return site.domain === domain; }); - - if (!site) { - console.error('Website not found:', domain); + + if (!website) { + console.error('Website not found'); 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; - }); + + // Toggle WordPress sites visibility + website.showWPSites = !website.showWPSites; + + // If we're hiding the section, return early + if (!website.showWPSites) { + return; } + + // If we already have the data, no need to fetch again + if (website.wp_sites && website.wp_sites.length > 0) { + return; + } + + // Set loading state + website.loadingWP = 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) { + website.wp_sites = response.data.data; + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message || 'Failed to fetch WordPress sites', + type: 'error' + }); + } + }).catch(function(error) { + console.error('Error:', error); + new PNotify({ + title: 'Operation Failed!', + text: 'Could not fetch WordPress sites. Please try again.', + type: 'error' + }); + }).finally(function() { + website.loadingWP = false; + }); }; $scope.updateSetting = function(wp, setting) { diff --git a/websiteFunctions/templates/websiteFunctions/listWebsites.html b/websiteFunctions/templates/websiteFunctions/listWebsites.html index a7b2ecd2b..027d5afbb 100755 --- a/websiteFunctions/templates/websiteFunctions/listWebsites.html +++ b/websiteFunctions/templates/websiteFunctions/listWebsites.html @@ -149,13 +149,22 @@ {$ web.wp_sites.length $} WordPress Sites - + +
+
+
+ Loading WordPress sites... +
+

{% trans "Loading WordPress sites..." %}

+
+
+ -
+