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.

85 lines
3.1 KiB

  1. angular.module('app.events', ['pascalprecht.translate'])
  2. .controller('EventsCtrl', function($scope, $http, $ionicModal,
  3. $timeout, $ionicLoading, $filter, $cordovaSocialSharing) {
  4. $scope.events=[];
  5. $scope.alerts=[];
  6. $scope.page=0;
  7. $scope.doRefresh = function() {
  8. /* events refresh: */
  9. //$http.get(urlapi + 'events?page=' + $scope.page)
  10. $scope.followingUsers = JSON.parse(localStorage.getItem("events_app_followingUsers"));
  11. console.log($scope.followingUsers);
  12. $http({
  13. url: urlapi + 'events/following',
  14. method: "POST",
  15. data: {users: $scope.followingUsers}
  16. })
  17. .then(function(data){
  18. console.log('data success events');
  19. console.log(data); // for browser console
  20. //$scope.events = data.data; // for UI
  21. $scope.events=data.data;
  22. $scope.$broadcast('scroll.refreshComplete');//refresher stop
  23. }, function(data){
  24. console.log('data error');
  25. $scope.$broadcast('scroll.refreshComplete');//refresher stop
  26. $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 });
  27. });
  28. $http.get(urlapi + 'alerts')
  29. .then(function(data){
  30. $scope.alerts=data.data;
  31. }, function(data){
  32. });
  33. };
  34. $scope.doRefresh();
  35. $scope.share = function(event){
  36. var message = "[" + event.title + "]" + event.description;
  37. /*var subject = event.title;
  38. var file= ['',''];*/
  39. var link = "http://duckduckgo.com";
  40. $cordovaSocialSharing
  41. .share(message, link) // Share via native share sheet
  42. .then(function(result) {
  43. // Success!
  44. }, function(err) {
  45. // An error occured. Show a message to the user
  46. });
  47. };
  48. $scope.savedEvents=[];
  49. $scope.$on('$ionicView.enter', function(){//per executar-ho cada cop que es carrega el view
  50. if (localStorage.getItem("events_app_savedEvents")) {
  51. $scope.savedEvents = JSON.parse(localStorage.getItem("events_app_savedEvents"));
  52. console.log("savedEvents");
  53. console.log($scope.savedEvents);
  54. }
  55. });
  56. $scope.saveEvent = function(event){
  57. $scope.savedEvents.push(event);
  58. localStorage.setItem("events_app_savedEvents", JSON.stringify($scope.savedEvents));
  59. $ionicLoading.show({ template: 'Event saved', noBackdrop: true, duration: 1000 });
  60. };
  61. $scope.unsaveEvent = function(event){
  62. for(var i=0; i<$scope.savedEvents.length; i++) {
  63. if ($scope.savedEvents[i]._id === event._id){
  64. $scope.savedEvents.splice(i, 1);
  65. }
  66. }
  67. localStorage.setItem("events_app_savedEvents", JSON.stringify($scope.savedEvents));
  68. $ionicLoading.show({ template: 'Event unsaved', noBackdrop: true, duration: 1000 });
  69. };
  70. $scope.isEventSaved = function(event) {
  71. for(var i=0; i<$scope.savedEvents.length; i++) {
  72. if ($scope.savedEvents[i]._id === event._id){
  73. return true;
  74. }
  75. }
  76. return false;
  77. };
  78. });