Commit c3e505df authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Ability to save map with an existing title.

parent 2b5daaa9
Pipeline #2301 canceled with stages
in 4 minutes and 53 seconds
......@@ -414,6 +414,8 @@ selection.add-many.button=Add to selection list
savedmaps=Remember current map
savedmaps.list=Map list
savedmaps.save=Remember map
savedmaps.existing-title.error=Your title is already in use.
savedmaps.empty-title.error=The title can not be empty string.
taxonomy.subtaxa=Subtaxa
filter.enter.title=Enter filter title
......
......@@ -145,7 +145,7 @@ document.addEventListener('DOMContentLoaded', function() {
}
});
$(document.getElementsByClassName('close')).on('click', function (event) {
$(document.getElementById('error-loading-popup-close')).on('click', function (event) {
event.preventDefault();
document.getElementById('error-loading-popup-id').style.display = 'none';
});
......
......@@ -39,7 +39,7 @@
<div id="error-loading-popup-id" class="error-loading-popup">
<div class="error-loading-popup-content">
<span class="close"><span class="glyphicon glyphicon-remove"></span></span>
<span class="close" id="error-loading-popup-close"><span class="glyphicon glyphicon-remove"></span></span>
<p><spring:message code="prompt.loading-data-failed" /></p>
</div>
</div>
......
......@@ -86,14 +86,14 @@
<div class="col-lg-10 col-md-9 col-sm-9 col-xs-12" id="content-area">
<!-- Modal -->
<div class="modal fade" id="modal-dialog" tabindex="-1" role="dialog" aria-labelledby="modal-label"
aria-hidden="true">
<div class="modal fade" id="modal-dialog" tabindex="-1" role="dialog" aria-labelledby="modal-label">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span
aria-hidden="true">&times;</span><span
class="sr-only">Close</span></button>
<button type="button" class="close" data-dismiss="modal">
<span>&times;</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="modal-label"><spring:message code="savedmaps.save"/></h4>
</div>
<div class="modal-body">
......@@ -119,10 +119,16 @@
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">
<div class="alert alert-danger" id="existingTitleError" style="display: none">
<spring:message code="savedmaps.existing-title.error"/>
</div>
<div class="alert alert-danger" id="emptyTitleError" style="display: none">
<spring:message code="savedmaps.empty-title.error"/>
</div>
<button type="button" id="cancel-filter-save" class="btn btn-primary">
<spring:message code="cancel"/>
</button>
<button id="save-filter" type="button" class="btn btn-primary" data-dismiss="modal">
<button id="save-filter" type="button" class="btn btn-primary">
<spring:message code="save"/>
</button>
</div>
......@@ -456,7 +462,10 @@
});
$('#remember-map').on('click', function(e) {
e.preventDefault();
e.preventDefault();
$("#filter-title").val('');
$('#existingTitleError').hide();
$('#emptyTitleError').hide();
});
$("body").on("click", ".addFiltersBtn", function () {
......@@ -612,6 +621,10 @@
$('#color select').simplecolorpicker();
$("#cancel-filter-save").on("click", function (event) {
event.preventDefault();
$('.modal').modal('hide');
});
$("#save-filter").on("click", function (event) {
event.preventDefault();
......@@ -620,21 +633,43 @@
var filter = jsonData;
$.ajax({
url: "/savedmaps/save",
type: "post",
dataType: "json",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
title: title,
filter: JSON.stringify(filter),
color: $('#color select').val()
}),
success: function (data) {
},
error: function (error) {
console.log(error)
url: "/savedmaps/get",
type: "get",
dataType: "json",
contentType: 'application/json; charset=utf-8'
}).done(function(res) {
var needToSave = true;
res.forEach(function(item) {
if(item.title === $.trim(title)) {
needToSave = false;
$('#existingTitleError').show();
$('#emptyTitleError').hide();
}
});
if($.trim(title) === '') {
needToSave = false;
$('#emptyTitleError').show();
$('#existingTitleError').hide();
}
if(needToSave) {
$.ajax({
url: "/savedmaps/save",
type: "post",
dataType: "json",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
title: $.trim(title),
filter: JSON.stringify(filter),
color: $('#color select').val()
}),
error: function (error) {
console.log(error)
}
}).done(function() {
$('.modal').modal('hide');
});
}
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment