diff --git a/dashboard/src/js/client.js b/dashboard/src/js/client.js index 47f74098c..6ea8bb883 100644 --- a/dashboard/src/js/client.js +++ b/dashboard/src/js/client.js @@ -828,6 +828,7 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout Client.prototype.hasCloudronBackground = function (callback) { get('/api/v1/branding/cloudron_background', null, function (error, data, status) { + console.log('hasCloudronBackground...') if (error && error.statusCode !== 404) callback(error); else if (error) callback(null, false); else callback(null, status === 200); @@ -2402,6 +2403,10 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout } }; + Client.prototype.getBackgroundImageUrl = function () { + return client.apiOrigin + '/api/v1/profile/background_image?access_token=' + token + '&bustcache=' + Date.now(); + }; + Client.prototype.setBackgroundImage = function (backgroundImage, callback) { // Blob type if object var fd = new FormData(); @@ -2598,30 +2603,6 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; - Client.prototype.refreshBranding = function (callback) { - var that = this; - - // currently only deals with background - this.refreshProfile(function () { - that.hasCloudronBackground(function (error, result) { - if (error) return callback(error); - - if (that._userInfo && that._userInfo.hasBackgroundImage) { - document.getElementById('mainContentContainer').style.backgroundImage = 'url("' + that.apiOrigin + '/api/v1/profile/background_image?access_token=' + token + '&bustcache=' + Date.now() + '")'; - document.getElementById('mainContentContainer').classList.add('has-background'); - } else if (result) { - document.getElementById('mainContentContainer').style.backgroundImage = 'url("' + that.apiOrigin + '/api/v1/cloudron/background?bustcache=' + Date.now() + '")'; - document.getElementById('mainContentContainer').classList.add('has-background'); - } else { - document.getElementById('mainContentContainer').style.backgroundImage = 'none'; - document.getElementById('mainContentContainer').classList.remove('has-background'); - } - - callback(null); - }); - }); - }; - Client.prototype._appPostProcess = function (app) { // calculate the icon paths app.iconUrl = app.iconUrl ? (this.apiOrigin + app.iconUrl + '?access_token=' + token + '&ts=' + app.ts) : null; diff --git a/dashboard/src/js/index.js b/dashboard/src/js/index.js index 7dd63fefb..6e1e099db 100644 --- a/dashboard/src/js/index.js +++ b/dashboard/src/js/index.js @@ -790,7 +790,6 @@ app.controller('MainController', ['$scope', '$route', '$timeout', '$location', ' Client.refreshProfile.bind(Client), Client.refreshConfig.bind(Client), Client.refreshAvailableLanguages.bind(Client), - Client.refreshBranding.bind(Client), Client.refreshInstalledApps.bind(Client) ], function (error) { if (error) return Client.initError(error, init); @@ -800,6 +799,11 @@ app.controller('MainController', ['$scope', '$route', '$timeout', '$location', ' $scope.config = Client.getConfig(); + if (Client.getUserInfo().hasBackgroundImage) { + document.getElementById('mainContentContainer').style.backgroundImage = 'url("' + Client.getBackgroundImageUrl() + '")'; + document.getElementById('mainContentContainer').classList.add('has-background'); + } + $scope.initialized = true; redirectOnMandatory2FA(); diff --git a/dashboard/src/views/branding.js b/dashboard/src/views/branding.js index ba28169b6..be0a8bfe9 100644 --- a/dashboard/src/views/branding.js +++ b/dashboard/src/views/branding.js @@ -268,9 +268,7 @@ angular.module('Application').controller('BrandingController', ['$scope', '$loca $scope.about.avatar = null; $scope.about.refresh(); - Client.refreshBranding(function () { - $scope.about.busy = false; - }); + $scope.about.busy = false; }); }); }); diff --git a/dashboard/src/views/profile.js b/dashboard/src/views/profile.js index 90d25779e..f3fc00513 100644 --- a/dashboard/src/views/profile.js +++ b/dashboard/src/views/profile.js @@ -247,13 +247,13 @@ angular.module('Application').controller('ProfileController', ['$scope', '$trans Client.setBackgroundImage(imageFile, function (error) { if (error) return console.error('Unable to change backgroundImage.', error); - Client.refreshBranding(function () { - $scope.user.hasBackgroundImage = true; + document.getElementById('mainContentContainer').style.backgroundImage = 'url("' + Client.getBackgroundImageUrl() + '")'; + document.getElementById('mainContentContainer').classList.add('has-background'); - $('#backgroundImageChangeModal').modal('hide'); + $scope.user.hasBackgroundImage = true; - $scope.backgroundImageChange.reset(); - }); + $('#backgroundImageChangeModal').modal('hide'); + $scope.backgroundImageChange.reset(); }); }, @@ -261,12 +261,13 @@ angular.module('Application').controller('ProfileController', ['$scope', '$trans Client.setBackgroundImage(null, function (error) { if (error) return console.error('Unable to change backgroundImage.', error); - Client.refreshBranding(function () { - $scope.user.hasBackgroundImage = false; + document.getElementById('mainContentContainer').style.backgroundImage = ''; + document.getElementById('mainContentContainer').classList.remove('has-background'); - $('#backgroundImageChangeModal').modal('hide'); - $scope.backgroundImageChange.reset(); - }); + $scope.user.hasBackgroundImage = false; + + $('#backgroundImageChangeModal').modal('hide'); + $scope.backgroundImageChange.reset(); }); }, @@ -278,7 +279,7 @@ angular.module('Application').controller('ProfileController', ['$scope', '$trans reset: function () { $scope.backgroundImageChange.error.avatar = null; - if ($scope.user.hasBackgroundImage) document.getElementById('previewBackgroundImage').src = Client.apiOrigin + '/api/v1/profile/background_image?access_token=' + Client.getToken() + '&bustcache=' + Date.now(); + if ($scope.user.hasBackgroundImage) document.getElementById('previewBackgroundImage').src = Client.getBackgroundImageUrl(); else document.getElementById('previewBackgroundImage').src = '/img/background-image-placeholder.svg'; $scope.backgroundImageChange.pictureChanged = false;