openEventsPlatformApp/www/js/event.js
www/js/event.jsRaw
1angular.module('app.event', ['pascalprecht.translate', 'ui-leaflet'])
2
3.controller('EventCtrl', function($scope, $http, $ionicModal,
4 $stateParams, $timeout, $ionicLoading, $filter, $ionicPopup,
5 leafletData, leafletBoundsHelpers, $cordovaSocialSharing) {
6
7
8 $scope.center= {
9 lat: 0,
10 lng: 0,
11 zoom: 1
12 };
13 $scope.markers=[];
14 $scope.tiles= {
15 url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
16 options: {
17 attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
18 }
19 };
20
21
22 $scope.event={};
23 $scope.doRefresh = function() {
24 /* events refresh: */
25 $http.get(urlapi + 'events/id/'+ $stateParams.eventid)
26 .then(function(data){
27 console.log('data success events');
28 console.log(data); // for browser console
29 //$scope.events = data.data; // for UI
30 $scope.event=data.data;
31 $scope.$broadcast('scroll.refreshComplete');//refresher stop
32
33 if($scope.event.location)
34 {
35 $scope.markers=[];
36 $scope.markers.push({
37 lat: Number($scope.event.location.geo.lat),
38 lng: Number($scope.event.location.geo.long),
39 message: $scope.event.location.direction
40 });
41 $scope.center= {
42 lat: Number($scope.event.location.geo.lat),
43 lng: Number($scope.event.location.geo.long),
44 zoom: 16
45 };
46 }
47
48 }, function(data){
49 console.log('data error');
50 $scope.$broadcast('scroll.refreshComplete');//refresher stop
51 $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 });
52
53 });
54 };
55 $scope.doRefresh();
56
57
58 $scope.share = function(event){
59 var message = "[" + event.title + "]" + event.description;
60 /*var subject = event.title;
61 var file= ['',''];*/
62 var link = "http://duckduckgo.com";
63 $cordovaSocialSharing
64 .share(message, link) // Share via native share sheet
65 .then(function(result) {
66 // Success!
67 }, function(err) {
68 // An error occured. Show a message to the user
69 });
70 };
71
72
73
74 $scope.deleteEvent = function(){
75 var confirmPopup = $ionicPopup.confirm({
76 title: 'Deleting event',
77 template: 'Are you sure you want to delete <b>'+ $scope.event.title+'</b>?'
78 });
79 confirmPopup.then(function(res) {
80 if(res) {
81 console.log('You are sure');
82 console.log("delete travel: " + $stateParams.eventid);
83 $http({
84 url: urlapi + '/events/id/' + $stateParams.eventid,
85 method: "DELETE"
86 })
87 .then(function(response) {
88 console.log(response);
89 $scope.events=response.data;
90 /*localStorage.setItem('c_travels', JSON.stringify($scope.travels));
91 localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date()));*/
92 $ionicLoading.show({ template: 'Event deleted', noBackdrop: true, duration: 2000 });
93 window.location.href="#/app/main";
94 },
95 function(response) { // optional
96 // failed
97 $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 });
98 });
99 } else {
100 console.log('You are not sure');
101 }
102 });
103 };
104});