closes #7 added automatic save/restore option values from DB

merge-requests/1/head
Julien Veyssier 2016-12-06 17:29:49 +01:00
parent 840406a82e
commit 2783a96f77
3 changed files with 57 additions and 0 deletions

View File

@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
[#4](https://gitlab.com/eneiluj/gpxedit-oc/issues/4) @eneiluj
- option to change marker style and tooltip visibility
[#2](https://gitlab.com/eneiluj/gpxedit-oc/issues/2) @eneiluj
- automatic save/restore options values
[#7](https://gitlab.com/eneiluj/gpxedit-oc/issues/7) @eneiluj
### Fixed
- remove $.parseXML, apparently useless and producing errors

View File

@ -26,5 +26,7 @@ return [
['name' => 'page#getdircontentdir', 'url' => '/getdircontentdir', 'verb' => 'POST'],
['name' => 'utils#addTileServer', 'url' => '/addTileServer', 'verb' => 'POST'],
['name' => 'utils#deleteTileServer', 'url' => '/deleteTileServer', 'verb' => 'POST'],
['name' => 'utils#getOptionsValues', 'url' => '/getOptionsValues', 'verb' => 'POST'],
['name' => 'utils#saveOptionsValues', 'url' => '/saveOptionsValues', 'verb' => 'POST'],
]
];

View File

@ -657,15 +657,68 @@ function updateLeafletDrawMarkerStyle(){
});
}
function restoreOptions(){
var url = OC.generateUrl('/apps/gpxedit/getOptionsValues');
var req = {
}
var optionsValues = '{}';
$.ajax({
type: 'POST',
url: url,
data: req,
async: false
}).done(function (response) {
optionsValues = response.values;
//alert('option values : '+optionsValues);
}).fail(function(){
alert('failed to restore options values');
});
optionsValues = $.parseJSON(optionsValues);
if (optionsValues.markerstyle !== undefined){
$('#markerstyleselect').val(optionsValues.markerstyle);
}
if (optionsValues.clearbeforeload !== undefined){
$('#clearbeforeload').prop('checked', optionsValues.clearbeforeload);
}
}
function saveOptions(){
var optionsValues = {};
optionsValues.markerstyle = $('#markerstyleselect').val();
optionsValues.clearbeforeload = $('#clearbeforeload').is(':checked');
//alert('to save : '+JSON.stringify(optionsValues));
var req = {
optionsValues : JSON.stringify(optionsValues),
}
var url = OC.generateUrl('/apps/gpxedit/saveOptionsValues');
$.ajax({
type: 'POST',
url: url,
data: req,
async: true
}).done(function (response) {
//alert(response);
}).fail(function(){
alert('failed to save options values');
});
}
$(document).ready(function(){
gpxedit.username = $('p#username').html();
load_map();
document.onkeydown = checkKey;
restoreOptions();
$('select#markerstyleselect').change(function(e){
updateLeafletDrawMarkerStyle();
saveOptions();
});
// to set the draw style
updateLeafletDrawMarkerStyle();
$('body').on('change','#clearbeforeload', function() {
saveOptions();
});
$('body').on('click','button.popupOkButton', function(e) {
var id = parseInt($(this).attr('layerid'));
var name = $(this).parent().find('.layerName').val();