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.

49 lines
1.9 KiB

  1. angular.module('app.savedEvents', ['pascalprecht.translate'])
  2. .controller('SavedEventsCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading, $filter) {
  3. $scope.share = function(event){
  4. var message = event.description;
  5. var subject = event.title;
  6. var file= ['',''];
  7. var link = "http://duckduckgo.com";
  8. $cordovaSocialSharing
  9. .share(message, subject, file, link) // Share via native share sheet
  10. .then(function(result) {
  11. // Success!
  12. }, function(err) {
  13. // An error occured. Show a message to the user
  14. });
  15. };
  16. $scope.$on('$ionicView.enter', function(){//per executar-ho cada cop que es carrega el view
  17. $scope.savedEvents=[];
  18. if (localStorage.getItem("events_app_savedEvents")) {
  19. $scope.savedEvents = JSON.parse(localStorage.getItem("events_app_savedEvents"));
  20. console.log("savedEvents");
  21. console.log($scope.savedEvents);
  22. }
  23. $scope.events=$scope.savedEvents;
  24. });
  25. $scope.saveEvent = function(event){
  26. $scope.savedEvents.push(event);
  27. localStorage.setItem("events_app_savedEvents", JSON.stringify($scope.savedEvents));
  28. $ionicLoading.show({ template: 'Event saved', noBackdrop: true, duration: 1000 });
  29. };
  30. $scope.unsaveEvent = function(event){
  31. for(var i=0; i<$scope.savedEvents.length; i++) {
  32. if ($scope.savedEvents[i]._id === event._id){
  33. $scope.savedEvents.splice(i, 1);
  34. }
  35. }
  36. localStorage.setItem("events_app_savedEvents", JSON.stringify($scope.savedEvents));
  37. $ionicLoading.show({ template: 'Event unsaved', noBackdrop: true, duration: 1000 });
  38. };
  39. $scope.isEventSaved = function(event) {
  40. for(var i=0; i<$scope.savedEvents.length; i++) {
  41. if ($scope.savedEvents[i]._id === event._id){
  42. return true;
  43. }
  44. }
  45. return false;
  46. };
  47. });