Improve avatar settings dialog

This commit is contained in:
Johannes Zellner
2019-12-12 15:34:26 +01:00
parent fd528edfed
commit 2eeb99e869
4 changed files with 48 additions and 28 deletions

View File

@@ -101,6 +101,9 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat
busy: false,
error: {},
avatar: null,
useGravatar: '',
useGravatarOrig: '',
pictureChanged: false,
getBlobFromImg: function (img, callback) {
var size = 256;
@@ -137,9 +140,12 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat
canvas.toBlob(callback);
},
clearAvatar: function () {
Client.clearAvatar(function (error) {
if (error) return console.error(error);
doChangeAvatar: function () {
$scope.avatarChange.error.avatar = null;
$scope.avatarChange.busy = true;
function done(error) {
if (error) return console.error('Unable to change avatar.', error);
Client.refreshUserInfo(function (error) {
if (error) return console.error(error);
@@ -147,35 +153,29 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat
$('#avatarChangeModal').modal('hide');
$scope.avatarChange.avatarChangeReset();
});
});
},
}
doChangeAvatar: function () {
$scope.avatarChange.error.avatar = null;
$scope.avatarChange.busy = true;
var img = document.getElementById('previewAvatar');
$scope.avatarChange.avatar.file = $scope.avatarChange.getBlobFromImg(img, function (blob) {
Client.changeAvatar(blob, function (error) {
if (error) return console.error('Unable to change cloudron avatar.', error);
Client.refreshUserInfo(function (error) {
if (error) return console.error(error);
$('#avatarChangeModal').modal('hide');
$scope.avatarChange.avatarChangeReset();
});
if ($scope.avatarChange.useGravatar) {
Client.clearAvatar(done);
} else {
var img = document.getElementById('previewAvatar');
$scope.avatarChange.getBlobFromImg(img, function (blob) {
Client.changeAvatar(blob, done);
});
});
}
},
setPreviewAvatar: function (avatar) {
$scope.avatarChange.pictureChanged = true;
$scope.avatarChange.avatar = avatar;
},
avatarChangeReset: function () {
$scope.avatarChange.error.avatar = null;
$scope.avatarChange.avatar = {
$scope.avatarChange.useGravatar = $scope.user.avatarUrl.indexOf('https://www.gravatar.com') === 0 ? 'true_string' : '';
$scope.avatarChange.useGravatarOrig = $scope.avatarChange.useGravatar;
$scope.avatarChange.pictureChanged = false;
$scope.avatarChange.avatar = $scope.avatarChange.useGravatar ? {} : {
url: $scope.user.avatarUrl
};
$scope.avatarChange.busy = false;