ADD пока начальная версия редактирования маршрута - название, описание, публичность
This commit is contained in:
parent
77570db7a8
commit
8125659f83
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class EdittrackController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
if (!App::$user->id) {
|
||||||
|
App::redirect('/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function actionTrip()
|
||||||
|
{
|
||||||
|
$id = intval(App::getParam('id'));
|
||||||
|
$trip = Trips::model()->getByPK($id);
|
||||||
|
|
||||||
|
if (empty($_POST['name']) || $trip->isEmpty() || $trip->owner != App::$user->id) {
|
||||||
|
App::error404();
|
||||||
|
}
|
||||||
|
|
||||||
|
$trip->name = trim($_POST['name']);
|
||||||
|
$trip->description = trim($_POST['description']);
|
||||||
|
$trip->status = ($_POST['isPublic'] == 'true') ? Trips::STATUS_PUBLIC : Trips::STATUS_PRIVATE;
|
||||||
|
$trip->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -28,6 +28,26 @@ class TracksController extends Controller
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function actionEdit()
|
||||||
|
{
|
||||||
|
$id = intval(App::getParam('id'));
|
||||||
|
|
||||||
|
if (!$id) {
|
||||||
|
App::error404();
|
||||||
|
}
|
||||||
|
|
||||||
|
$trip = Trips::model()->getByPK($id);
|
||||||
|
|
||||||
|
if ($trip->isEmpty() || $trip->owner != App::$user->id) {
|
||||||
|
App::error404();
|
||||||
|
}
|
||||||
|
|
||||||
|
self::render('/tracks/edit.php', array(
|
||||||
|
'trip' => $trip,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function actionFiles()
|
function actionFiles()
|
||||||
{
|
{
|
||||||
$files = TrackFiles::model()->getAll(array('where' => '`owner` = :owner'), array('owner' => App::$user->id));
|
$files = TrackFiles::model()->getAll(array('where' => '`owner` = :owner'), array('owner' => App::$user->id));
|
||||||
|
|
@ -126,7 +146,7 @@ class TracksController extends Controller
|
||||||
'createdAt' => isset($gpxObject->metadata->time) ? $gpxObject->metadata->time : date('c'),
|
'createdAt' => isset($gpxObject->metadata->time) ? $gpxObject->metadata->time : date('c'),
|
||||||
'owner' => App::$user->id,
|
'owner' => App::$user->id,
|
||||||
'distance' => 0,
|
'distance' => 0,
|
||||||
'description' => 'Трек сздан ' . date('d-m-Y H:i') . ' из файла ' . $trackFile->filename,
|
'description' => 'Трек создан ' . date('d-m-Y H:i') . ' из файла ' . $trackFile->filename,
|
||||||
'status' => Trips::STATUS_PRIVATE,
|
'status' => Trips::STATUS_PRIVATE,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -233,7 +253,7 @@ class TracksController extends Controller
|
||||||
'createdAt' => $kml->getTime(),
|
'createdAt' => $kml->getTime(),
|
||||||
'owner' => App::$user->id,
|
'owner' => App::$user->id,
|
||||||
'distance' => 0,
|
'distance' => 0,
|
||||||
'description' => 'Трек сздан ' . date('d-m-Y H:i') . ' из файла ' . $trackFile->filename,
|
'description' => 'Трек создан ' . date('d-m-Y H:i') . ' из файла ' . $trackFile->filename,
|
||||||
'status' => Trips::STATUS_PRIVATE,
|
'status' => Trips::STATUS_PRIVATE,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
<a href="/tracks/" class="btn btn-success pull-right">
|
||||||
|
<span class="glyphicon glyphicon-home" aria-hidden="true"></span>
|
||||||
|
Выйти из редактора
|
||||||
|
</a>
|
||||||
|
<h3>Редактор треков</h3>
|
||||||
|
|
||||||
|
<form onfocusout="saveChangesTrip()">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="tripName">Название трека</label>
|
||||||
|
<input type="text" class="form-control" id="tripName" placeholder="Великолепное путешествие <?= date('Y') ?>" value="<?= $trip->name ?>">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="tripDescription">Описание Трека</label>
|
||||||
|
<input type="text" class="form-control" id="tripDescription" placeholder="Это было незабываемое путешествие!..." value="<?= $trip->description ?>">
|
||||||
|
</div>
|
||||||
|
<a href="/edittrack/delete/id/<?= $trip->id ?>" class="btn btn-danger pull-right" onclick="return confirm('Вы уверены, что хотите удалить трек?')">
|
||||||
|
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
||||||
|
Удалить трек
|
||||||
|
</a>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="tripIsPublic" <?= ($trip->status == Trips::STATUS_PUBLIC) ? 'checked="checked"' : '' ?>> Публичный трек (его могут видеть другие пользователи)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span id="tripSavedOK" style="color: #999; display: none;">изменения сохранены...</span>
|
||||||
|
<span id="tripSavedError" style="color: #900; display: none;">при сохранении возникла ошибка!</span>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
<script lang="javascript">
|
||||||
|
function saveChangesTrip()
|
||||||
|
{
|
||||||
|
$('#tripSavedOK').hide();
|
||||||
|
$('#tripSavedError').hide();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "/edittrack/trip/id/<?= $trip->id ?>",
|
||||||
|
method: "POST",
|
||||||
|
data: {
|
||||||
|
name: $('#tripName').val(),
|
||||||
|
description: $('#tripDescription').val(),
|
||||||
|
isPublic: $('#tripIsPublic').prop('checked')
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
$('#tripSavedOK').show();
|
||||||
|
setTimeout(function () {
|
||||||
|
$('#tripSavedOK').fadeOut(300);
|
||||||
|
}, 2000);
|
||||||
|
},
|
||||||
|
error: function (data) {
|
||||||
|
$('#tripSavedError').show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
@ -22,7 +22,11 @@
|
||||||
if ($trips) {
|
if ($trips) {
|
||||||
foreach ($trips as $trip):
|
foreach ($trips as $trip):
|
||||||
?>
|
?>
|
||||||
<?= $trip->id ?> — <a href="/?track=<?= $trip->id ?>"><?= $trip->name ?></a> (<?= $trip->createdAt ?>)
|
<a href="/tracks/edit/id/<?= $trip->id ?>" class="btn btn-default">
|
||||||
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true" title="Редактировать трек"></span>
|
||||||
|
</a>
|
||||||
|
<?= $trip->id ?> —
|
||||||
|
<a href="/?track=<?= $trip->id ?>"><?= $trip->name ?></a> (<?= $trip->createdAt ?>)
|
||||||
<?php if($trip->status == Trips::STATUS_PUBLIC):?>
|
<?php if($trip->status == Trips::STATUS_PUBLIC):?>
|
||||||
<span class="glyphicon glyphicon-eye-open" style="color: #aaa;" aria-hidden="true" title="Публичный трек. Его могут видеть другие пользователи."></span>
|
<span class="glyphicon glyphicon-eye-open" style="color: #aaa;" aria-hidden="true" title="Публичный трек. Его могут видеть другие пользователи."></span>
|
||||||
<?php endif;?>
|
<?php endif;?>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue