You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
3.0 KiB

  1. angular.module('app.editUser', ['pascalprecht.translate'])
  2. .controller('EditUserCtrl', function($scope, $stateParams, $http, $filter,
  3. $ionicModal, $cordovaCamera, $ionicLoading) {
  4. $scope.storageuser = JSON.parse(localStorage.getItem("cim_app_userdata"));
  5. $scope.user=$scope.storageuser;
  6. $scope.selectAvatar = function(){
  7. console.log("img");
  8. var options = {
  9. quality: 100,
  10. destinationType: Camera.DestinationType.DATA_URL,
  11. sourceType: Camera.sourceType,
  12. allowEdit: true,
  13. encodingType: Camera.EncodingType.PNG,
  14. targetWidth: 500,
  15. targetHeight: 500,
  16. popoverOptions: CameraPopoverOptions,
  17. saveToPhotoAlbum: false,
  18. correctOrientation:true
  19. };
  20. $cordovaCamera.getPicture(options).then(function(imageData) {
  21. //$scope.user.newAvatar = "data:image/jpeg;base64," + imageData;
  22. $scope.user.avatar = "data:image/jpeg;base64," + imageData;
  23. $scope.user.newAvatar = imageData;
  24. }, function(err) {
  25. console.log(err);
  26. });
  27. /*$cordovaCamera.getPicture(options).then(function(imageURI) {
  28. $scope.user.avatar = imageURI;
  29. $scope.user.newAvatar = imageURI;
  30. }, function(err) {
  31. console.log(err);
  32. });*/
  33. };
  34. $scope.selectFaircoinPublicKey = function(){
  35. console.log("img");
  36. var options = {
  37. quality: 100,
  38. destinationType: Camera.DestinationType.DATA_URL,
  39. sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
  40. allowEdit: true,
  41. encodingType: Camera.EncodingType.JPEG,
  42. targetWidth: 100,
  43. targetHeight: 100,
  44. popoverOptions: CameraPopoverOptions,
  45. saveToPhotoAlbum: false,
  46. correctOrientation:true
  47. };
  48. $cordovaCamera.getPicture(options).then(function(imageData) {
  49. $scope.user.faircoin = "data:image/jpeg;base64," + imageData;
  50. $scope.user.newFaircoin = imageData;
  51. }, function(err) {
  52. console.log(err);
  53. });
  54. };
  55. $scope.update=function(){
  56. $http({
  57. url: urlapi + 'users',
  58. method: "PUT",
  59. data: $scope.user
  60. })
  61. .then(function(data) {
  62. // success
  63. console.log("data: ");
  64. console.log(data.data);
  65. localStorage.setItem("cim_app_userdata", JSON.stringify(data.data));
  66. window.location="#/app/users/" + data.data._id;
  67. },
  68. function(data) { // optional
  69. // failed
  70. $ionicLoading.show({
  71. template: 'Error on update',
  72. noBackdrop: true,
  73. duration: 2000
  74. });
  75. });
  76. };
  77. });