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; font-size: 12px;
display: inline-block; 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_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); localStorage.setItem("c_userid", response.data.userid);
localStorage.setItem("c_avatar", response.data.avatar);
}else{ }else{
console.log("login failed"); console.log("login failed");
} }
@ -109,6 +110,8 @@ angular.module('starter.controllers', [])
$scope.logout = function(){ $scope.logout = function(){
localStorage.removeItem("c_username"); localStorage.removeItem("c_username");
localStorage.removeItem("c_token"); localStorage.removeItem("c_token");
localStorage.removeItem("c_avatar");
localStorage.removeItem("c_userid");
$window.location.reload(true); $window.location.reload(true);
}; };
}) })
@ -374,7 +377,8 @@ angular.module('starter.controllers', [])
$scope.newjoin={ $scope.newjoin={
travelId: $stateParams.travelId, travelId: $stateParams.travelId,
joinedUserId: localStorage.getItem("c_userid"), joinedUserId: localStorage.getItem("c_userid"),
joinedUsername: localStorage.getItem("c_username")
joinedUsername: localStorage.getItem("c_username"),
joinedAvatar: localStorage.getItem("c_avatar")
}; };
$http({ $http({
url: urlapi + 'travels/join/' + $stateParams.travelId, url: urlapi + 'travels/join/' + $stateParams.travelId,
@ -391,6 +395,9 @@ angular.module('starter.controllers', [])
// failed // failed
}); });
}; };
$scope.unjoinTravel = function(){
console.log("unjoin");
};
/* adding comment */ /* adding comment */
$scope.doingNewComment=false; $scope.doingNewComment=false;
@ -405,6 +412,7 @@ angular.module('starter.controllers', [])
$scope.doNewComment = function() { $scope.doNewComment = function() {
$scope.newComment.commentUserId=localStorage.getItem("c_userid"); $scope.newComment.commentUserId=localStorage.getItem("c_userid");
$scope.newComment.commentUsername=localStorage.getItem("c_username"); $scope.newComment.commentUsername=localStorage.getItem("c_username");
$scope.newComment.commentAvatar=localStorage.getItem("c_avatar");
console.log($scope.newComment); console.log($scope.newComment);
$http({ $http({
url: urlapi + 'travels/comment/' + $stateParams.travelId, url: urlapi + 'travels/comment/' + $stateParams.travelId,
@ -425,6 +433,21 @@ console.log($scope.newComment);
}); });
$scope.closeNewComment(); $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) { .controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout) {

+ 1
- 1
www/templates/signup.html

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

+ 13
- 3
www/templates/travel.html

@ -34,9 +34,17 @@
<div ng-show="storageusername"> <div ng-show="storageusername">
<p class='text-right' ng-show="storageusername!==travel.owner"> <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=='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=='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> <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>
<p ng-show="storageusername==travel.owner" class="text-right"> <p ng-show="storageusername==travel.owner" class="text-right">
<a href="#" ng-click="deleteTravel()" class="button button-assertive o-pull-right">Delete</a> <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]"> <div class="item item-body" ng-show="joins[0]">
Joined users:<br> Joined users:<br>
<a ng-repeat="join in joins" ng-href="#/app/users/{{join.joinedUsername}}" class="button button-small button-dark"> <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> </a>
</div> </div>
<div class="item item-body"> <div class="item item-body">
<div ng-show="comments[0]"> <div ng-show="comments[0]">
Comments:<br> Comments:<br>
<a ng-repeat="comment in comments" ng-href="#/app/users/{{comment.commentUsername}}" class="item"> <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> <p>{{comment.comment}}</p>
</a> </a>
</div> </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"> <form class="list" ng-show="doingNewComment">
<label class="item item-input item-floating-label"> <label class="item item-input item-floating-label">
<span class="input-label">Comment</span> <span class="input-label">Comment</span>

Loading…
Cancel
Save