mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-21 23:02:22 +01:00
* Cropping remove, nicer UI * Fix MIME-type checking, add image upload tests * Change image config settings to uploads.profile.image to build a more rational structure for configuring other types of uploads
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
angular
|
|
.module('users')
|
|
.controller('ChangeProfilePictureController', ChangeProfilePictureController);
|
|
|
|
ChangeProfilePictureController.$inject = ['$timeout', 'Authentication', 'Upload', 'Notification'];
|
|
|
|
function ChangeProfilePictureController($timeout, Authentication, Upload, Notification) {
|
|
var vm = this;
|
|
|
|
vm.user = Authentication.user;
|
|
vm.progress = 0;
|
|
|
|
vm.upload = function (dataUrl) {
|
|
|
|
Upload.upload({
|
|
url: '/api/users/picture',
|
|
data: {
|
|
newProfilePicture: dataUrl
|
|
}
|
|
}).then(function (response) {
|
|
$timeout(function () {
|
|
onSuccessItem(response.data);
|
|
});
|
|
}, function (response) {
|
|
if (response.status > 0) onErrorItem(response.data);
|
|
}, function (evt) {
|
|
vm.progress = parseInt(100.0 * evt.loaded / evt.total, 10);
|
|
});
|
|
};
|
|
|
|
// Called after the user has successfully uploaded a new picture
|
|
function onSuccessItem(response) {
|
|
// Show success message
|
|
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Successfully changed profile picture' });
|
|
|
|
// Populate user object
|
|
vm.user = Authentication.user = response;
|
|
|
|
// Reset form
|
|
vm.fileSelected = false;
|
|
vm.progress = 0;
|
|
}
|
|
|
|
// Called after the user has failed to upload a new picture
|
|
function onErrorItem(response) {
|
|
vm.fileSelected = false;
|
|
vm.progress = 0;
|
|
|
|
// Show error message
|
|
Notification.error({ message: response.message, title: '<i class="glyphicon glyphicon-remove"></i> Failed to change profile picture' });
|
|
}
|
|
}
|
|
}());
|