Browse Source

delete travel and join travel implemented

master
nau 8 years ago
parent
commit
53b9f840fc
2 changed files with 39 additions and 1 deletions
  1. +33
    -1
      www/js/controllers.js
  2. +6
    -0
      www/templates/travel.html

+ 33
- 1
www/js/controllers.js

@ -68,6 +68,7 @@ angular.module('starter.controllers', [])
console.log("login successful"); console.log("login successful");
localStorage.setItem("c_username", $scope.loginData.username); localStorage.setItem("c_username", $scope.loginData.username);
localStorage.setItem("c_token", response.data.token); localStorage.setItem("c_token", response.data.token);
localStorage.setItem("c_userid", response.data.userid);
}else{ }else{
console.log("login failed"); console.log("login failed");
} }
@ -330,8 +331,21 @@ angular.module('starter.controllers', [])
console.log('data error'); console.log('data error');
}) })
.then(function(result){ .then(function(result){
travels = result.data;
travel = result.data;
});
$http.get(urlapi + 'travels/join/'+$stateParams.travelId)
.success(function(data, status, headers,config){
console.log('data success');
console.log(data); // for browser console
$scope.joins = data; // for UI
})
.error(function(data, status, headers,config){
console.log('data error');
})
.then(function(result){
joins = result.data;
}); });
$scope.deleteTravel = function(){ $scope.deleteTravel = function(){
console.log("delete travel: " + $stateParams.travelId); console.log("delete travel: " + $stateParams.travelId);
$http({ $http({
@ -346,7 +360,25 @@ angular.module('starter.controllers', [])
}); });
}; };
$scope.joinTravel = function(){ $scope.joinTravel = function(){
$scope.newjoin={
travelId: $stateParams.travelId,
joinedUserId: localStorage.getItem("c_userid"),
joinedUsername: localStorage.getItem("c_username")
};
$http({
url: urlapi + 'travels/join/' + $stateParams.travelId,
method: "POST",
data: $scope.newjoin
})
.then(function(response) {
// success
console.log("response: ");
console.log(response);
},
function(response) { // optional
// failed
});
}; };
}) })

+ 6
- 0
www/templates/travel.html

@ -43,5 +43,11 @@
</p> </p>
</div> </div>
</div> </div>
<div class="item item-body">
Joined users:<br>
<a ng-repeat="join in joins" ng-href="#/app/users/{{join.joinedUsername}}" class="button button-small button-dark">
{{join.joinedUsername}}<br>
</a>
</div>
</ion-content> </ion-content>
</ion-view> </ion-view>

Loading…
Cancel
Save