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.

125 lines
3.6 KiB

  1. angular.module('app.newEvent', ['pascalprecht.translate', 'ui-leaflet'])
  2. .controller('NewEventCtrl', function($scope, $http, $ionicModal, $timeout,
  3. $ionicLoading, $filter, leafletData, leafletBoundsHelpers,
  4. $cordovaCamera) {
  5. //initialization
  6. $scope.event={};
  7. $scope.event.categories=[];
  8. $scope.event.location={
  9. direction: "",
  10. geo: {
  11. lat: "",
  12. long: "",
  13. name: ""
  14. }
  15. };
  16. //imgfile
  17. $scope.selectImgFile = function() {
  18. console.log("img");
  19. var options = {
  20. quality: 100,
  21. destinationType: Camera.DestinationType.DATA_URL,
  22. sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
  23. allowEdit: true,
  24. encodingType: Camera.EncodingType.PNG,
  25. targetWidth: 500,
  26. targetHeight: 500,
  27. popoverOptions: CameraPopoverOptions,
  28. saveToPhotoAlbum: false,
  29. correctOrientation: true
  30. };
  31. $cordovaCamera.getPicture(options).then(function(imageData) {
  32. $scope.event.imgpreview = "data:image/jpeg;base64," + imageData;
  33. $scope.event.img = imageData;
  34. }, function(err) {
  35. console.log(err);
  36. });
  37. };
  38. //get list of categories
  39. $scope.categories;
  40. $http.get(urlapi + 'categoriesList')
  41. .then(function(data){
  42. $scope.categories=data.data;
  43. console.log($scope.categories);
  44. }, function(data){
  45. console.log('data error');
  46. console.log(data);
  47. $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 });
  48. });
  49. $scope.categorySelected = function(){
  50. $scope.event.categories=[];
  51. for(var i=0; i<$scope.categories.length; i++)
  52. {
  53. if($scope.categories[i].selected)
  54. {
  55. $scope.event.categories.push($scope.categories[i]);
  56. }
  57. }
  58. console.log($scope.event.categories);
  59. };
  60. $scope.postEvent = function(){
  61. $http({
  62. url: urlapi + 'events',
  63. method: "POST",
  64. data: $scope.event
  65. })
  66. .then(function(data) {
  67. $scope.event={};
  68. window.location.href="#/app/events";
  69. },
  70. function(response) { // optional
  71. // failed
  72. console.log(response);
  73. });
  74. };
  75. /* map */
  76. $scope.center= {
  77. lat: 0,
  78. lng: 0,
  79. zoom: 1
  80. };
  81. $scope.markers=new Array();
  82. $scope.tiles= {
  83. url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
  84. options: {
  85. attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
  86. }
  87. };
  88. $scope.getGeo = function(){
  89. $scope.markers=[];
  90. console.log($scope.event.location.direction);
  91. $http.get('http://nominatim.openstreetmap.org/search?q=' + $scope.event.location.direction + '&format=json&limit=1')
  92. .then(function(data) {
  93. console.log(data);
  94. if(data.data[0])
  95. {
  96. $scope.event.location.geo.lat=data.data[0].lat;
  97. $scope.event.location.geo.long=data.data[0].lon;
  98. //$scope.newtravel.from.name=data.data[0].display_name;
  99. $scope.markers.push({
  100. lat: Number(data.data[0].lat),
  101. lng: Number(data.data[0].lon),
  102. message: $scope.event.location.direction
  103. });
  104. $scope.center= {
  105. lat: Number(data.data[0].lat),
  106. lng: Number(data.data[0].lon),
  107. zoom: 16
  108. };
  109. }
  110. });
  111. };
  112. });