Merge pull request #82 from owncloud/display-favs
added possibility to show/hide favorites
This commit is contained in:
Коммит
ca07435f49
|
@ -35,5 +35,6 @@ $application->registerRoutes($this, array('routes' => array(
|
|||
array('name' => 'location#load_devices', 'url' => '/api/1.0/location/loadDevices', 'verb' => 'GET'),
|
||||
array('name' => 'location#load_locations', 'url' => '/api/1.0/location/loadLocations', 'verb' => 'GET'),
|
||||
array('name' => 'favorite#add_favorite', 'url' => '/api/1.0/favorite/addToFavorites', 'verb' => 'POST'),
|
||||
array('name' => 'favorite#get_favorites', 'url' => '/api/1.0/favorite/getFavorites', 'verb' => 'POST'),
|
||||
|
||||
)));
|
||||
|
|
|
@ -91,6 +91,16 @@ class FavoriteController extends ApiController {
|
|||
return new JSONResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @return JSONResponse
|
||||
*/
|
||||
public function getFavorites(){
|
||||
$favorites = $this->favoriteMapper->findAll();
|
||||
return new JSONResponse($favorites);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
|
|
|
@ -59,6 +59,10 @@ div#search-icon {
|
|||
background: url('../img/icons/personBackground.png');
|
||||
padding: 4px 5px 13px 4px;
|
||||
}
|
||||
.favorite-icon {
|
||||
background: url('../img/icons/favMarker.png');
|
||||
padding: 4px 5px 13px 4px;
|
||||
}
|
||||
.photo-marker {
|
||||
background: url('../img/icons/personBackground.png');
|
||||
padding: 4px 5px 13px 4px;
|
||||
|
|
45
js/script.js
45
js/script.js
|
@ -289,6 +289,11 @@ Array.prototype.unique = function() {
|
|||
}, function() {
|
||||
//TODO
|
||||
});
|
||||
$('.favoriteLayer').clickToggle(function() {
|
||||
favorites.show();
|
||||
}, function() {
|
||||
favorites.hide();
|
||||
});
|
||||
$('.contactLayer').clickToggle(function() {
|
||||
Maps.loadAdressBooks()
|
||||
}, function() {
|
||||
|
@ -896,10 +901,14 @@ Array.prototype.unique = function() {
|
|||
}
|
||||
|
||||
toolKit = {
|
||||
addMarker : function(marker, markerHTML, openPopup) {
|
||||
addMarker : function(marker, markerHTML, openPopup, fav) {
|
||||
fav = fav || false;
|
||||
var openPopup = (openPopup) ? true : false;
|
||||
var latlng = marker._latlng.lat + ',' + marker._latlng.lng;
|
||||
var markerHTML2 = markerHTML + '<div><a class="setDestination" data-latlng="' + latlng + '">Navigate to here</a> | <a class="addToFav" data-latlng="' + latlng + '">Add to favorites</a></div>';
|
||||
var markerHTML2 = markerHTML + '<div><a class="setDestination" data-latlng="' + latlng + '">Navigate to here</a> | ';
|
||||
if(fav) markerHTML2 += '<a class="remFromFav">Remove from favorites</a>';
|
||||
else markerHTML2 += '<a class="addToFav" data-latlng="' + latlng + '">Add to favorites</a>';
|
||||
markerHTML2 += '</div>';
|
||||
marker.addTo(map).bindPopup(markerHTML2);
|
||||
if (openPopup === true) {
|
||||
setTimeout(function() {
|
||||
|
@ -1174,6 +1183,7 @@ Array.prototype.unique = function() {
|
|||
}
|
||||
|
||||
favorites = {
|
||||
favArray : [],
|
||||
add : function(){
|
||||
var latlng = $(this).attr("data-latlng").split(",");
|
||||
var formData = {
|
||||
|
@ -1181,6 +1191,37 @@ Array.prototype.unique = function() {
|
|||
lng : latlng[1]
|
||||
};
|
||||
$.post(OC.generateUrl('/apps/maps/api/1.0/favorite/addToFavorites'), formData);
|
||||
},
|
||||
show : function(){
|
||||
$.post(OC.generateUrl('/apps/maps/api/1.0/favorite/getFavorites'), null, function(data){
|
||||
for(var i=0; i<data.length; i++){
|
||||
var fav = data[i];
|
||||
|
||||
var imagePath = OC.filePath('maps', 'img', 'icons/favMarker.png');
|
||||
var iconImage = L.icon({
|
||||
iconUrl : imagePath,
|
||||
iconSize : [42, 49],
|
||||
iconAnchor : [21, 49],
|
||||
popupAnchor : [0, -49]
|
||||
});
|
||||
|
||||
var markerHTML = '<b>' + fav.name + " (" + fav.userId + ")</b>";
|
||||
markerHTML += '<br />Latitude: ' + parseFloat(fav.lat).toFixed(3);
|
||||
markerHTML += '<br />Longitude: ' + parseFloat(fav.lng).toFixed(3);
|
||||
markerHTML += '<br />Added: ' + new Date(fav.timestamp*1000).toString();
|
||||
var marker = L.marker([fav.lat, fav.lng], {
|
||||
icon : iconImage
|
||||
});
|
||||
toolKit.addMarker(marker, markerHTML, false, true);
|
||||
favorites.favArray.push(marker);
|
||||
}
|
||||
});
|
||||
},
|
||||
hide : function(){
|
||||
for(var i=0; i<favorites.favArray.length; i++){
|
||||
map.removeLayer(favorites.favArray[i]);
|
||||
}
|
||||
favorites.favArray = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,9 @@
|
|||
<a class='contactLayer icon-contacts-dark' id='contactMenu' data-layer="contacts">Contacts</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<li>
|
||||
<a class='favoriteLayer icon-star' id='favoriteMenu' data-layer="favorites">Favorites</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class='photoLayer icon-link' id='photoMenu' data-layer="photos">Photos</a>
|
||||
</li>
|
||||
|
|
Загрузка…
Ссылка в новой задаче