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.

72 lines
2.7 KiB

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