mirror of https://github.com/nextcloud/contacts
37 lines
900 B
JavaScript
37 lines
900 B
JavaScript
angular.module('contactsApp')
|
|
.directive('avatar', function(ContactService) {
|
|
return {
|
|
scope: {
|
|
contact: '=data'
|
|
},
|
|
controller: 'avatarCtrl',
|
|
controllerAs: 'ctrl',
|
|
bindToController: {
|
|
contact: '=data'
|
|
},
|
|
link: function(scope, element) {
|
|
var input = element.find('input');
|
|
input.bind('change', function() {
|
|
var file = input.get(0).files[0];
|
|
if (file.size > 1024*1024) { // 1 MB
|
|
OC.Notification.showTemporary(t('contacts', 'The selected image is too big (max 1MB)'));
|
|
} else {
|
|
var reader = new FileReader();
|
|
|
|
reader.addEventListener('load', function () {
|
|
scope.$apply(function() {
|
|
scope.contact.photo(reader.result);
|
|
ContactService.update(scope.contact);
|
|
});
|
|
}, false);
|
|
|
|
if (file) {
|
|
reader.readAsDataURL(file);
|
|
}
|
|
}
|
|
});
|
|
},
|
|
templateUrl: OC.linkTo('contacts', 'templates/avatar.html')
|
|
};
|
|
});
|