mirror of
https://github.com/arnaucube/commonroutesWebApp.git
synced 2026-02-07 03:16:41 +01:00
implemented travel join system, added notifications page and to navbar
This commit is contained in:
@@ -3,6 +3,34 @@
|
||||
<div class="col-sm-4">
|
||||
<div ng-include="'views/travelCardTemplate.html'"></div>
|
||||
<br>
|
||||
<div class="panel">
|
||||
<div class="panel-heading c_deepPurpleG500to300">
|
||||
<h3 class="panel-title">Actions</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p class='text-right'>
|
||||
<div ng-show="userHasJoined(travel.joinPetitions, storageuser._id)==-1">
|
||||
<div ng-show="userHasJoined(travel.joins, storageuser._id)==-1">
|
||||
<a ng-show="travel.type=='offering'" ng-click="joinTravel()" class="btn btn-raised c_deepPurple300">Ask to join</a>
|
||||
<a ng-show="travel.type=='asking'" ng-click="joinTravel()" class="btn btn-raised c_deepPurple300">Offer car</a>
|
||||
<a ng-show="travel.type=='package'" ng-click="joinTravel()" class="btn btn-raised c_deepPurple300">Offer car</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-show="userHasJoined(travel.joinPetitions, storageuser._id)>-1">
|
||||
<a ng-show="travel.type=='offering'" ng-click="unjoinTravel()" class="btn btn-raised c_red300">Unjoin</a>
|
||||
<a ng-show="travel.type=='asking'" ng-click="unjoinTravel()" class="btn btn-raised c_red300">Unoffer car</a>
|
||||
<a ng-show="travel.type=='package'" ng-click="unjoinTravel()" class="btn btn-raised c_red300">Unoffer car</a>
|
||||
</div>
|
||||
|
||||
<div ng-show="userHasJoined(travel.joins, storageuser._id)>-1">
|
||||
You are in this travel!
|
||||
<a ng-show="travel.type=='offering'" ng-click="leaveTravel()" class="btn btn-raised c_red300">Leave</a>
|
||||
</div>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="panel">
|
||||
<div class="panel-heading c_deepPurpleG500to300">
|
||||
<h3 class="panel-title">{{travel.joinPetitions.length}} Pendent joins</h3>
|
||||
@@ -50,8 +78,7 @@
|
||||
<h3 class="panel-title">Map</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<leaflet width="100%" height="500px" markers="markers" center="center"
|
||||
tiles="tiles" id="map-simple-map"></leaflet>
|
||||
<leaflet width="100%" height="500px" markers="markers" center="center" tiles="tiles" id="map-simple-map"></leaflet>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,9 @@ angular.module('app.travel', ['ngRoute', 'ui-leaflet'])
|
||||
}])
|
||||
|
||||
.controller('TravelCtrl', function($scope, $http, $routeParams,
|
||||
leafletData, leafletBoundsHelpers) {
|
||||
leafletData, leafletBoundsHelpers, toastr) {
|
||||
|
||||
$scope.storageuser = JSON.parse(localStorage.getItem("cr_webapp_userdata"));
|
||||
$scope.travel = {};
|
||||
|
||||
|
||||
@@ -68,12 +70,141 @@ angular.module('app.travel', ['ngRoute', 'ui-leaflet'])
|
||||
.then(function(data) {
|
||||
console.log(data);
|
||||
$scope.travels = data.data;
|
||||
toastr.info('Travel deleted');
|
||||
|
||||
window.location = "#!/main/";
|
||||
},
|
||||
function(data) { // optional
|
||||
// failed
|
||||
toastr.error('Error on delete travel');
|
||||
});
|
||||
};
|
||||
|
||||
$scope.joinTravel = function() {
|
||||
$http({
|
||||
url: urlapi + 'travels/join/' + $routeParams.travelid,
|
||||
method: "POST",
|
||||
data: {}
|
||||
})
|
||||
.then(function(data) {
|
||||
console.log("data: ");
|
||||
console.log(data);
|
||||
if (data.data.success == false) {
|
||||
toastr.error('Error on join');
|
||||
} else {
|
||||
$scope.travel = data.data;
|
||||
toastr.success('Joined travel');
|
||||
}
|
||||
},
|
||||
function(response) { // optional
|
||||
// failed
|
||||
});
|
||||
};
|
||||
$scope.unjoinTravel = function() {
|
||||
$http({
|
||||
url: urlapi + 'travels/unjoin/' + $routeParams.travelid,
|
||||
method: "POST",
|
||||
data: {}
|
||||
})
|
||||
.then(function(data) {
|
||||
console.log("data: ");
|
||||
console.log(data);
|
||||
if (data.data.success == false) {
|
||||
toastr.error('Error on unjoin');
|
||||
} else {
|
||||
$scope.travel = data.data;
|
||||
toastr.success('Unjoined travel');
|
||||
}
|
||||
},
|
||||
function(response) { // optional
|
||||
// failed
|
||||
});
|
||||
};
|
||||
|
||||
$scope.declineJoin = function(joinPetition) {
|
||||
$http({
|
||||
url: urlapi + 'travels/declineJoin/' + $routeParams.travelid,
|
||||
method: "POST",
|
||||
data: {
|
||||
userid: joinPetition._id
|
||||
}
|
||||
})
|
||||
.then(function(data) {
|
||||
console.log("data: ");
|
||||
console.log(data);
|
||||
if (data.data.success == false) {
|
||||
toastr.error('Error on declining');
|
||||
} else {
|
||||
$scope.travel = data.data;
|
||||
console.log("success");
|
||||
toastr.success('Join declined');
|
||||
}
|
||||
},
|
||||
function(response) { // optional
|
||||
// failed
|
||||
});
|
||||
};
|
||||
|
||||
$scope.acceptJoin = function(joinPetition) {
|
||||
$http({
|
||||
url: urlapi + 'travels/acceptJoin/' + $routeParams.travelid,
|
||||
method: "POST",
|
||||
data: {
|
||||
userid: joinPetition._id
|
||||
}
|
||||
})
|
||||
.then(function(data) {
|
||||
console.log("data: ");
|
||||
console.log(data);
|
||||
if (data.data.success == false) {
|
||||
toastr.error('Error on accepting');
|
||||
} else {
|
||||
$scope.travel = data.data;
|
||||
console.log("success");
|
||||
toastr.success('Join accepted');
|
||||
}
|
||||
},
|
||||
function(response) { // optional
|
||||
// failed
|
||||
});
|
||||
};
|
||||
|
||||
$scope.leaveTravel = function() {
|
||||
|
||||
$http({
|
||||
url: urlapi + 'travels/leave/' + $routeParams.travelid,
|
||||
method: "POST",
|
||||
data: {}
|
||||
})
|
||||
.then(function(data) {
|
||||
console.log("data: ");
|
||||
console.log(data);
|
||||
if (data.data.success == false) {
|
||||
toastr.error('Error on leave');
|
||||
} else {
|
||||
$scope.travel = data.data;
|
||||
toastr.success('Travel leaved');
|
||||
}
|
||||
},
|
||||
function(response) { // optional
|
||||
// failed
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.userHasJoined = function(myArray, searchTerm) {
|
||||
//console.log(myArray+", "+searchTerm);
|
||||
if (myArray) {
|
||||
for (var i = 0, len = myArray.length; i < len; i++) {
|
||||
//console.log(myArray[i] + " - " + searchTerm);
|
||||
if (myArray[i]._id === searchTerm) {
|
||||
//console.log("i: " + i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
//console.log("i: -1");
|
||||
return -1;
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user