1
1
zenergyApp . controller ( "ponctualEventCreationPageController" , [ "$scope" , "$http" , "tokenService" , "$window" , "$location" , function ( $scope , $http , tokenService , $window , $location ) {
2
2
3
- // Get activities
4
- var response = $http ( {
5
- url : '/api/activities/findByManagerId/' + tokenService . getUserId ( ) ,
6
- method : 'GET' ,
7
- headers : {
8
- 'Content-Type' : 'application/json'
9
- }
10
- } ) . then ( function successCallback ( response ) {
11
- $scope . hasError = false ;
12
- $scope . activities = [ ] ;
13
- $scope . activities = $ . parseJSON ( JSON . stringify ( response . data ) ) ;
14
- console . log ( $scope . activities ) ;
15
- } ) ;
3
+ if ( $scope . isManager ( ) ) {
4
+ // Get activities
5
+ var response = $http ( {
6
+ url : '/api/activities/findByManagerId/' + tokenService . getUserId ( ) ,
7
+ method : 'GET' ,
8
+ headers : {
9
+ 'Content-Type' : 'application/json'
10
+ }
11
+ } ) . then ( function successCallback ( response ) {
12
+ $scope . hasError = false ;
13
+ $scope . activities = [ ] ;
14
+ $scope . activities = $ . parseJSON ( JSON . stringify ( response . data ) ) ;
15
+ console . log ( $scope . activities ) ;
16
+ } ) ;
16
17
17
- // Get rooms
18
- var response = $http ( {
19
- url : '/api/rooms' ,
20
- method : 'GET' ,
21
- headers : {
22
- 'Content-Type' : 'application/json'
23
- }
24
- } ) . then ( function successCallback ( response ) {
25
- $scope . hasError = false ;
26
- $scope . rooms = [ ] ;
27
- $scope . rooms = $ . parseJSON ( JSON . stringify ( response . data ) ) ;
28
- console . log ( $scope . rooms ) ;
29
- } ) ;
18
+ // Get rooms
19
+ var response = $http ( {
20
+ url : '/api/rooms' ,
21
+ method : 'GET' ,
22
+ headers : {
23
+ 'Content-Type' : 'application/json'
24
+ }
25
+ } ) . then ( function successCallback ( response ) {
26
+ $scope . hasError = false ;
27
+ $scope . rooms = [ ] ;
28
+ $scope . rooms = $ . parseJSON ( JSON . stringify ( response . data ) ) ;
29
+ console . log ( $scope . rooms ) ;
30
+ } ) ;
30
31
31
- $scope . ponctualEvent = { eventId : 1 , eventDate : new Date ( ) , event : { eventId : 1 , roomId : '' , activityId : '' , eventName : '' , eventPrice : '' , eventDurationHours : '' , eventMaxPeople : '' , eventDescription : '' , timeBegin : '' } } ;
32
+ $scope . ponctualEvent = { eventId : 1 , eventDate : new Date ( ) , event : { eventId : 1 , roomId : '' , activityId : '' , eventName : '' , eventPrice : '' , eventDurationHours : '' , eventMaxPeople : '' , eventDescription : '' , timeBegin : '' } } ;
32
33
33
- $scope . createEvent = function ( ) {
34
- //console.log($scope.ponctualEvent);
34
+ $scope . createEvent = function ( ) {
35
+ //console.log($scope.ponctualEvent);
35
36
36
- $scope . hasError = false ;
37
- $scope . dateError = false ;
37
+ $scope . hasError = false ;
38
+ $scope . dateError = false ;
38
39
39
- var today = new Date ( ) ;
40
- if ( $scope . ponctualEvent . eventDate <= today ) {
41
- $scope . hasError = true ;
42
- $scope . dateError = true ;
43
- }
40
+ var today = new Date ( ) ;
41
+ if ( $scope . ponctualEvent . eventDate <= today ) {
42
+ $scope . hasError = true ;
43
+ $scope . dateError = true ;
44
+ }
45
+
46
+ var date = new Date ( $scope . ponctualEvent . event . timeBegin ) ;
47
+ $scope . ponctualEvent . event . timeBegin = date . getHours ( ) . toString ( ) + ":" + date . getMinutes ( ) . toString ( ) ;
44
48
45
- var date = new Date ( $scope . ponctualEvent . event . timeBegin ) ;
46
- $scope . ponctualEvent . event . timeBegin = date . getHours ( ) . toString ( ) + ":" + date . getMinutes ( ) . toString ( ) ;
47
-
48
- $scope . ponctualEvent . event . roomId = document . getElementById ( "roomSelect" ) . value ;
49
- $scope . ponctualEvent . event . activityId = document . getElementById ( "actSelect" ) . value ;
49
+ $scope . ponctualEvent . event . roomId = document . getElementById ( "roomSelect" ) . value ;
50
+ $scope . ponctualEvent . event . activityId = document . getElementById ( "actSelect" ) . value ;
50
51
51
- if ( ! $scope . hasError )
52
- {
53
- var response = $http ( {
54
- url : '/api/ponctualEvents' ,
55
- method : 'POST' ,
56
- data : $scope . ponctualEvent ,
57
- headers : {
58
- 'Content-Type' : 'application/json'
59
- }
60
- } ) . then ( function successCallback ( response ) {
61
- bootbox . alert ( "Your event is now created!" , function ( ) {
62
- $location . path ( "/#/MyEvents" ) ;
52
+ if ( ! $scope . hasError ) {
53
+ var response = $http ( {
54
+ url : '/api/ponctualEvents' ,
55
+ method : 'POST' ,
56
+ data : $scope . ponctualEvent ,
57
+ headers : {
58
+ 'Content-Type' : 'application/json'
59
+ }
60
+ } ) . then ( function successCallback ( response ) {
61
+ bootbox . alert ( "Your event is now created!" , function ( ) {
62
+ $location . path ( "/#/MyEvents" ) ;
63
+ } ) ;
64
+ } , function errorCallback ( response ) {
65
+ bootbox . alert ( "There has been an error during the event creation. Please check your event information." ) ;
63
66
} ) ;
64
- } , function errorCallback ( response ) {
65
- bootbox . alert ( "There has been an error during the event creation. Please check your event information." ) ;
66
- } ) ;
67
+ }
67
68
}
68
69
}
69
70
} ] ) ;
0 commit comments