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

Ability to save map with an existing title.

parent 2b5daaa9
...@@ -414,6 +414,8 @@ selection.add-many.button=Add to selection list ...@@ -414,6 +414,8 @@ selection.add-many.button=Add to selection list
savedmaps=Remember current map savedmaps=Remember current map
savedmaps.list=Map list savedmaps.list=Map list
savedmaps.save=Remember map 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 taxonomy.subtaxa=Subtaxa
filter.enter.title=Enter filter title filter.enter.title=Enter filter title
......
...@@ -145,7 +145,7 @@ document.addEventListener('DOMContentLoaded', function() { ...@@ -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(); event.preventDefault();
document.getElementById('error-loading-popup-id').style.display = 'none'; document.getElementById('error-loading-popup-id').style.display = 'none';
}); });
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<div id="error-loading-popup-id" class="error-loading-popup"> <div id="error-loading-popup-id" class="error-loading-popup">
<div class="error-loading-popup-content"> <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> <p><spring:message code="prompt.loading-data-failed" /></p>
</div> </div>
</div> </div>
......
...@@ -86,14 +86,14 @@ ...@@ -86,14 +86,14 @@
<div class="col-lg-10 col-md-9 col-sm-9 col-xs-12" id="content-area"> <div class="col-lg-10 col-md-9 col-sm-9 col-xs-12" id="content-area">
<!-- Modal --> <!-- Modal -->
<div class="modal fade" id="modal-dialog" tabindex="-1" role="dialog" aria-labelledby="modal-label" <div class="modal fade" id="modal-dialog" tabindex="-1" role="dialog" aria-labelledby="modal-label">
aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span <button type="button" class="close" data-dismiss="modal">
aria-hidden="true">&times;</span><span <span>&times;</span>
class="sr-only">Close</span></button> <span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="modal-label"><spring:message code="savedmaps.save"/></h4> <h4 class="modal-title" id="modal-label"><spring:message code="savedmaps.save"/></h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
...@@ -119,10 +119,16 @@ ...@@ -119,10 +119,16 @@
</div> </div>
</div> </div>
<div class="modal-footer"> <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"/> <spring:message code="cancel"/>
</button> </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"/> <spring:message code="save"/>
</button> </button>
</div> </div>
...@@ -456,7 +462,10 @@ ...@@ -456,7 +462,10 @@
}); });
$('#remember-map').on('click', function(e) { $('#remember-map').on('click', function(e) {
e.preventDefault(); e.preventDefault();
$("#filter-title").val('');
$('#existingTitleError').hide();
$('#emptyTitleError').hide();
}); });
$("body").on("click", ".addFiltersBtn", function () { $("body").on("click", ".addFiltersBtn", function () {
...@@ -612,6 +621,10 @@ ...@@ -612,6 +621,10 @@
$('#color select').simplecolorpicker(); $('#color select').simplecolorpicker();
$("#cancel-filter-save").on("click", function (event) {
event.preventDefault();
$('.modal').modal('hide');
});
$("#save-filter").on("click", function (event) { $("#save-filter").on("click", function (event) {
event.preventDefault(); event.preventDefault();
...@@ -620,21 +633,43 @@ ...@@ -620,21 +633,43 @@
var filter = jsonData; var filter = jsonData;
$.ajax({ $.ajax({
url: "/savedmaps/save", url: "/savedmaps/get",
type: "post", type: "get",
dataType: "json", dataType: "json",
contentType: 'application/json; charset=utf-8', contentType: 'application/json; charset=utf-8'
data: JSON.stringify({ }).done(function(res) {
title: title, var needToSave = true;
filter: JSON.stringify(filter), res.forEach(function(item) {
color: $('#color select').val() if(item.title === $.trim(title)) {
}), needToSave = false;
success: function (data) { $('#existingTitleError').show();
$('#emptyTitleError').hide();
},
error: function (error) {
console.log(error)
} }
});
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