AJAX добавлене точки
This commit is contained in:
parent
eaf3cb1522
commit
5a00e3e050
|
|
@ -73,13 +73,13 @@ class JsonController extends Controller
|
|||
{
|
||||
$errors = array();
|
||||
|
||||
if(!( isset($_POST['name']) && $_POST['name'] && strlen($_POST['name']) > 1 )) $errors[]='Неверное название точки';
|
||||
if(!( isset($_POST['img']) && $_POST['img'] && strlen($_POST['img']) > 13 )) $errors[]='Плохая ссылка на изображение';
|
||||
if(!( isset($_POST['description']) && $_POST['description'] && strlen($_POST['description']) > 25 )) $errors[]='Слишком короткое описание';
|
||||
if(!( isset($_POST['categoryId']) && $_POST['categoryId'] )) $errors[]='Не задана категория точки';
|
||||
if(!( isset($_POST['source']) )) $errors[]='Не передано поле источкика информации. Допускается пустое значение.';
|
||||
if(!( isset($_POST['lat']) && $_POST['lat'] )) $errors[]='Ошибочное значение широты';
|
||||
if(!( isset($_POST['lng']) && $_POST['lng'] )) $errors[]='Ошибочное значение долготы';
|
||||
if(!( isset($_POST['name']) && $_POST['name'] && strlen($_POST['name']) > 1 )) $errors[1]='Неверное название точки';
|
||||
if(!( isset($_POST['img']) && $_POST['img'] && strlen($_POST['img']) > 13 )) $errors[2]='Плохая ссылка на изображение';
|
||||
if(!( isset($_POST['description']) && $_POST['description'] && strlen($_POST['description']) > 25 )) $errors[3]='Слишком короткое описание';
|
||||
if(!( isset($_POST['categoryId']) && $_POST['categoryId'] )) $errors[4]='Не задана категория точки';
|
||||
if(!( isset($_POST['source']) )) $errors[5]='Не передано поле источкика информации. Допускается пустое значение.';
|
||||
if(!( isset($_POST['lat']) && $_POST['lat'] )) $errors[6]='Ошибочное значение широты';
|
||||
if(!( isset($_POST['lng']) && $_POST['lng'] )) $errors[7]='Ошибочное значение долготы';
|
||||
|
||||
if (empty($errors))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
<button class="btn btn-default" type="button" onclick="showMeOnTheMap()"><span class="glyphicon glyphicon-screenshot"></span> Я на карте</button>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<button class="btn btn-default" type="button" id="addPointButton" onclick="tryAddPoint($(this))"><span class="glyphicon glyphicon-plus-sign"></span> Добавить точку</button>
|
||||
<button class="btn btn-default" type="button" id="addPointButton" onclick="tryAddPoint()"><span class="glyphicon glyphicon-plus-sign"></span> Добавить точку</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
@ -34,21 +34,21 @@
|
|||
<form method="POST" action="/json/addpoint/" id="addPointForm">
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="name">Название</label>
|
||||
<input type="text" id="name" name="name" class="form-control" />
|
||||
<input type="text" id="addPointName" name="name" class="form-control" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="img">URL изображения</label>
|
||||
<input type="text" id="img" name="img" class="form-control" />
|
||||
<input type="text" id="addPointImg" name="img" class="form-control" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="description">Описание</label>
|
||||
<textarea id="description" name="description" class="form-control"></textarea>
|
||||
<textarea id="addPointDescription" name="description" class="form-control"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="categoryId">Тип</label>
|
||||
<select id="categoryId" name="categoryId" class="form-control">
|
||||
<select id="addPointCategoryId" name="categoryId" class="form-control">
|
||||
<?php foreach ($categories as $category): ?>
|
||||
<option value="<?=$category['id']?>"><?=$category['name']?></option>
|
||||
<?php endforeach; ?>
|
||||
|
|
@ -56,17 +56,17 @@
|
|||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="source">Источник</label>
|
||||
<input type="text" id="source" name="source" class="form-control" />
|
||||
<label class="control-label" for="source">Ссылка на источник</label>
|
||||
<input type="text" id="addPointSource" name="source" class="form-control" placeholder="http://" />
|
||||
</div>
|
||||
|
||||
<input type="hidden" id="lat" name="lat" value="'+coords[0].toPrecision(11)+'" />
|
||||
<input type="hidden" id="lng" name="lng" value="'+coords[1].toPrecision(11)+'" />
|
||||
<input type="hidden" id="addPointLat" name="lat" />
|
||||
<input type="hidden" id="addPointLng" name="lng" />
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Отмена</button>
|
||||
<button type="button" class="btn btn-primary" onclick="$('#addPointForm').submit();">Сохранить</button>
|
||||
<button type="button" class="btn btn-primary" onclick="addPoint();">Сохранить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ function init() {
|
|||
if ( $('#addPointButton').hasClass('btn-success') )
|
||||
{
|
||||
coords = e.get('coordPosition');
|
||||
$('#lat').val(coords[0].toPrecision(11));
|
||||
$('#lng').val(coords[1].toPrecision(11));
|
||||
$('#addPointLat').val(coords[0].toPrecision(11));
|
||||
$('#addPointLng').val(coords[1].toPrecision(11));
|
||||
$('#addPointModal').modal('show');
|
||||
}
|
||||
}
|
||||
|
|
@ -92,9 +92,7 @@ function initCategories()
|
|||
$.ajax({
|
||||
url: "/json/categories/",
|
||||
success: function(data){
|
||||
for(var k in data) {
|
||||
categories = categories + '<option value="'+data[k]['id']+'">'+data[k]['name']+'</option>';
|
||||
}
|
||||
categories = data;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -157,11 +155,70 @@ function showMeOnTheMap()
|
|||
});
|
||||
}
|
||||
|
||||
function tryAddPoint(el)
|
||||
function tryAddPoint()
|
||||
{
|
||||
$(el).toggleClass('btn-success').toggleClass('btn-default');
|
||||
$('#addPointButton').toggleClass('btn-success').toggleClass('btn-default');
|
||||
if ( $('#addPointButton').hasClass('btn-success') )
|
||||
myMap.cursors.push('crosshair');
|
||||
else
|
||||
myMap.cursors.push('arrow');
|
||||
}
|
||||
|
||||
function addPoint()
|
||||
{
|
||||
$('.form-group').removeClass('has-error');
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/json/addpoint/",
|
||||
data: {
|
||||
name: $('#addPointName').val(),
|
||||
img: $('#addPointImg').val(),
|
||||
description: $('#addPointDescription').val(),
|
||||
categoryId: $('#addPointCategoryId').val(),
|
||||
source: $('#addPointSource').val(),
|
||||
lat: $('#addPointLat').val(),
|
||||
lng: $('#addPointLng').val()
|
||||
},
|
||||
success: function(data) {
|
||||
id = data;
|
||||
points[id] = new ymaps.Placemark(
|
||||
[$('#addPointLat').val(), $('#addPointLng').val()], {
|
||||
hintContent: $('#addPointName').val(),
|
||||
id: id
|
||||
}, {
|
||||
iconImageHref: categories[$('#addPointCategoryId').val()].icon,
|
||||
iconImageSize: [32, 37],
|
||||
openEmptyBalloon: true,
|
||||
balloonCloseButton: false
|
||||
});
|
||||
|
||||
points[id].events.add('click', function(e) {
|
||||
showInfo(e.get('target').properties.get('id'));
|
||||
});
|
||||
myMap.geoObjects.add(points[id]);
|
||||
$('#addPointModal').modal('hide');
|
||||
$('#addPointButton').toggleClass('btn-success').toggleClass('btn-default');
|
||||
},
|
||||
error: function(data) {
|
||||
response = data.responseJSON;
|
||||
message = '';
|
||||
for (var k in response) {
|
||||
if (typeof response[k] !== 'function') {
|
||||
if (k == 1)
|
||||
$('#addPointName').parent().addClass('has-error');
|
||||
else
|
||||
if (k == 2)
|
||||
$('#addPointImg').parent().addClass('has-error');
|
||||
else
|
||||
if (k == 3)
|
||||
$('#addPointDescription').parent().addClass('has-error');
|
||||
else
|
||||
message += response[k] + '; ';
|
||||
}
|
||||
}
|
||||
|
||||
if (message != '')
|
||||
alert(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue