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.

68 lines
2.6 KiB

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