ADD редактирование путевых точек
This commit is contained in:
parent
c7a52b19d1
commit
97482ffc15
|
|
@ -47,4 +47,67 @@ class EdittrackController extends Controller
|
|||
$trip->json = '';
|
||||
$trip->save();
|
||||
}
|
||||
|
||||
function actionDeletetrack()
|
||||
{
|
||||
$id = intval(App::getParam('id'));
|
||||
|
||||
$track = Tracks::model()->getByPK($id);
|
||||
if ($track->isEmpty()) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$trip = Trips::model()->getByPK($track->tripId);
|
||||
if ($trip->isEmpty() || $trip->owner != App::$user->id) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$track->delete($id);
|
||||
|
||||
$trip->json = '';
|
||||
$trip->save();
|
||||
|
||||
App::redirect('/tracks/edit/id/'.$trip->id);
|
||||
}
|
||||
|
||||
function actionWaypoint()
|
||||
{
|
||||
$id = intval(App::getParam('id'));
|
||||
|
||||
$waypoint = WayPoints::model()->getByPK($id);
|
||||
if (empty($_POST['name']) || $waypoint->isEmpty()) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$trip = Trips::model()->getByPK($waypoint->tripId);
|
||||
if ($trip->isEmpty() || $trip->owner != App::$user->id) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$waypoint->name = trim($_POST['name']);
|
||||
$waypoint->description = trim($_POST['description']);
|
||||
$waypoint->save();
|
||||
}
|
||||
|
||||
function actionDeletewaypoint()
|
||||
{
|
||||
$id = intval(App::getParam('id'));
|
||||
|
||||
$waypoint = WayPoints::model()->getByPK($id);
|
||||
if ($waypoint->isEmpty()) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$trip = Trips::model()->getByPK($waypoint->tripId);
|
||||
if ($trip->isEmpty() || $trip->owner != App::$user->id) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$waypoint->delete($id);
|
||||
|
||||
$trip->json = '';
|
||||
$trip->save();
|
||||
|
||||
App::redirect('/tracks/edit/id/'.$trip->id);
|
||||
}
|
||||
}
|
||||
|
|
@ -718,17 +718,17 @@ class JsonController extends Controller
|
|||
|
||||
$distance1 = Geo::distance($prevPoint, array('lat' => $trackPoint->lat, 'lng' => $trackPoint->lng));
|
||||
|
||||
if ($distance1 < 100) {
|
||||
if ($distance1 < 30) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$distance2 = Geo::distance($nextPoint, array('lat' => $trackPoint->lat, 'lng' => $trackPoint->lng));
|
||||
$distance3 = Geo::distance($prevPoint, $nextPoint);
|
||||
|
||||
|
||||
if (($distance3 / ($distance1+$distance2)) > 0.982) {
|
||||
continue;
|
||||
}
|
||||
// $distance2 = Geo::distance($nextPoint, array('lat' => $trackPoint->lat, 'lng' => $trackPoint->lng));
|
||||
// $distance3 = Geo::distance($prevPoint, $nextPoint);
|
||||
//
|
||||
//
|
||||
// if (($distance3 / ($distance1+$distance2)) > 0.982) {
|
||||
// continue;
|
||||
// }
|
||||
}
|
||||
|
||||
$prevPoint = $trackPoints[$index];
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class TracksController extends Controller
|
|||
self::render('/tracks/edit.php', array(
|
||||
'trip' => $trip,
|
||||
'tracks' => Tracks::model()->getAll(array('where' => '`tripId` = ' . $trip->id)),
|
||||
'waypoints' => WayPoints::model()->getAll(array('where' => '`tripId` = ' . $trip->id)),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class Trips extends Model
|
|||
return new self();
|
||||
}
|
||||
|
||||
function getDistance()
|
||||
function distance()
|
||||
{
|
||||
return Geo::formatedDistance($this->distance);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ if (App::$user) {
|
|||
<div style="border-bottom: solid 1px #CCC">
|
||||
<input type="checkbox" id="trackShowHide<?= $track->id ?>" onchange="showHideTrack(<?= $track->id ?>)" />
|
||||
<?= $track->name ?>
|
||||
<b><?= $track->getDistance(); ?></b>
|
||||
<b><?= $track->distance(); ?></b>
|
||||
<?php if($track->status == Trips::STATUS_PUBLIC):?>
|
||||
<a href="/?track=<?= $track->id ?>" title="Ссылка на трек. <?="\n"?>[клик правой кнопкой -> копировать адрес]">
|
||||
<span class="glyphicon glyphicon-link" aria-hidden="true"></span>
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@
|
|||
</form>
|
||||
|
||||
<?php if ($tracks): ?>
|
||||
<h3 onclick="$('#tracksBlock').toggle()" style="cursor: pointer;">Фрагменты трека</h3>
|
||||
<div id="tracksBlock" style="">
|
||||
<h3 onclick="$('#tracksBlock').toggle()" style="cursor: pointer;">Фрагменты трека (<?= count($tracks) ?>)</h3>
|
||||
<div id="tracksBlock" style="display: none;">
|
||||
<!--<hr/>-->
|
||||
<?php foreach ($tracks as $track): ?>
|
||||
<form onfocusout="saveChangesTrack(<?= $track->id ?>)" class="form-horizontal">
|
||||
|
|
@ -51,6 +51,32 @@
|
|||
<?php endforeach; ?>
|
||||
<span id="trackSavedOK" style="color: #999; display: none;">изменения сохранены...</span>
|
||||
<span id="trackSavedError" style="color: #900; display: none;">при сохранении возникла ошибка!</span>
|
||||
<br/>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($waypoints): ?>
|
||||
<h3 onclick="$('#waypointsBlock').toggle()" style="cursor: pointer;">Путевые точки (<?= count($waypoints) ?>)</h3>
|
||||
<div id="waypointsBlock" style="display: none;">
|
||||
<!--<hr/>-->
|
||||
<?php foreach ($waypoints as $waypoint): ?>
|
||||
<form onfocusout="saveChangesWaypoint(<?= $waypoint->id ?>)" class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<div class="col-sm-3">
|
||||
<input type="text" class="form-control" id="waypointName<?= $waypoint->id ?>" placeholder="А здесь..." value="<?= $waypoint->name ?>">
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control" id="waypointDescription<?= $waypoint->id ?>" placeholder="Здесь очень..." value="<?= $waypoint->description ?>">
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
<a href="/edittrack/deletewaypoint/id/<?= $waypoint->id ?>" class="btn btn-danger" onclick="return confirm('Вы уверены, что хотите удалить путевую точку?')"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!--<hr/>-->
|
||||
<?php endforeach; ?>
|
||||
<span id="waypointSavedOK" style="color: #999; display: none;">изменения сохранены...</span>
|
||||
<span id="waypointSavedError" style="color: #900; display: none;">при сохранении возникла ошибка!</span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
|
@ -103,4 +129,28 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
function saveChangesWaypoint(id)
|
||||
{
|
||||
$('#waypointSavedOK').hide();
|
||||
$('#waypointSavedError').hide();
|
||||
|
||||
$.ajax({
|
||||
url: "/edittrack/waypoint/id/" + id,
|
||||
method: "POST",
|
||||
data: {
|
||||
name: $('#waypointName' + id).val(),
|
||||
description: $('#waypointDescription' + id).val()
|
||||
},
|
||||
success: function (data) {
|
||||
$('#waypointSavedOK').show();
|
||||
setTimeout(function () {
|
||||
$('#waypointSavedOK').fadeOut(300);
|
||||
}, 2000);
|
||||
},
|
||||
error: function (data) {
|
||||
$('#waypointSavedError').show();
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue