Browse Source

arrayObjectIndexOf, and some details

master
idoctnef 8 years ago
parent
commit
6401e99328
4 changed files with 42 additions and 5 deletions
  1. +4
    -0
      www/css/style.css
  2. +24
    -1
      www/js/controllers.js
  3. +1
    -1
      www/templates/signup.html
  4. +13
    -3
      www/templates/travel.html

+ 4
- 0
www/css/style.css

@ -20,3 +20,7 @@
font-size: 12px;
display: inline-block;
}
.o-img-joined{
width: 20px!important;
height: 20px!important;
}

+ 24
- 1
www/js/controllers.js

@ -69,6 +69,7 @@ angular.module('starter.controllers', [])
localStorage.setItem("c_username", $scope.loginData.username);
localStorage.setItem("c_token", response.data.token);
localStorage.setItem("c_userid", response.data.userid);
localStorage.setItem("c_avatar", response.data.avatar);
}else{
console.log("login failed");
}
@ -109,6 +110,8 @@ angular.module('starter.controllers', [])
$scope.logout = function(){
localStorage.removeItem("c_username");
localStorage.removeItem("c_token");
localStorage.removeItem("c_avatar");
localStorage.removeItem("c_userid");
$window.location.reload(true);
};
})
@ -374,7 +377,8 @@ angular.module('starter.controllers', [])
$scope.newjoin={
travelId: $stateParams.travelId,
joinedUserId: localStorage.getItem("c_userid"),
joinedUsername: localStorage.getItem("c_username")
joinedUsername: localStorage.getItem("c_username"),
joinedAvatar: localStorage.getItem("c_avatar")
};
$http({
url: urlapi + 'travels/join/' + $stateParams.travelId,
@ -391,6 +395,9 @@ angular.module('starter.controllers', [])
// failed
});
};
$scope.unjoinTravel = function(){
console.log("unjoin");
};
/* adding comment */
$scope.doingNewComment=false;
@ -405,6 +412,7 @@ angular.module('starter.controllers', [])
$scope.doNewComment = function() {
$scope.newComment.commentUserId=localStorage.getItem("c_userid");
$scope.newComment.commentUsername=localStorage.getItem("c_username");
$scope.newComment.commentAvatar=localStorage.getItem("c_avatar");
console.log($scope.newComment);
$http({
url: urlapi + 'travels/comment/' + $stateParams.travelId,
@ -425,6 +433,21 @@ console.log($scope.newComment);
});
$scope.closeNewComment();
};
$scope.arrayObjectIndexOf = function(myArray, searchTerm, property) {
if(myArray)
{
for(var i = 0, len = myArray.length; i < len; i++) {
if (myArray[i][property] === searchTerm){
//console.log("i: " + i);
return i;
}
}
}
//console.log("i: -1");
return -1;
}
})
.controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout) {

+ 1
- 1
www/templates/signup.html

@ -2,7 +2,7 @@
<ion-header-bar>
<h1 class="title">Signup</h1>
<div class="buttons">
<button class="button button-dark" ng-click="closeLogin()">Close</button>
<button class="button button-dark" ng-click="closeSignup()">Close</button>
</div>
</ion-header-bar>
<ion-content>

+ 13
- 3
www/templates/travel.html

@ -34,9 +34,17 @@
<div ng-show="storageusername">
<p class='text-right' ng-show="storageusername!==travel.owner">
<div ng-show="arrayObjectIndexOf(joins, storageusername, 'joinedUsername')==-1">
<a ng-show="travel.modality=='offering'" ng-click="joinTravel()" href="#" class="button button-calm o-pull-right">Ask to join</a>
<a ng-show="travel.modality=='asking'" ng-click="joinTravel()" href="#" class="button button-calm o-pull-right">Offer car</a>
<a ng-show="travel.modality=='package'" ng-click="joinTravel()" href="#" class="button button-calm o-pull-right">Offer car</a>
</div>
<div ng-show="arrayObjectIndexOf(joins, storageusername, 'joinedUsername')!=-1">
<a ng-show="travel.modality=='offering'" ng-click="unjoinTravel()" href="#" class="button button-assertive o-pull-right">Unjoin</a>
<a ng-show="travel.modality=='asking'" ng-click="unjoinTravel()" href="#" class="button button-assertive o-pull-right">Unoffer car</a>
<a ng-show="travel.modality=='package'" ng-click="unjoinTravel()" href="#" class="button button-assertive o-pull-right">Unoffer car</a>
</div>
</p>
<p ng-show="storageusername==travel.owner" class="text-right">
<a href="#" ng-click="deleteTravel()" class="button button-assertive o-pull-right">Delete</a>
@ -46,18 +54,20 @@
<div class="item item-body" ng-show="joins[0]">
Joined users:<br>
<a ng-repeat="join in joins" ng-href="#/app/users/{{join.joinedUsername}}" class="button button-small button-dark">
{{join.joinedUsername}}<br>
<img ng-src="img/avatars/{{join.joinedAvatar}}.png" class="o-img-joined" />{{join.joinedUsername}}<br>
</a>
</div>
<div class="item item-body">
<div ng-show="comments[0]">
Comments:<br>
<a ng-repeat="comment in comments" ng-href="#/app/users/{{comment.commentUsername}}" class="item">
<h3>{{comment.commentUsername}}</h3>
<h3><img ng-src="img/avatars/{{comment.commentAvatar}}.png" class="o-img-joined" />{{comment.commentUsername}}</h3>
<p>{{comment.comment}}</p>
</a>
</div>
<a ng-click="showNewComment()" ng-show="!doingNewComment" class="button button-calm right">New comment</a>
<div ng-show="storageusername">
<a ng-click="showNewComment()" ng-show="!doingNewComment" class="button button-calm right">New comment</a>
</div>
<form class="list" ng-show="doingNewComment">
<label class="item item-input item-floating-label">
<span class="input-label">Comment</span>

Loading…
Cancel
Save