|
| 1 | +zenergyApp.controller("myEventsPageController", ["$scope", "$http", "tokenService", "$window", "$location", function ($scope, $http, tokenService, $window, $location) { |
| 2 | + |
| 3 | + $scope.pastevent = false; |
| 4 | + //date format |
| 5 | + var today = new Date(); |
| 6 | + $scope.dateSelected = today.getMonth() + 1 + "/" + today.getDate() + "/" + today.getFullYear(); |
| 7 | + |
| 8 | + $scope.formatDate = function (today) { |
| 9 | + function pad(n) { |
| 10 | + return n < 10 ? '0' + n : n; |
| 11 | + } |
| 12 | + return today && today.getMonth() + 1 + "/" + today.getDate() + "/" + today.getFullYear(); |
| 13 | + }; |
| 14 | + |
| 15 | + //initialize array of events |
| 16 | + $scope.events = []; |
| 17 | + |
| 18 | + //DateTime.Now.ToString("dd-MM-yyyy") |
| 19 | + |
| 20 | + //function get ponctual event |
| 21 | + $scope.getEvent = function () { |
| 22 | + $scope.events = []; |
| 23 | + var responseEvent = $http({ |
| 24 | + url: '/api/users/' + tokenService.getUserId() + '/events', |
| 25 | + method: 'GET', |
| 26 | + headers: { |
| 27 | + 'Content-Type': 'application/json' |
| 28 | + } |
| 29 | + }).then(function successCallback(responseEvent) { |
| 30 | + console.log(responseEvent); |
| 31 | + |
| 32 | + //var for displaying or not the join button |
| 33 | + if (new Date($scope.dateSelected) < today) { |
| 34 | + $scope.pastevent = true; |
| 35 | + } |
| 36 | + else { |
| 37 | + $scope.pastevent = false; |
| 38 | + } |
| 39 | + for (var e in responseEvent.data) { |
| 40 | + |
| 41 | + var date = new Date(responseEvent.data[e].ponctualEvent.eventDate); |
| 42 | + date = date.getMonth() + 1 + "/" + date.getDate() + "/" + date.getFullYear(); |
| 43 | + |
| 44 | + // add this event to the list if it's current date |
| 45 | + if (date == $scope.dateSelected) { |
| 46 | + $scope.events.push({ |
| 47 | + Id: responseEvent.data[e].eventId, |
| 48 | + roomName: responseEvent.data[e].room.roomName, |
| 49 | + Description: responseEvent.data[e].eventDescription, |
| 50 | + timeBegin: responseEvent.data[e].timeBegin, |
| 51 | + duration: responseEvent.data[e].eventDurationHours, |
| 52 | + price: responseEvent.data[e].eventPrice, |
| 53 | + name: responseEvent.data[e].eventName, |
| 54 | + activity: responseEvent.data[e].activity.activityName |
| 55 | + }); |
| 56 | + } |
| 57 | + } |
| 58 | + if ($scope.events.length == 0) { |
| 59 | + bootbox.alert("There is no event for this day"); |
| 60 | + } |
| 61 | + |
| 62 | + }); |
| 63 | + |
| 64 | + }; |
| 65 | + //Register to the event |
| 66 | + $scope.unjoinEvent = function (eventid) { |
| 67 | + // reister to an event |
| 68 | + var responseEvent = $http({ |
| 69 | + url: '/api/users/' + tokenService.getUserId() + '/events/' + eventid + '/registration', |
| 70 | + method: 'DELETE', |
| 71 | + headers: { |
| 72 | + 'Content-Type': 'application/json' |
| 73 | + } |
| 74 | + }).then(function successCallback(responseEvent) { |
| 75 | + bootbox.alert("You're are now unregistered from this event !"); |
| 76 | + }); |
| 77 | + }; |
| 78 | + |
| 79 | + $scope.getEvent(); |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +}]); |
| 84 | + |
0 commit comments