mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-05-05 16:46:07 +02:00
* Add ng-file-upload and picture cropping * Update bower.json Remove bower dependency for angular-file-upload
57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
angular
|
|
.module('users')
|
|
.controller('ChangeProfilePictureController', ChangeProfilePictureController);
|
|
|
|
ChangeProfilePictureController.$inject = ['$timeout', 'Authentication', 'Upload'];
|
|
|
|
function ChangeProfilePictureController($timeout, Authentication, Upload) {
|
|
var vm = this;
|
|
|
|
vm.user = Authentication.user;
|
|
vm.fileSelected = false;
|
|
|
|
vm.upload = function (dataUrl, name) {
|
|
vm.success = vm.error = null;
|
|
|
|
Upload.upload({
|
|
url: 'api/users/picture',
|
|
data: {
|
|
newProfilePicture: Upload.dataUrltoBlob(dataUrl, name)
|
|
}
|
|
}).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
|
|
vm.success = true;
|
|
|
|
// Populate user object
|
|
vm.user = Authentication.user = response;
|
|
|
|
// Reset form
|
|
vm.fileSelected = false;
|
|
vm.progress = 0;
|
|
}
|
|
|
|
// Called after the user has failed to uploaded a new picture
|
|
function onErrorItem(response) {
|
|
vm.fileSelected = false;
|
|
|
|
// Show error message
|
|
vm.error = response.message;
|
|
}
|
|
}
|
|
}());
|