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.

71 lines
2.6 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.JPEG,
  14. targetWidth: 100,
  15. targetHeight: 100,
  16. popoverOptions: CameraPopoverOptions,
  17. saveToPhotoAlbum: false,
  18. correctOrientation:true
  19. };
  20. $cordovaCamera.getPicture(options).then(function(imageData) {
  21. $scope.user.avatar = "data:image/jpeg;base64," + imageData;
  22. }, function(err) {
  23. console.log(err);
  24. });
  25. };
  26. $scope.selectFaircoinPublicKey = function(){
  27. console.log("img");
  28. var options = {
  29. quality: 100,
  30. destinationType: Camera.DestinationType.DATA_URL,
  31. sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
  32. allowEdit: true,
  33. encodingType: Camera.EncodingType.JPEG,
  34. targetWidth: 100,
  35. targetHeight: 100,
  36. popoverOptions: CameraPopoverOptions,
  37. saveToPhotoAlbum: false,
  38. correctOrientation:true
  39. };
  40. $cordovaCamera.getPicture(options).then(function(imageData) {
  41. $scope.user.faircoin = "data:image/jpeg;base64," + imageData;
  42. }, function(err) {
  43. console.log(err);
  44. });
  45. };
  46. $scope.update=function(){
  47. $http({
  48. url: urlapi + 'users',
  49. method: "PUT",
  50. data: $scope.user
  51. })
  52. .then(function(data) {
  53. // success
  54. console.log("data: ");
  55. console.log(data.data);
  56. localStorage.setItem("cim_app_userdata", JSON.stringify(data.data));
  57. window.location="#/app/users/" + data.data._id;
  58. },
  59. function(data) { // optional
  60. // failed
  61. $ionicLoading.show({
  62. template: 'Error on update',
  63. noBackdrop: true,
  64. duration: 2000
  65. });
  66. });
  67. };
  68. });