add wp loader

This commit is contained in:
usmannasir 2025-04-07 14:43:00 +05:00
parent e0dc261b77
commit 8f9ba56815
2 changed files with 53 additions and 37 deletions

View File

@ -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) {

View File

@ -139,6 +139,7 @@
<span ng-if="web.wp_sites && web.wp_sites.length > 0" style="text-transform: none">
{$ web.wp_sites.length $} WordPress Sites
</span>
<i ng-if="web.loadingWPSites" class="fa fa-spinner fa-spin" style="margin-left: 5px;"></i>
</a>
</div>
</div>