extra symbols accessible in edition

merge-requests/1/head
Julien Veyssier 2016-12-13 03:28:57 +01:00
parent 6d4ae1b23b
commit 3127bee438
3 changed files with 60 additions and 26 deletions

View File

@ -139,36 +139,22 @@ class PageController extends Controller {
$userFolder = \OC::$server->getUserFolder(); $userFolder = \OC::$server->getUserFolder();
$userfolder_path = $userFolder->getPath(); $userfolder_path = $userFolder->getPath();
// DIRS array population
$all = $userFolder->search(".gpx");
$alldirs = Array();
foreach($all as $file){
if ($file->getType() === \OCP\Files\FileInfo::TYPE_FILE and
(
endswith($file->getName(), '.gpx') or
endswith($file->getName(), '.GPX')
)
){
$rel_dir = str_replace($userfolder_path, '', dirname($file->getPath()));
$rel_dir = str_replace('//', '/', $rel_dir);
if ($rel_dir === ''){
$rel_dir = '/';
}
if (!in_array($rel_dir, $alldirs)){
array_push($alldirs, $rel_dir);
}
}
}
$tss = $this->getUserTileServers(); $tss = $this->getUserTileServers();
// extra symbols
$dataDirPath = $this->config->getSystemValue('datadirectory').'/gpxedit';
$extraSymbolList = Array();
foreach(globRecursive($dataDirPath.'/symbols', '*.png', False) as $symbolfile){
$filename = basename($symbolfile);
array_push($extraSymbolList, Array('smallname'=>str_replace('.png', '', $filename), 'name'=>$filename));
}
// PARAMS to view // PARAMS to view
sort($alldirs);
$params = [ $params = [
'dirs'=>$alldirs,
'username'=>$this->userId, 'username'=>$this->userId,
'tileservers'=>$tss, 'tileservers'=>$tss,
'extrasymbols'=>$extraSymbolList,
'gpxedit_version'=>$this->appVersion 'gpxedit_version'=>$this->appVersion
]; ];
$response = new TemplateResponse('gpxedit', 'main', $params); $response = new TemplateResponse('gpxedit', 'main', $params);

View File

@ -904,7 +904,18 @@ function updateLeafletDrawMarkerStyle(){
var wst = $('#markerstyleselect').val(); var wst = $('#markerstyleselect').val();
var theclass = symbolSelectClasses[wst]; var theclass = symbolSelectClasses[wst];
$('#markerstyleselect').removeClass($('#markerstyleselect').attr('class')); $('#markerstyleselect').removeClass($('#markerstyleselect').attr('class'));
$('#markerstyleselect').attr('style','');
if (theclass){
$('#markerstyleselect').addClass(theclass); $('#markerstyleselect').addClass(theclass);
}
else if (wst !== ''){
var url = OC.generateUrl('/apps/gpxedit/getExtraSymbol?');
var fullurl = url+'name='+encodeURI(wst+'.png');
$('#markerstyleselect').attr('style',
'background: url(\''+fullurl+'\') no-repeat '+
'right 8px center rgba(240, 240, 240, 0.90);'+
'background-size: 24px 24px;');
}
var tst = $('#tooltipstyleselect').val(); var tst = $('#tooltipstyleselect').val();
var theicon = symbolIcons[wst]; var theicon = symbolIcons[wst];
@ -956,7 +967,8 @@ function restoreOptions(){
alert('failed to restore options values'); alert('failed to restore options values');
}); });
optionsValues = $.parseJSON(optionsValues); optionsValues = $.parseJSON(optionsValues);
if (optionsValues.markerstyle !== undefined){ if (optionsValues.markerstyle !== undefined &&
symbolIcons.hasOwnProperty(optionsValues.markerstyle)){
$('#markerstyleselect').val(optionsValues.markerstyle); $('#markerstyleselect').val(optionsValues.markerstyle);
} }
if (optionsValues.tooltipstyle !== undefined){ if (optionsValues.tooltipstyle !== undefined){
@ -1010,10 +1022,26 @@ function updateSavePath(){
$('#savePath').val(dir+'/'+filename); $('#savePath').val(dir+'/'+filename);
} }
function addExtraSymbols(){
var url = OC.generateUrl('/apps/gpxedit/getExtraSymbol?');
$('ul#extrasymbols li').each(function(){
var name = $(this).attr('name');
var smallname = $(this).html();
var fullurl = url+'name='+encodeURI(name);
var d = L.icon({
iconUrl: fullurl,
iconSize: L.point(24, 24),
iconAnchor: [12, 12]
});
symbolIcons[smallname] = d;
});
}
$(document).ready(function(){ $(document).ready(function(){
gpxedit.username = $('p#username').html(); gpxedit.username = $('p#username').html();
load_map(); load_map();
document.onkeydown = checkKey; document.onkeydown = checkKey;
addExtraSymbols();
fillWaypointStyles(); fillWaypointStyles();
restoreOptions(); restoreOptions();
@ -1173,7 +1201,18 @@ $(document).ready(function(){
$('body').on('change', 'select[role=symbol]', function() { $('body').on('change', 'select[role=symbol]', function() {
$(this).removeClass($(this).attr('class')); $(this).removeClass($(this).attr('class'));
$(this).attr('style','');
if (symbolSelectClasses.hasOwnProperty($(this).val())){
$(this).addClass(symbolSelectClasses[$(this).val()]); $(this).addClass(symbolSelectClasses[$(this).val()]);
}
else if ($(this).val() !== ''){
var url = OC.generateUrl('/apps/gpxedit/getExtraSymbol?');
var fullurl = url+'name='+encodeURI($(this).val()+'.png');
$(this).attr('style',
'background: url(\''+fullurl+'\') no-repeat '+
'right 8px center rgba(240, 240, 240, 0.90);'+
'background-size: 24px 24px;');
}
}); });
// load a file if 'file' GET url parameter was given // load a file if 'file' GET url parameter was given

View File

@ -72,6 +72,15 @@ p($_['gpxedit_version']);
echo '<p id="username" style="display:none">'; echo '<p id="username" style="display:none">';
p($_['username']); p($_['username']);
echo '</p>'."\n"; echo '</p>'."\n";
echo '<ul id="extrasymbols" style="display:none">';
foreach($_['extrasymbols'] as $symbol){
echo '<li name="';
p($symbol['name']);
echo '">';
p($symbol['smallname']);
echo '</li>';
}
echo '</ul>'."\n";
?> ?>
</div> </div>