Advertisement
Guest User

Untitled

a guest
Jun 12th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. // amadeusounds.controller('ValidateController',
  2. // [
  3. // '$scope',
  4. // '$rootScope',
  5. // '$location',
  6. // '$filter',
  7. // 'UserService',
  8. //
  9. // function($scope, $rootScope, $location, $filter, UserService) {
  10. //
  11. // $scope.register = function() {
  12. // UserService.authenticate($.param({
  13. // first: $scope.first,
  14. // last: $scope.last,
  15. // email: $scope.email,
  16. // password: $scope.password,
  17. // image: $scope.image,
  18. // bio: $scope.bio,
  19. // website: $scope.website
  20. // }), function(authenticationResult) {
  21. // UserService.post(function(u) {
  22. // $rootScope.user = u;
  23. // alert("NAJAVEN");
  24. // });
  25. // $rootScope.loginAction = true;
  26. // if($rootScope.returnPath
  27. // && $rootScope.returnPath != "/login") {
  28. // $location.path($rootScope.returnPath);
  29. // delete $rootScope.returnPath;
  30. // } else {
  31. // $location.path("/");
  32. // }
  33. // alert("NAJAVEN JOK " + authenticationResult);
  34. // },
  35. // function() {
  36. // //toaster.pop('error', $filter('translate')('generic.login_error'),
  37. // // $filter('translate')('generic.invalid_username_or_password'));
  38. // alert("Greska pri najavuvanje");
  39. // });
  40. // };
  41. // }]);
  42.  
  43. amadeusounds.directive('fileModel', ['$parse', function ($parse) {
  44. return {
  45. restrict: 'A',
  46. link: function(scope, element, attrs) {
  47. var model = $parse(attrs.fileModel);
  48. var modelSetter = model.assign;
  49.  
  50. element.bind('change', function(){
  51. scope.$apply(function(){
  52. modelSetter(scope, element[0].files[0]);
  53. });
  54. });
  55. }
  56. };
  57. }]);
  58.  
  59. amadeusounds.service('fileUpload', ['$http', function ($http) {
  60. this.uploadFileToUrl = function(file, uploadUrl){
  61. var fd = new FormData();
  62. fd.append('file', file);
  63.  
  64. $http.post(uploadUrl, fd, {
  65. transformRequest: angular.identity,
  66. headers: {'Content-Type': undefined}
  67. })
  68.  
  69. .success(function(){
  70. })
  71.  
  72. .error(function(){
  73. });
  74. }
  75. }]);
  76.  
  77. amadeusounds.controller("ValidateController", ['$scope', '$http','fileUpload', function ($scope, $http,fileUpload) {
  78.  
  79. $scope.data1 = {};
  80. $scope.countries={};
  81. $http.get('json/countries.json').
  82. success(function(data, status, headers, config) {
  83. $scope.countries = data;
  84.  
  85. }).
  86. error(function(data, status, headers, config) {
  87. // log error
  88. });
  89. $scope.uploadFile = function(id){
  90. var file = $scope.myFile;
  91.  
  92. console.log('file is ' );
  93. console.dir(file);
  94.  
  95. var uploadUrl = "/api/admin/users/"+id+"/image";
  96. fileUpload.uploadFileToUrl(file, uploadUrl);
  97. };
  98.  
  99. $scope.SendData = function () {
  100. $scope.uploadFile(1).name;
  101.  
  102.  
  103. $scope.data1.firstName = $scope.firstName;
  104. $scope.data1.lastName= $scope.lastName;
  105. $scope.data1.email= $scope.email;
  106. $scope.data1.password= $scope.password;
  107. $scope.data1.location = $scope.location;
  108. $scope.data1.image= $scope.uploadFile(1).name;
  109. $scope.data1.biography= $scope.biography;
  110. $scope.data1.website= $scope.website;
  111. $http({
  112. method: "POST",
  113. url: "/api/users/register",
  114. data: $scope.data1
  115. })
  116. .then(
  117. function success1(response) {
  118. $scope.PostDataResponse = response.data.message;
  119. },
  120. function error1(response) {
  121. console.log(response);
  122. return response;
  123. }
  124. );
  125.  
  126. };
  127.  
  128. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement