@ -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 |
|||
}); |
|||
} |
|||
}); |
|||
}); |
|||
|
|||
}; |
|||
}); |
@ -0,0 +1,58 @@ |
|||
<ion-view view-title="{{'Edit Travel' | translate}}"> |
|||
<ion-content> |
|||
<div class="padding"> |
|||
<label class="item item-input"> |
|||
<span class="input-label">{{'Title' | translate}}</span> |
|||
<input type="text" ng-model="travel.title"> |
|||
</label> |
|||
<div layout="row"> |
|||
<label class="item item-input"> |
|||
<span class="input-label">{{'From' | translate}}</span> |
|||
<input type="text" ng-model="travel.from.name"> |
|||
</label> |
|||
<label class="item item-input"> |
|||
<span class="input-label">{{'To' | translate}}</span> |
|||
<input type="text" ng-model="travel.to.name"> |
|||
</label> |
|||
</div> |
|||
</div><!-- end of padding --> |
|||
<a ng-click="getGeo()" ng-show="travel.from.name && travel.to.name" |
|||
class="button o_purple300">{{'Get_positions' | translate}}</a> |
|||
|
|||
<leaflet ng-show="markers[0]" |
|||
width="100%" height="40%" markers="markers" center="center" |
|||
tiles="tiles" id="map-simple-map"></leaflet> |
|||
|
|||
<div class="padding" ng-show="markers[0]"> |
|||
<label class="item item-input" ng-show="travel.seats"> |
|||
<span class="input-label">{{'n_Seats' | translate}}</span> |
|||
<input ng-model="travel.seats" type="number"> |
|||
</label> |
|||
|
|||
<label class="item-input"> |
|||
<span class="input-label">{{'Date' | translate}}</span> |
|||
<input ng-model="travel.date" type="date" placeholder=""> |
|||
</label> |
|||
<label class="item-input"> |
|||
<span class="input-label">{{'Hour' | translate}}</span> |
|||
<input ng-model="travel.date" type="time" placeholder=""> |
|||
</label> |
|||
<ion-toggle ng-show="travel.package" ng-model="travel.package" toggle-class="toggle-calm"> |
|||
<i class="icon ion-ios-box"></i> |
|||
{{'Can_carry_package' | translate}} |
|||
</ion-toggle> |
|||
<ion-toggle ng-show="travel.collectivized" ng-model="travel.collectivized" toggle-class="toggle-calm"> |
|||
{{'Collectivized_car' | translate}} |
|||
</ion-toggle> |
|||
<label class="item item-input"> |
|||
<span class="input-label">{{'Description' | translate}}</span> |
|||
<input type="text" ng-model="travel.description"> |
|||
</label> |
|||
<p class="padding"> |
|||
<a ng-click="updateTravel()" class="button o_purple400 o_floatRight"> |
|||
{{'Update Travel' | translate}} |
|||
</a> |
|||
</p> |
|||
</div><!-- end of padding --> |
|||
</ion-content> |
|||
</ion-view> |