From ebc4bd02e41cedaa7bf25c221e4d77ec41f67fe7 Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Tue, 14 Jun 2016 11:34:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=BD=D0=B5=D1=81=20=D0=B2=20?= =?UTF-8?q?=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20JS=20?= =?UTF-8?q?=D0=B8=20CSS=20=D0=B2=D1=81=D1=91=20=D0=BF=D0=BE=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8E=20=D1=82=D1=80=D0=B5=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/TracksController.php | 3 + public/css/editTrack.css | 11 +++ public/js/editTrack.js | 143 ++++++++++++++++++++++++++- views/tracks/edit.php | 161 +++---------------------------- 4 files changed, 163 insertions(+), 155 deletions(-) create mode 100644 public/css/editTrack.css diff --git a/controllers/TracksController.php b/controllers/TracksController.php index 16f56dd..947b23f 100644 --- a/controllers/TracksController.php +++ b/controllers/TracksController.php @@ -33,6 +33,9 @@ class TracksController extends Controller self::addScript('/js/leaflet.js'); self::addStyle('/css/leaflet.css'); + self::addScript('/js/editTrack.js'); + self::addStyle('/css/editTrack.css'); + $id = intval(App::getParam('id')); if (!$id) { diff --git a/public/css/editTrack.css b/public/css/editTrack.css new file mode 100644 index 0000000..bff06a7 --- /dev/null +++ b/public/css/editTrack.css @@ -0,0 +1,11 @@ +.savedOK {color: #999; display: none;} +.savedError {color: #900; display: none;} + +.trackpointsContainer {display: none;} +.trackpointsContainer table {height: 500px; width: 100%; margin-bottom: 20px;} +.trackpointsContainer table td {width: 50%;} + +.trackPoint:hover {background-color: #ddd;} + +.trackpointsList {overflow-y: scroll; height: 500px;} +.trackpointsMap {height: 500px;} \ No newline at end of file diff --git a/public/js/editTrack.js b/public/js/editTrack.js index 9facedf..f60b252 100644 --- a/public/js/editTrack.js +++ b/public/js/editTrack.js @@ -1,7 +1,140 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ +var tracks = new Array; +var maps = new Array; +var markers = new Array; +var icon = L.icon({ + iconUrl: '/ico/marker.png', + iconSize: [32, 37], + iconAnchor: [16, 37], + popupAnchor: [0, 1] +}); + +function saveChangesTrip() +{ + $('#tripSavedOK').hide(); + $('#tripSavedError').hide(); + + $.ajax({ + url: "/edittrack/trip/id/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(); + } + }); +} + +function saveChangesTrack(id) +{ + $('#trackSavedOK').hide(); + $('#trackSavedError').hide(); + + $.ajax({ + url: "/edittrack/track/id/" + id, + method: "POST", + data: { + name: $('#trackName' + id).val(), + description: $('#trackDescription' + id).val() + }, + success: function (data) { + $('#trackSavedOK').show(); + setTimeout(function () { + $('#trackSavedOK').fadeOut(300); + }, 2000); + }, + error: function (data) { + $('#trackSavedError').show(); + } + }); +} + +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(); + } + }); +} + +function loadTrackDetails(id) +{ + $('#trackpointsContainer' + id).toggle(); + if ($('#trackpointsMap' + id).text() != '') { + return true; + } + + $.ajax({ + url: "/edittrack/gettrackdetails/id/" + id, + method: "POST", + success: function (data) { + $('#trackpointsList' + id).html(''); + if (typeof (data) != 'undefined') { + latlngs = new Array(); + for (var i = 0; i < data.length; i++) { + $(makeRow(data[i])).appendTo('#trackpointsList' + id); + latlngs.push({lat: data[i]['lat'], lng: data[i]['lng']}) + + } + + maps[id] = L.map('trackpointsMap' + id, {zoomControl: true, scrollWheelZoom: false}).setView([latlngs[0]['lat'], latlngs[0]['lng']], 13); + L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { + attribution: '© OpenStreetMap contributors' + }).addTo(maps[id]); + + tracks[id] = L.polyline(latlngs, {color: '#F00', width: 4, opacity: 0.8}); + maps[id].addLayer(tracks[id]); + + markers[id] = L.marker([latlngs[1]['lat'], latlngs[1]['lng']], {icon: icon}); + maps[id].addLayer(markers[id]) + + maps[id].fitBounds(tracks[id].getBounds()); + } + }, + error: function (data) { + console.log(data); + } + }); +} + +function makeRow(data) +{ + row = '
'; + row += data.lat + ' / ' + data.lng; +// row += data.id + ' - ' + data.lat + ' / ' + data.lng; + row += ' '; + row += '
'; + return row; +} + +function moveMarker(mapId, lat, lng) +{ + markers[mapId].setLatLng([lat, lng]); + maps[mapId].setView([lat, lng], maps[mapId].getZoom()); +} diff --git a/views/tracks/edit.php b/views/tracks/edit.php index 83e2685..0324f2c 100644 --- a/views/tracks/edit.php +++ b/views/tracks/edit.php @@ -26,8 +26,8 @@ $tracksCounter = 1; - - + изменения сохранены... + при сохранении возникла ошибка!
@@ -36,9 +36,9 @@ $tracksCounter = 1; @@ -92,146 +92,7 @@ $tracksCounter = 1; - - + изменения сохранены... + при сохранении возникла ошибка! - -