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.

70 lines
2.6 KiB

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