Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $scope.handleFileSelect = function(files) {
- var uploadedFile = files[0];
- var general = $scope.data;
- var func = $scope.edit;
- $scope.isReadyCrop = true;
- $mdDialog.show({
- templateUrl: 'dialogs/image-crop.html',
- clickOutsideToClose: false,
- controller: function($scope, $mdDialog, apiService, modalService) {
- 'ngInject';
- $scope.profile = general;
- $scope.myImage = '';
- $scope.myCroppedImage = '';
- $scope.fileName = '';
- $scope.fileType = '';
- $scope.newFile = uploadedFile;
- $scope.$watch('newFile', function(newFile) {
- if (newFile) {
- $scope.fileName = $scope.formatName(newFile);
- $scope.fileType = newFile.type;
- var reader = new FileReader();
- reader.onload = function(evt) {
- $scope.$apply(function($scope) {
- $scope.myImage = evt.target.result;
- });
- };
- reader.readAsDataURL(newFile);
- }
- });
- $scope.formatName = function(file) {
- var unformatted = file.name.split('.')[0];
- var split_space = unformatted.split(' ');
- return split_space.join('-');
- }
- $scope.cancel = function() {
- $mdDialog.hide();
- }
- $scope.saveCrop = function() {
- if ($scope.myCroppedImage) {
- apiService.postHeader('/account/upload/image/' + $scope.fileName, $scope.myCroppedImage, {
- "Content-Type": 'image/png;base64'
- }).then(function successCallback(result) {
- $scope.result = result
- $mdDialog.hide();
- $scope.isReadyCrop = false;
- // $scope.profile.profile_image = result;
- $scope.imgVersion = "?" + (new Date()).getTime();
- func({
- arg: {
- fieldvalue: {
- general: {
- 'profile_image': result
- }
- }
- }
- });
- }, function errorCallback(err) {
- modalService.ERROR(err)
- });
- }
- };
- }
- })
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement