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.

64 lines
2.2 KiB

4 years ago
  1. app.controller('PersonalFormController', function($scope, $cookieStore, $http, $location, $routeParams, $modal, Upload) {
  2. if( typeof($cookieStore.get('user')) != "undefined" ){
  3. $scope.user = $cookieStore.get('user');
  4. if($routeParams.id){
  5. $http({
  6. method: 'GET',
  7. url: serverURL+"/personals/show/"+$routeParams.id,
  8. data: {
  9. user: $scope.user
  10. },
  11. headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  12. }).success(function(data, status, headers, config) {
  13. if(data.success == "true"){
  14. $scope.personal = data.personal;
  15. }else{
  16. modal = modalCreate($modal,"danger", "Error", "It has successfully made the connection but something went wrong");
  17. }
  18. }).error(function(data, status, headers, config) {
  19. modal = modalCreate($modal,"danger", "Error", "Not connected with server.");
  20. });
  21. }
  22. $scope.createPersonal = function (personal) {
  23. $http({
  24. method: 'POST',
  25. url: serverURL+"/personals/form",
  26. data: {
  27. personal: personal,
  28. user: $scope.user
  29. },
  30. headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  31. }).success(function(data, status, headers, config) {
  32. if(data.success == "true"){
  33. $location.path( "/personals" );
  34. }else{
  35. modal = modalCreate($modal,"danger", "Error", "It has successfully made the connection but something went wrong");
  36. }
  37. }).error(function(data, status, headers, config) {
  38. modal = modalCreate($modal,"danger", "Error", "Not connected with server.");
  39. });
  40. };
  41. // upload on file select or drop
  42. $scope.upload = function (file) {
  43. if (file && !file.$error) {
  44. Upload.upload({
  45. url: serverURL+"/user/photo",
  46. data: {'user': $scope.user},
  47. file: file
  48. }).progress(function (evt) {
  49. var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
  50. $scope.progressPercentage = progressPercentage;
  51. }).success(function (data, status, headers, config) {
  52. $scope.user.img = data.img;
  53. $cookieStore.put('user', $scope.user);
  54. $scope.progressPercentage = 0;
  55. }).error(function (data, status, headers, config) {
  56. modal = modalCreate($modal,"danger", "Error", "Error to upload an image.");
  57. })
  58. }
  59. };
  60. }
  61. });