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.

100 lines
2.9 KiB

  1. angular.module('app.newEvent', ['pascalprecht.translate', 'ui-leaflet'])
  2. .controller('NewEventCtrl', function($scope, $http, $ionicModal, $timeout,
  3. $ionicLoading, $filter, leafletData, leafletBoundsHelpers) {
  4. //initialization
  5. $scope.event={};
  6. $scope.event.categories=[];
  7. $scope.event.location={
  8. direction: "",
  9. geo: {
  10. lat: "",
  11. long: "",
  12. name: ""
  13. }
  14. };
  15. //get list of categories
  16. $scope.categories;
  17. $http.get(urlapi + 'categoriesList')
  18. .then(function(data){
  19. $scope.categories=data.data;
  20. console.log($scope.categories);
  21. }, function(data){
  22. console.log('data error');
  23. console.log(data);
  24. $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 });
  25. });
  26. $scope.categorySelected = function(){
  27. $scope.event.categories=[];
  28. for(var i=0; i<$scope.categories.length; i++)
  29. {
  30. if($scope.categories[i].selected)
  31. {
  32. $scope.event.categories.push($scope.categories[i]);
  33. }
  34. }
  35. console.log($scope.event.categories);
  36. };
  37. $scope.postEvent = function(){
  38. $http({
  39. url: urlapi + 'events',
  40. method: "POST",
  41. data: $scope.event
  42. })
  43. .then(function(data) {
  44. $scope.event={};
  45. window.location.href="#/app/events";
  46. },
  47. function(response) { // optional
  48. // failed
  49. console.log(response);
  50. });
  51. };
  52. /* map */
  53. $scope.center= {
  54. lat: 0,
  55. lng: 0,
  56. zoom: 1
  57. };
  58. $scope.markers=new Array();
  59. $scope.tiles= {
  60. url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
  61. options: {
  62. attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
  63. }
  64. };
  65. $scope.getGeo = function(){
  66. $scope.markers=[];
  67. console.log($scope.event.location.direction);
  68. $http.get('http://nominatim.openstreetmap.org/search?q=' + $scope.event.location.direction + '&format=json&limit=1')
  69. .then(function(data) {
  70. console.log(data);
  71. if(data.data[0])
  72. {
  73. $scope.event.location.geo.lat=data.data[0].lat;
  74. $scope.event.location.geo.long=data.data[0].lon;
  75. //$scope.newtravel.from.name=data.data[0].display_name;
  76. $scope.markers.push({
  77. lat: Number(data.data[0].lat),
  78. lng: Number(data.data[0].lon),
  79. message: $scope.event.location.direction
  80. });
  81. $scope.center= {
  82. lat: Number(data.data[0].lat),
  83. lng: Number(data.data[0].lon),
  84. zoom: 16
  85. };
  86. }
  87. });
  88. };
  89. });