Browse Source

join inside the travel model

master
idoctnef 8 years ago
parent
commit
1810e315a9
2 changed files with 11 additions and 38 deletions
  1. +5
    -32
      www/js/controllers.js
  2. +6
    -6
      www/templates/travel.html

+ 5
- 32
www/js/controllers.js

@ -384,37 +384,10 @@ angular.module('starter.controllers', ['pascalprecht.translate'])
$http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('c_token');
}
$scope.storageusername=localStorage.getItem("c_username");
$scope.travel="";
console.log($stateParams.travelId);
/*$http.get(urlapi + 'travels/'+$stateParams.travelId)
.success(function(data, status, headers,config){
console.log('data success');
console.log(data); // for browser console
$scope.travel = data; // for UI
console.log("b");
console.log($scope.travel);
})
.error(function(data, status, headers,config){
console.log('data error');
})
.then(function(result){
travel = result.data;
});*/
$scope.travels= JSON.parse(localStorage.getItem('c_travels'));
$scope.travel = $filter('filter')($scope.travels, $stateParams.travelId, true)[0];
$scope.joins="";
$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;
});
$http.get(urlapi + 'travels/comment/'+$stateParams.travelId)
.success(function(data, status, headers,config){
console.log(data); // for browser console
@ -456,13 +429,13 @@ angular.module('starter.controllers', ['pascalprecht.translate'])
};
$scope.joinTravel = function(){
$scope.newjoin={
travelId: $stateParams.travelId,
//travelId: $stateParams.travelId,
joinedUserId: localStorage.getItem("c_userid"),
joinedUsername: localStorage.getItem("c_username"),
joinedAvatar: localStorage.getItem("c_avatar")
};
$http({
url: urlapi + 'travels/join/' + $stateParams.travelId,
url: urlapi + 'travels/'+ $stateParams.travelId+'/join',
method: "POST",
data: $scope.newjoin
})
@ -485,7 +458,7 @@ angular.module('starter.controllers', ['pascalprecht.translate'])
joinedAvatar: localStorage.getItem("c_avatar")
};
$http({
url: urlapi + 'travels/unjoin/' + $stateParams.travelId,
url: urlapi + 'travels/'+ $stateParams.travelId+'/unjoin',
method: "POST",
data: $scope.unjoin
})
@ -540,7 +513,7 @@ console.log($scope.newComment);
$scope.arrayObjectIndexOf = function(myArray, searchTerm, property) {
console.log(myArray+", "+searchTerm+", "+property);
//console.log(myArray+", "+searchTerm+", "+property);
if(myArray)
{
for(var i = 0, len = myArray.length; i < len; i++) {

+ 6
- 6
www/templates/travel.html

@ -49,15 +49,15 @@
<br>
<div ng-show="storageusername">
<p class='text-right' ng-show="storageusername!=travel.owner">
<div ng-show="arrayObjectIndexOf(joins, storageusername, 'joinedUsername')==-1">
<div ng-show="storageusername && storageusername!=travel.owner">
<p class='text-right'>
<div ng-show="arrayObjectIndexOf(travel.joins, storageusername, 'joinedUsername')==-1">
<a ng-show="travel.modality=='offering'" ng-click="joinTravel()" href="#" class="button button-calm o-pull-right">{{'Ask_to_join' | translate}}</a>
<a ng-show="travel.modality=='asking'" ng-click="joinTravel()" href="#" class="button button-calm o-pull-right">{{'Offer_car' | translate}}</a>
<a ng-show="travel.modality=='package'" ng-click="joinTravel()" href="#" class="button button-calm o-pull-right">{{'Offer_car' | translate}}</a>
</div>
<div ng-show="arrayObjectIndexOf(joins, storageusername, 'joinedUsername')!=-1">
<div ng-show="arrayObjectIndexOf(travel.joins, storageusername, 'joinedUsername')!=-1">
<a ng-show="travel.modality=='offering'" ng-click="unjoinTravel()" href="#" class="button button-assertive o-pull-right">{{'Unjoin' | translate}}</a>
<a ng-show="travel.modality=='asking'" ng-click="unjoinTravel()" href="#" class="button button-assertive o-pull-right">{{'Unoffer_car' | translate}}</a>
<a ng-show="travel.modality=='package'" ng-click="unjoinTravel()" href="#" class="button button-assertive o-pull-right">{{'Unoffer_car' | translate}}</a>
@ -65,9 +65,9 @@
</p>
</div>
</div>
<div class="item item-body" ng-show="joins[0]">
<div class="item item-body" ng-show="travel.joins[0]">
{{'Joined_users' | translate}}:<br>
<a ng-repeat="join in joins" ng-href="#/app/users/{{join.joinedUsername}}" class="button button-small button-dark">
<a ng-repeat="join in travel.joins" ng-href="#/app/users/{{join.joinedUsername}}" class="button button-small button-dark">
<img ng-src="img/avatars/{{join.joinedAvatar}}.png" class="o-img-joined" />{{join.joinedUsername}}<br>
</a>
</div>

Loading…
Cancel
Save