jshint and jslint on gpxedit.js

merge-requests/1/head
Julien Veyssier 2017-03-19 14:09:01 -03:00
parent 67fc74f6b0
commit 90e5304b9a
2 changed files with 1376 additions and 1291 deletions

View File

@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- app is now compliant to occ check-code
- jshint and jslint in da place
## 0.0.4 2017-01-17
### Added

View File

@ -43,7 +43,7 @@ var symbolSelectClasses = {
'Contact, Female3': 'contact-female3-select',
'Contact, Cat': 'contact-cat-select',
'Contact, Dog': 'contact-dog-select',
}
};
var symbolIcons = {
'marker': L.divIcon({
@ -161,7 +161,7 @@ var symbolIcons = {
className: 'contact-dog',
iconAnchor: [12, 12]
}),
}
};
var hoverStyle = {
weight: 12,
@ -194,10 +194,10 @@ function load_map() {
// get url from key and layer type
function geopUrl (key, layer, format)
{ return 'http://wxs.ign.fr/'+ key + '/wmts?LAYER=' + layer
+'&EXCEPTIONS=text/xml&FORMAT='+(format?format:'image/jpeg')
+'&SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&STYLE=normal'
+'&TILEMATRIXSET=PM&TILEMATRIX={z}&TILECOL={x}&TILEROW={y}' ;
{ return 'http://wxs.ign.fr/' + key + '/wmts?LAYER=' + layer +
'&EXCEPTIONS=text/xml&FORMAT=' + (format?format:'image/jpeg') +
'&SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&STYLE=normal' +
'&TILEMATRIXSET=PM&TILEMATRIX={z}&TILECOL={x}&TILEROW={y}' ;
}
// change it if you deploy GPXEDIT
var API_KEY = 'ljthe66m795pr2v2g8p7faxt';
@ -374,7 +374,7 @@ function load_map() {
circle: false,
rectangle: false,
marker: {
icon: symbolIcons['marker']
icon: symbolIcons.marker
}
},
edit: {
@ -483,20 +483,27 @@ function onCreated(type, layer){
'<tr><td>' + t('gpxedit', 'Description') + '</td><td><textarea class="layerDesc"></textarea></td></tr>' +
'<tr><td>' + t('gpxedit', 'Comment') + '</td><td><textarea class="layerCmt"></textarea></td></tr>';
if (type === 'marker') {
popupTxt = popupTxt + '<tr><td>'+t('gpxedit', 'Lat')+'</td><td><input class="layerLat"></input></td></tr>';
popupTxt = popupTxt + '<tr><td>'+t('gpxedit', 'Lon')+'</td><td><input class="layerLon"></input></td></tr>';
popupTxt = popupTxt + '<tr><td>'+t('gpxedit', 'Symbol')+'</td><td><select role="symbol">';
popupTxt = popupTxt + '<option value="">'+t('gpxedit', 'No symbol')+'</option>';
popupTxt = popupTxt + '<option value="unknown">'+t('gpxedit', 'Unknown symbol')+'</option>';
popupTxt = popupTxt + '<tr><td>' + t('gpxedit', 'Lat') +
'</td><td><input class="layerLat"></input></td></tr>';
popupTxt = popupTxt + '<tr><td>' + t('gpxedit', 'Lon') +
'</td><td><input class="layerLon"></input></td></tr>';
popupTxt = popupTxt + '<tr><td>' + t('gpxedit', 'Symbol') +
'</td><td><select role="symbol">';
popupTxt = popupTxt + '<option value="">' +
t('gpxedit', 'No symbol') + '</option>';
popupTxt = popupTxt + '<option value="unknown">' +
t('gpxedit', 'Unknown symbol') + '</option>';
for (var cl in symbolIcons) {
if (cl !== 'marker') {
popupTxt = popupTxt + '<option value="'+cl+'">'+cl+'</option>';
popupTxt = popupTxt + '<option value="' + cl + '">' +
cl + '</option>';
}
}
popupTxt = popupTxt + '</select></td></tr>';
}
popupTxt = popupTxt + '</table>';
popupTxt = popupTxt + '<button class="popupOkButton" layerid="'+gpxedit.id+'">OK</button>';
popupTxt = popupTxt + '<button class="popupOkButton" layerid="' +
gpxedit.id + '">OK</button>';
layer.bindPopup(popupTxt);
if (type !== 'marker') {
@ -527,11 +534,9 @@ function getUrlParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam)
{
if (sParameterName[0] === sParam) {
return sParameterName[1];
}
}
@ -539,6 +544,7 @@ function getUrlParameter(sParam)
// generate gpx text from current map elements
function generateGpx() {
var lat, lng, alt, time, i;
var gpxText = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n';
var now = new Date();
var now_utc_str = now.getUTCFullYear() + '-' +
@ -577,9 +583,9 @@ function generateGpx(){
var time = gpxedit.layersData[id].time;
if (layer.type === 'marker') {
var symbol = gpxedit.layersData[id].symbol;
var lat = layer._latlng.lat;
var lng = layer._latlng.lng;
var alt = layer._latlng.alt;
lat = layer._latlng.lat;
lng = layer._latlng.lng;
alt = layer._latlng.alt;
gpxText = gpxText + ' <wpt lat="' + lat + '" lon="' + lng + '">\n';
if (name) {
gpxText = gpxText + ' <name>' + name + '</name>\n';
@ -619,11 +625,11 @@ function generateGpx(){
gpxText = gpxText + ' <desc>' + description + '</desc>\n';
}
gpxText = gpxText + ' <trkseg>\n';
for (var i=0; i<layer._latlngs.length; i++){
var lat = layer._latlngs[i].lat;
var lng = layer._latlngs[i].lng;
var alt = layer._latlngs[i].alt;
var time = layer._latlngs[i].time;
for (i = 0; i < layer._latlngs.length; i++) {
lat = layer._latlngs[i].lat;
lng = layer._latlngs[i].lng;
alt = layer._latlngs[i].alt;
time = layer._latlngs[i].time;
gpxText = gpxText + ' <trkpt lat="' + lat + '" lon="' + lng + '">\n';
if (time) {
gpxText = gpxText + ' <time>' + time + '</time>\n';
@ -649,11 +655,11 @@ function generateGpx(){
if (description) {
gpxText = gpxText + ' <desc>' + description + '</desc>\n';
}
for (var i=0; i<layer._latlngs.length; i++){
var lat = layer._latlngs[i].lat;
var lng = layer._latlngs[i].lng;
var alt = layer._latlngs[i].alt;
var time = layer._latlngs[i].time;
for (i = 0; i < layer._latlngs.length; i++) {
lat = layer._latlngs[i].lat;
lng = layer._latlngs[i].lng;
alt = layer._latlngs[i].alt;
time = layer._latlngs[i].time;
gpxText = gpxText + ' <rtept lat="' + lat + '" lon="' + lng + '">\n';
if (time !== undefined) {
gpxText = gpxText + ' <time>' + time + '</time>\n';
@ -803,6 +809,7 @@ function parseGpx(xml){
// remove layers from map and delete all layers data
function clear() {
var i;
var layersToRemove = [];
gpxedit.editableLayers.eachLayer(function (layer) {
layer.unbindTooltip();
@ -810,7 +817,7 @@ function clear(){
layersToRemove.push(layer);
});
for(var i=0; i<layersToRemove.length; i++){
for(i = 0; i < layersToRemove.length; i++) {
gpxedit.editableLayers.removeLayer(layersToRemove[i]);
}
}
@ -834,7 +841,9 @@ function checkKey(e){
}
function showSaveFailAnimation(path, message) {
$('#failed').find('b#content').html(t('gpxedit', 'Failed to save file')+' '+path+'<br/>'+message);
$('#failed').find('b#content').html(
t('gpxedit', 'Failed to save file') + ' ' + path + '<br/>' + message
);
$('#failed').fadeIn();
setTimeout(hideFailedAnimation, 4000);
}
@ -850,7 +859,9 @@ function hideFailedAnimation(){
}
function showSaveSuccessAnimation(path) {
$('#saved').find('b#content').html(t('gpxedit', 'File successfully saved as')+'<br/>'+path);
$('#saved').find('b#content').html(
t('gpxedit', 'File successfully saved as') + '<br/>' + path
);
$('#saved').fadeIn();
setTimeout(hideSaveSuccessAnimation, 4000);
}
@ -883,15 +894,17 @@ function hideSavingAnimation(){
$('#saving').hide();
}
function loadAction(file) {
if (!endsWith(file, '.gpx') &&
!endsWith(file, '.kml') &&
!endsWith(file, '.jpg') &&
!endsWith(file, '.csv')){
OC.dialogs.alert(t('gpxedit', 'Impossible to load this file. ')+
t('gpxedit', 'Supported formats are gpx, kml, csv (unicsv) and jpg.'),t('gpxedit', 'Load error'));
if ( !endsWith(file, '.gpx')
&& !endsWith(file, '.kml')
&& !endsWith(file, '.jpg')
&& !endsWith(file, '.csv')
) {
OC.dialogs.alert(
t('gpxedit', 'Impossible to load this file. ') +
t('gpxedit', 'Supported formats are gpx, kml, csv (unicsv) and jpg.'),
t('gpxedit', 'Load error')
);
return;
}
@ -900,25 +913,27 @@ function loadAction(file){
var spl = file.split('/');
var basename = spl[spl.length - 1];
$('input#saveName').val(
basename.replace(/\.jpg$/, '.gpx').replace(/\.kml$/, '.gpx').replace(/\.csv$/, '.gpx')
basename.replace(/\.jpg$/, '.gpx')
.replace(/\.kml$/, '.gpx')
.replace(/\.csv$/, '.gpx')
);
}
function loadFile(file) {
var req = {
path: file
}
};
var url = OC.generateUrl('/apps/gpxedit/getgpx');
$('#loadingpc').text('0');
showLoadingAnimation();
gpxedit.currentAjax = $.ajax({
type: "POST",
type: 'POST',
async: true,
url: url,
data: req,
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.addEventListener("progress", function(evt) {
xhr.addEventListener('progress', function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total * 100;
$('#loadingpc').text(parseInt(percentComplete));
@ -932,13 +947,18 @@ function loadFile(file){
clear();
}
if (response.gpx === '') {
OC.dialogs.alert('The file does not exist or it is not supported', 'Load error');
OC.dialogs.alert('The file does not exist or it is not supported',
'Load error');
}
else{
parseGpx(response.gpx);
var bounds = gpxedit.editableLayers.getBounds();
gpxedit.map.fitBounds(bounds,
{animate:true, paddingTopLeft: [parseInt($('#sidebar').css('width')), 0]}
gpxedit.map.fitBounds(
bounds,
{
animate: true,
paddingTopLeft: [parseInt($('#sidebar').css('width')), 0]
}
);
hideLoadingAnimation();
}
@ -949,7 +969,7 @@ function deleteTileServer(li){
var sname = li.attr('name');
var req = {
servername: sname
}
};
var url = OC.generateUrl('/apps/gpxedit/deleteTileServer');
$.ajax({
type: 'POST',
@ -959,7 +979,9 @@ function deleteTileServer(li){
}).done(function (response) {
//alert(response.done);
if (response.done) {
li.fadeOut('slow', function() { li.remove(); });
li.fadeOut('slow', function() {
li.remove();
});
var activeLayerName = gpxedit.activeLayers.getActiveBaseLayer().name;
// if we delete the active layer, first select another
if (activeLayerName === sname) {
@ -967,14 +989,20 @@ function deleteTileServer(li){
}
gpxedit.activeLayers.removeLayer(gpxedit.baseLayers[sname]);
delete gpxedit.baseLayers[sname];
OC.Notification.showTemporary(t('gpxedit', 'Tile server "{ts}" has been deleted', {ts: sname}));
OC.Notification.showTemporary(
t('gpxedit', 'Tile server "{ts}" has been deleted', {ts: sname})
);
}
else{
OC.Notification.showTemporary(t('gpxedit', 'Failure on tile server "{ts}" deletion', {ts: sname}));
OC.Notification.showTemporary(
t('gpxedit', 'Failure on tile server "{ts}" deletion', {ts: sname})
);
}
}).always(function() {
}).fail(function() {
OC.Notification.showTemporary(t('gpxedit', 'Failure on tile server "{ts}" deletion', {ts: sname}));
OC.Notification.showTemporary(
t('gpxedit', 'Failure on tile server "{ts}" deletion', {ts: sname})
);
});
}
@ -982,11 +1010,13 @@ function addTileServer(){
var sname = $('#tileservername').val();
var surl = $('#tileserverurl').val();
if (sname === '' || surl === '') {
OC.dialogs.alert(t('gpxedit','Server name or server url should not be empty'), t('gpxedit','Impossible to add tile server'));
OC.dialogs.alert(t('gpxedit', 'Server name or server url should not be empty'),
t('gpxedit', 'Impossible to add tile server'));
return;
}
if ($('#tileserverlist ul li[name="' + sname + '"]').length > 0) {
OC.dialogs.alert(t('gpxedit','A server with this name already exists'), t('gpxedit','Impossible to add tile server'));
OC.dialogs.alert(t('gpxedit', 'A server with this name already exists'),
t('gpxedit', 'Impossible to add tile server'));
return;
}
$('#tileservername').val('');
@ -995,7 +1025,7 @@ function addTileServer(){
var req = {
servername: sname,
serverurl: surl
}
};
var url = OC.generateUrl('/apps/gpxedit/addTileServer');
$.ajax({
type: 'POST',
@ -1006,25 +1036,37 @@ function addTileServer(){
//alert(response.done);
if (response.done) {
$('#tileserverlist ul').prepend(
'<li style="display:none;" name="'+sname+'" title="'+surl+'">'+sname+' <button>'+
'<li style="display:none;" name="' + sname + '" title="' +
surl + '">' + sname + ' <button>' +
'<i class="fa fa-trash" aria-hidden="true" style="color:red;"></i> ' +
t('gpxedit', 'Delete') + '</button></li>'
);
$('#tileserverlist ul li[name="' + sname + '"]').fadeIn('slow');
// add tile server in leaflet control
var newlayer = new L.TileLayer(surl,
{maxZoom: 18, attribution: 'custom tile server'});
var newlayer = new L.TileLayer(
surl,
{
maxZoom: 18,
attribution: 'custom tile server'
}
);
gpxedit.activeLayers.addBaseLayer(newlayer, sname);
gpxedit.baseLayers[sname] = newlayer;
OC.Notification.showTemporary(t('gpxedit', 'Tile server "{ts}" has been added', {ts: sname}));
OC.Notification.showTemporary(
t('gpxedit', 'Tile server "{ts}" has been added', {ts: sname})
);
}
else{
OC.Notification.showTemporary(t('gpxedit', 'Failure on tile server "{ts}" addition', {ts: sname}));
OC.Notification.showTemporary(
t('gpxedit', 'Failure on tile server "{ts}" addition', {ts: sname})
);
}
}).always(function() {
}).fail(function() {
OC.Notification.showTemporary(t('gpxedit', 'Failure on tile server "{ts}" addition', {ts: sname}));
OC.Notification.showTemporary(
t('gpxedit', 'Failure on tile server "{ts}" addition', {ts: sname})
);
});
}
@ -1043,7 +1085,8 @@ function updateLeafletDrawMarkerStyle(){
$('#markerstyleselect').attr('style',
'background: url(\'' + fullurl + '\') no-repeat ' +
'right 8px center rgba(240, 240, 240, 0.90);' +
'background-size: contain;');
'background-size: contain;'
);
}
var tst = $('#tooltipstyleselect').val();
var theicon = symbolIcons[wst];
@ -1060,7 +1103,9 @@ function updateLeafletDrawMarkerStyle(){
var name = gpxedit.layersData[id].name;
var symbol = gpxedit.layersData[id].symbol;
if (layer.type === 'marker') {
if (symboo && symbol !== '' && symbolIcons.hasOwnProperty(symbol)){
if ( symboo && symbol !== ''
&& symbolIcons.hasOwnProperty(symbol)
) {
layer.setIcon(symbolIcons[symbol]);
}
else{
@ -1082,7 +1127,7 @@ function updateLeafletDrawMarkerStyle(){
function restoreOptions() {
var url = OC.generateUrl('/apps/gpxedit/getOptionsValues');
var req = {
}
};
var optionsValues = '{}';
$.ajax({
type: 'POST',
@ -1093,11 +1138,13 @@ function restoreOptions(){
optionsValues = response.values;
//alert('option values: '+optionsValues);
}).fail(function() {
OC.dialogs.alert(t('gpxedit','failed to restore options values'), t('gpxedit','Error'));
OC.dialogs.alert(t('gpxedit', 'failed to restore options values'),
t('gpxedit', 'Error'));
});
optionsValues = $.parseJSON(optionsValues);
if (optionsValues.markerstyle !== undefined &&
symbolIcons.hasOwnProperty(optionsValues.markerstyle)){
if ( optionsValues.markerstyle !== undefined
&& symbolIcons.hasOwnProperty(optionsValues.markerstyle)
) {
$('#markerstyleselect').val(optionsValues.markerstyle);
}
if (optionsValues.tooltipstyle !== undefined) {
@ -1124,8 +1171,8 @@ function saveOptions(){
//alert('to save: '+JSON.stringify(optionsValues));
var req = {
optionsValues : JSON.stringify(optionsValues),
}
optionsValues: JSON.stringify(optionsValues)
};
var url = OC.generateUrl('/apps/gpxedit/saveOptionsValues');
$.ajax({
type: 'POST',
@ -1135,13 +1182,16 @@ function saveOptions(){
}).done(function (response) {
//alert(response);
}).fail(function() {
OC.dialogs.alert(t('gpxedit','failed to save options values'), t('gpxedit','Error'));
OC.dialogs.alert(t('gpxedit', 'failed to save options values'),
t('gpxedit', 'Error'));
});
}
function fillWaypointStyles() {
for (var st in symbolIcons) {
$('select#markerstyleselect').append('<option value="'+st+'">'+st+'</option>');
$('select#markerstyleselect').append(
'<option value="' + st + '">' + st + '</option>'
);
}
$('select#markerstyleselect').val('marker');
}
@ -1171,7 +1221,7 @@ function saveAction(targetPath){
var req = {
path: saveFilePath,
content: gpxText
}
};
var url = OC.generateUrl('/apps/gpxedit/savegpx');
$.ajax({
type: 'POST',
@ -1180,7 +1230,7 @@ function saveAction(targetPath){
data: req,
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt) {
xhr.upload.addEventListener('progress', function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total * 100;
//Do something with upload progress here
@ -1193,16 +1243,31 @@ function saveAction(targetPath){
}).done(function (response) {
hideSavingAnimation();
if (response.status === 'fiw') {
showSaveFailAnimation(saveFilePath, t('gpxedit', 'Impossible to write file')+' : '+t('gpxedit', 'write access denied'));
showSaveFailAnimation(
saveFilePath,
t('gpxedit', 'Impossible to write file') + ' : ' +
t('gpxedit', 'write access denied')
);
}
else if (response.status === 'fu') {
showSaveFailAnimation(saveFilePath, t('gpxedit', 'Impossible to write file')+' : '+t('gpxedit', 'folder does not exist'));
showSaveFailAnimation(
saveFilePath,
t('gpxedit', 'Impossible to write file') + ' : ' +
t('gpxedit', 'folder does not exist')
);
}
else if (response.status === 'fw') {
showSaveFailAnimation(saveFilePath, t('gpxedit', 'Impossible to write file')+' : '+t('gpxedit', 'folder write access denied'));
showSaveFailAnimation(
saveFilePath,
t('gpxedit', 'Impossible to write file') + ' : ' +
t('gpxedit', 'folder write access denied')
);
}
else if (response.status === 'bfn') {
showSaveFailAnimation(saveFilePath, t('gpxedit', 'Bad file name, must end with ".gpx"'));
showSaveFailAnimation(
saveFilePath,
t('gpxedit', 'Bad file name, must end with ".gpx"')
);
}
else{
showSaveSuccessAnimation(saveFilePath);
@ -1257,8 +1322,10 @@ $(document).ready(function(){
if (symbol === 'unknown') {
// pass
}
else if (symboo && symbol !== '' && symbolIcons.hasOwnProperty(symbol)){
gpxedit.layersData[id].layer.setIcon(symbolIcons[symbol])
else if ( symboo && symbol !== ''
&& symbolIcons.hasOwnProperty(symbol)
) {
gpxedit.layersData[id].layer.setIcon(symbolIcons[symbol]);
}
else{
var theicon = symbolIcons[wst];
@ -1271,10 +1338,16 @@ $(document).ready(function(){
}
if (name !== '') {
if (tst === 'p') {
gpxedit.layersData[id].layer.bindTooltip(name, {permanent:true});
gpxedit.layersData[id].layer.bindTooltip(
name,
{permanent: true}
);
}
else{
gpxedit.layersData[id].layer.bindTooltip(name, {sticky:true});
gpxedit.layersData[id].layer.bindTooltip(
name,
{sticky: true}
);
}
}
@ -1289,9 +1362,15 @@ $(document).ready(function(){
gpxedit.currentAjax.abort();
hideLoadingAnimation();
}
OC.dialogs.filepicker(t('gpxedit', 'Load file (gpx, kml, csv, png)'), function(targetPath) {
OC.dialogs.filepicker(
t('gpxedit', 'Load file (gpx, kml, csv, png)'),
function(targetPath) {
loadAction(targetPath);
}, false, null, true);
},
false,
null,
true
);
});
$('button#saveButton').click(function(e) {
@ -1300,9 +1379,13 @@ $(document).ready(function(){
}
else{
var filename = $('#saveName').val();
OC.dialogs.filepicker(t('gpxedit', 'Where to save')+' <b>'+filename+'</b>', function(targetPath) {
OC.dialogs.filepicker(
t('gpxedit', 'Where to save') + ' <b>' + filename + '</b>',
function(targetPath) {
saveAction(targetPath);
}, false, "httpd/unix-directory", true);
},
false, "httpd/unix-directory", true
);
}
});
@ -1326,7 +1409,8 @@ $(document).ready(function(){
$(this).attr('style',
'background: url(\'' + fullurl + '\') no-repeat ' +
'right 8px center rgba(240, 240, 240, 0.90);' +
'background-size: contain;');
'background-size: contain;'
);
}
});