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.

50 lines
2.0 KiB

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