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