%PDF- %PDF-
Direktori : /var/www/html/news/public/scripts/controllers/profile/ |
Current File : /var/www/html/news/public/scripts/controllers/profile/profile.controller.js |
'use strict'; angular.module('controllers').controller('profileController', function ($scope, user, resource, notification, $rootScope, auth, Cropper, $timeout) { $scope.user = angular.extend(user); $scope.user.birthdate = moment($scope.user.birthdate).toDate(); $scope.showEvent = 'show'; $scope.hideEvent = 'hide'; $scope.cropperProxy = 'cropper.first'; $scope.save = function () { resource.forResource('users').update($scope.user.id, $scope.user).then(function (res) { notification.success('Profile information updated successfully'); $scope.refreshUserInfo(); }, function (error) { notification.error(error); }); }; $scope.back = function () { history.back(); }; $scope.toggleDatepicker = function () { $scope.birthdatePicker = !$scope.birthdatePicker; }; $scope.changePassword = function () { resource.forResource('users/' + $scope.user.id + '/actions/changePassword').save($scope.req).then(function (response) { notification.success('Password changed successfully'); }, function (error) { notification.error(error); }); }; $scope.back = function () { history.back(); }; $scope.options = { maximize: false, aspectRatio: 1 / 1, zoomable: false, zoomOnTouch: false, zoomOnWheel: false, preview: '.img-live-preview', crop: function (dataNew) { $scope.croppedImageResult = dataNew; }, built: function (a) { } }; $scope.fileAdded = function (files) { $scope.file = files[0].file; var reader = new FileReader(); reader.readAsDataURL($scope.file); reader.onload = function () { $timeout(function () { $scope.selectedImage = reader.result; }, 100); }; }; $scope.showCropper = function () { $scope.isCropping = true; $scope.$broadcast($scope.showEvent); }; $scope.hideCropper = function () { $scope.isCropping = false; $scope.$broadcast($scope.hideEvent); }; $scope.crop = function () { if ($scope.isCropping) { $timeout($scope.hideCropper()); Cropper.crop($scope.file, $scope.croppedImageResult).then(Cropper.encode).then(function (dataUrl) { $scope.selectedImage = dataUrl; $scope.uploadProfilePicture(dataUrl); }); } else { $timeout($scope.showCropper()); } }; $scope.uploadProfilePicture = function (source) { var payload = { file_name: $scope.file.name, type: 'image_profile', source: source.split(',')[1] }; resource.forResource('users/' + $scope.user.id + '/actions/uploadPicture').save(payload).then(function (res) { notification.success('Profile picture uploaded successfully'); $scope.user.profile_picture = res.url; $scope.refreshUserInfo(); }, function (err) { notification.error(err); }); }; $scope.refreshUserInfo = function () { auth.updateUserData().then(function (response) { auth.setUserData(response.data); $rootScope.updateShowingInformation(); $scope.selectedImage = null; }); }; });