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.

104 lines
3.5 KiB

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