mirror of
https://github.com/arnaucube/commonroutesApp.git
synced 2026-02-07 03:26:44 +01:00
added travel edit, added link to web view of travels, fixed travel delete button
This commit is contained in:
@@ -23,6 +23,7 @@ angular.module('starter', [
|
||||
'app.search',
|
||||
'app.travels',
|
||||
'app.travel',
|
||||
'app.editTravel',
|
||||
'app.newTravel',
|
||||
'app.offerCar',
|
||||
'app.askForCar',
|
||||
@@ -120,7 +121,15 @@ angular.module('starter', [
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
.state('app.editTravel', {
|
||||
url: '/editTravel/:travelid',
|
||||
views: {
|
||||
'menuContent': {
|
||||
templateUrl: 'templates/editTravel.html',
|
||||
controller: 'EditTravelCtrl'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('app.newTravel', {
|
||||
url: '/newTravel',
|
||||
views: {
|
||||
|
||||
103
www/js/editTravel.js
Normal file
103
www/js/editTravel.js
Normal file
@@ -0,0 +1,103 @@
|
||||
angular.module('app.editTravel', ['pascalprecht.translate', 'ui-leaflet'])
|
||||
|
||||
.controller('EditTravelCtrl', function($scope, $stateParams, $translate,
|
||||
$http, $filter, $ionicLoading) {
|
||||
$scope.center = {};
|
||||
$scope.bounds = {};
|
||||
$scope.markers = [];
|
||||
$scope.tiles= {
|
||||
url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||
options: {
|
||||
attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
}
|
||||
};
|
||||
$scope.travel={};
|
||||
// get the travel
|
||||
$http.get(urlapi + 'travels/id/' + $stateParams.travelid)
|
||||
.then(function(data) {
|
||||
console.log('data success travels');
|
||||
console.log(data); // for browser console
|
||||
$scope.travel = data.data; // for UI
|
||||
$scope.travel.date = new Date($scope.travel.date);
|
||||
$scope.markers = [];
|
||||
$scope.markers.push({
|
||||
lat: Number($scope.travel.from.lat),
|
||||
lng: Number($scope.travel.from.long),
|
||||
message: $scope.travel.from.name
|
||||
});
|
||||
$scope.markers.push({
|
||||
lat: Number($scope.travel.to.lat),
|
||||
lng: Number($scope.travel.to.long),
|
||||
message: $scope.travel.to.name
|
||||
});
|
||||
$scope.center = {
|
||||
lat: (Number($scope.travel.from.lat) + Number($scope.travel.to.lat)) / 2,
|
||||
lng: (Number($scope.travel.from.long) + Number($scope.travel.to.long)) / 2,
|
||||
zoom: 4
|
||||
};
|
||||
$scope.$broadcast('scroll.refreshComplete'); //refresher stop
|
||||
}, function(data) {
|
||||
console.log('data error');
|
||||
$scope.$broadcast('scroll.refreshComplete'); //refresher stop
|
||||
$ionicLoading.show({
|
||||
template: 'Error connecting server',
|
||||
noBackdrop: true,
|
||||
duration: 2000
|
||||
});
|
||||
});
|
||||
|
||||
$scope.updateTravel =function(){
|
||||
$http({
|
||||
url: urlapi + 'travels/id/modify/' + $scope.travel._id,
|
||||
method: "PUT",
|
||||
data: $scope.travel
|
||||
})
|
||||
.then(function(data) {
|
||||
console.log(data);
|
||||
|
||||
window.location="#app/travels/" + $scope.travel._id;
|
||||
},
|
||||
function(data) { // optional
|
||||
// failed
|
||||
console.log(data);
|
||||
$ionicLoading.show({ template: 'Error updating travel. ' + data.data, noBackdrop: true, duration: 2000 });
|
||||
|
||||
});
|
||||
};
|
||||
$scope.getGeo = function(){
|
||||
|
||||
$scope.markers=[];
|
||||
console.log($scope.travel.from.name);
|
||||
console.log($scope.travel.to.name);
|
||||
$http.get('https://nominatim.openstreetmap.org/search?q=' + $scope.travel.from.name + '&format=json&limit=1')
|
||||
.then(function(data) {
|
||||
console.log(data);
|
||||
if(data.data[0])
|
||||
{
|
||||
$scope.travel.from.lat=data.data[0].lat;
|
||||
$scope.travel.from.long=data.data[0].lon;
|
||||
$scope.travel.from.name=data.data[0].display_name;
|
||||
$scope.markers.push({
|
||||
lat: Number(data.data[0].lat),
|
||||
lng: Number(data.data[0].lon),
|
||||
message: data.data[0].display_name
|
||||
});
|
||||
}
|
||||
$http.get('https://nominatim.openstreetmap.org/search?q=' + $scope.travel.to.name + '&format=json&limit=1')
|
||||
.then(function(data) {
|
||||
if(data.data[0])
|
||||
{
|
||||
$scope.travel.to.lat=data.data[0].lat;
|
||||
$scope.travel.to.long=data.data[0].lon;
|
||||
$scope.travel.to.name=data.data[0].display_name;
|
||||
$scope.markers.push({
|
||||
lat: Number(data.data[0].lat),
|
||||
lng: Number(data.data[0].lon),
|
||||
message: data.data[0].display_name
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
});
|
||||
@@ -285,6 +285,10 @@ angular.module('app.travel', ['pascalprecht.translate', 'ui-leaflet'])
|
||||
//console.log("i: -1");
|
||||
return -1;
|
||||
};
|
||||
$scope.openTravelLink = function(travelid) {
|
||||
window.open('http://routes.fair.coop/app/#!/travel/' + travelid, '_system', 'location=yes');
|
||||
return false;
|
||||
};
|
||||
$scope.openTelegram = function(telegramuser) {
|
||||
window.open('http://telegram.me/' + telegramuser, '_system', 'location=yes');
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user