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.

78 lines
2.8 KiB

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