From a78328830a66eda98f856639590b8133b6915ab6 Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Thu, 12 Jun 2014 01:15:37 +0400 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=82=D0=BE=D1=87?= =?UTF-8?q?=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/classes/Controller.php | 7 ++ ground/classes/Model.php | 9 ++ ground/controllers/IndexController.php | 1 + ground/controllers/JsonController.php | 21 +++- ground/views/layout.php | 8 ++ ground/views/modals/addPoint.php | 3 +- public/js/main.js | 127 ++++++++++++++++++++++--- 7 files changed, 162 insertions(+), 14 deletions(-) diff --git a/ground/classes/Controller.php b/ground/classes/Controller.php index c4d6cd7..f6e9c4e 100644 --- a/ground/classes/Controller.php +++ b/ground/classes/Controller.php @@ -6,6 +6,7 @@ abstract class Controller static $layout = 'layout.php'; static private $styles = array(); static private $scripts = array(); + static private $vars = array(); static function addStyle($name) @@ -24,6 +25,11 @@ abstract class Controller } } + static function addVar($name, $value) + { + self::$vars[$name] = $value; + } + /** * Рендерит шаблон без лейаута. * @param string $template - имя шаблона @@ -75,6 +81,7 @@ abstract class Controller 'content' => $content, 'styles' => self::$styles, 'scripts' => self::$scripts, + 'vars' => self::$vars, 'data' => $data, ), true); diff --git a/ground/classes/Model.php b/ground/classes/Model.php index fcc1004..6340f97 100644 --- a/ground/classes/Model.php +++ b/ground/classes/Model.php @@ -100,6 +100,15 @@ class Model } } + /** + * Устанавливает значения полей из массива. + * @param array $values - ассоциативный массив со значениями. + */ + function setValues($values) + { + $this->_vals_ = $values; + } + /** * Сохраняет объект в БД. * @return object/boolean diff --git a/ground/controllers/IndexController.php b/ground/controllers/IndexController.php index 09c24ff..e64cb97 100644 --- a/ground/controllers/IndexController.php +++ b/ground/controllers/IndexController.php @@ -29,6 +29,7 @@ class IndexController extends Controller $routes = $routes->getByAuthor(App::$user->id); } + self::addVar('isAdmin', (int)(App::$user && App::$user->isAdmin == 1) ); $res = App::$DB->query("SELECT COUNT(`id`) pointsCount FROM `points`")->fetch(PDO::FETCH_ASSOC); App::setConfig('title', $res['pointsCount'].' или даже больше поводов не сидеть дома'); diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php index 36d7470..e6898c6 100644 --- a/ground/controllers/JsonController.php +++ b/ground/controllers/JsonController.php @@ -39,7 +39,7 @@ class JsonController extends Controller { $point = new Point(); $point = $point->getByPK($id); - $point->description = nl2br($point->description); + $point->descriptionHtml = nl2br($point->description); $categories = new Category(); $categories = $categories->getAll(); @@ -82,11 +82,30 @@ class JsonController extends Controller if(!( isset($_POST['lat']) && $_POST['lat'] )) $errors[6]='Ошибочное значение широты'; if(!( isset($_POST['lng']) && $_POST['lng'] )) $errors[7]='Ошибочное значение долготы'; if(!App::$user ) $errors[8]='Вы не авторизованы! Пожалуйста, войдите.'; + if(isset($_POST['id']) && $_POST['id'] && App::$user->isAdmin == 0 ) $errors[9]='Редактирование точек достурно только администратору!'; if (empty($errors)) { $point = new Point(); + + // Редактирование существующей точки + if (isset($_POST['id']) && $_POST['id']) + { + + $id = $_POST['id']; + $point = $point->getByPK($id); + + $point->setValues($_POST); + $point->save(); + + self::renderPartial('json.php', array( + 'data' => $point->id + )); + + die; + } + $_POST['author'] = App::$user->id; $_POST['date'] = time(); $point->add($_POST); diff --git a/ground/views/layout.php b/ground/views/layout.php index 557a260..29a051d 100644 --- a/ground/views/layout.php +++ b/ground/views/layout.php @@ -15,6 +15,14 @@ + + + +
diff --git a/ground/views/modals/addPoint.php b/ground/views/modals/addPoint.php index 16e5f39..c30efc8 100644 --- a/ground/views/modals/addPoint.php +++ b/ground/views/modals/addPoint.php @@ -5,7 +5,7 @@
- '; points[id].properties.set('balloonContent', description); point = getURLParameter('point'); @@ -262,23 +325,30 @@ function activateAddPoint() { $('#addPointButton').toggleClass('btn-success').toggleClass('btn-default'); if ($('#addPointButton').hasClass('btn-success')) + { myMap.cursors.push('crosshair'); + setStatus(statusHunting) + } else + { myMap.cursors.push('arrow'); + setStatus(statusReady) + } return true; } /** - * Отправляет данные по новой точке на сервер. + * Отправляет данные о точке на сервер. * @returns {Boolean} */ function addPoint() { $('.form-group').removeClass('has-error'); - if (!addPointInProcess) + if (status != statusSendingToServer) { - addPointInProcess = true; + setStatus(statusSendingToServer) + id = $('#addPointId').length ? $('#addPointId').val() : 0; $.ajax({ type: "POST", url: "/json/addpoint/", @@ -289,13 +359,20 @@ function addPoint() categoryId: $('#addPointCategoryId').val(), source: $('#addPointSource').val(), lat: $('#addPointLat').val(), - lng: $('#addPointLng').val() + lng: $('#addPointLng').val(), + id: id }, success: function(data) { - balloon = myMap.balloon.open([$('#addPointLat').val(), $('#addPointLng').val()], {content: 'Точка успешно добавлена!'}, {closeButton: false}); + text = id ? 'Точка успешно отредактирована!' : 'Точка успешно добавлена!'; + if ( id ) + { + myMap.geoObjects.remove(points[id]); + } + + balloon = myMap.balloon.open([$('#addPointLat').val(), $('#addPointLng').val()], {content: text}, {closeButton: false}); setTimeout(function() { balloon.close(); - }, 3000); + }, 2000); obj = {}; obj.id = data; @@ -315,9 +392,10 @@ function addPoint() $('#addPointForm textarea').val(''); $('.form-group').removeClass('has-error'); $('#addPointButton').removeClass('btn-success').addClass('btn-default'); + $('#addPointId').remove(); myMap.cursors.push('arrow'); + setStatus(statusReady); - addPointInProcess = false; return true; }, error: function(data) { @@ -341,7 +419,7 @@ function addPoint() if (message != '') alert(message); - addPointInProcess = false; + resetStatus(); return false; } }); @@ -499,3 +577,28 @@ function routeToURL() return true; } + +function editPoint(id) +{ + $('#addPointId').remove(); + $('').appendTo('#addPointForm').val(id); + $('#addPointName').val(pointsSources[id].name); + $('#addPointImg').val(pointsSources[id].img); + $('#addPointDescription').val(pointsSources[id].description); + $("#addPointCategoryId option" ).attr('selected', null); + $("#addPointCategoryId option[value='"+pointsSources[id].categoryId+"']" ).attr('selected', 'selected'); + $('#addPointSource').val(pointsSources[id].source); + $('#addPointLat').val(pointsSources[id].lat); + $('#addPointLng').val(pointsSources[id].lng); + + myMap.balloon.close(); + $('#addPointModal').modal('show'); + setStatus(statusEdit); +} + +function editSetNewCoords() +{ + $('#addPointModal').modal('hide'); + myMap.cursors.push('crosshair'); + setStatus(statusReHunting) +}