Commit 90d4d639 authored by Renán Sosa Guillen's avatar Renán Sosa Guillen

list updated

parent 15bb7498
...@@ -95,55 +95,66 @@ var makeRequest = function (value) { ...@@ -95,55 +95,66 @@ var makeRequest = function (value) {
function drawPolygon(element) { function drawPolygon(element) {
polygonList.forEach(function (polygon) { polygonList.forEach(function (polygon) {
if (polygon.id === element.id) { if (polygon.id === element.id) {
// remove prev polygon // remove prev polygon
osmap.removePolygon(); osmap.removePolygon();
// format coords to draw // format coords to draw
var coords = osmap.formatCoords(polygon.geojson.geometry.coordinates); var coords = osmap.formatCoords(polygon.geojson.geometry.coordinates);
// get the biggest area // get the biggest area
var biggest = osmap.getBiggestPolygon(coords); var biggest = osmap.getBiggestPolygon(coords);
// draw coordsR // draw coordsR
osmap.addPolygon(biggest); osmap.addPolygon(biggest);
} }
}) })
} }
$('#ajax-input').focus(function () { $('#ajax-input').focus(function () {
console.log('in'); console.log('in');
if (OPT_LIST_IS_HIDDEN && $(this).val() != '') { if (OPT_LIST_IS_HIDDEN && $(this).val()) {
$('#option-list').show(); $('#option-list').show();
OPT_LIST_IS_HIDDEN = false; OPT_LIST_IS_HIDDEN = false;
} }
}).blur(function () { }).blur(function () {
if (!OPT_LIST_IS_HIDDEN && $(this).val() != '' && $(event.target).closest('#option-list').length ) { if (!OPT_LIST_IS_HIDDEN && $(this).val() && $(event.target).closest('#option-list').length) {
$('#option-list').hide(); $('#option-list').hide();
OPT_LIST_IS_HIDDEN = true; OPT_LIST_IS_HIDDEN = true;
} }
}); });
$('#polygon-list').click(function () {
$('#option-list').hide();
OPT_LIST_IS_HIDDEN = true;
$('#ajax-input').value = $(this)
});
$(document).click(function (event) { $(document).click(function (event) {
if (!OPT_LIST_IS_HIDDEN) { if (!OPT_LIST_IS_HIDDEN) {
//if click is triggered outside '#option-list' element remove the list //if click is triggered outside '#option-list' element remove the list
if(!$(event.target).closest('#option-list').length > 0 ) { if(!$(event.target).closest('#option-list').length > 0 ) {
$('#option-list').hide(); $('#option-list').hide();
OPT_LIST_IS_HIDDEN = true; OPT_LIST_IS_HIDDEN = true;
} }
} }
}); });
$(document).ready(function () { $(document).ready(function () {
var pol_element = document.getElementById('polygon-list'); var pol_element = document.getElementById('polygon-list');
$('#ajax-input').on('input', function(e) { var typingTimer;
var typingInterval = 800; //milliseconds
// On keyup, start the contdown
$('#ajax-input').on('input', function () {
var value = $('#ajax-input').val();
clearTimeout(typingTimer);
var value = $(this).val(); if (value) {
if (value === '') { typingTimer = setTimeout(makeRequest.bind(null, value), typingInterval);
} else {
$('#option-list').hide(); $('#option-list').hide();
while (pol_element.firstChild) { while (pol_element.firstChild) {
...@@ -154,36 +165,5 @@ $(document).ready(function () { ...@@ -154,36 +165,5 @@ $(document).ready(function () {
return return
} }
// console.log("TOKEN: ", document.getElementsByName('csrfmiddlewaretoken')[0].value);
makeRequest(value);
// $.ajax({
// type: "POST",
// url: "http://localhost:8080/catalog/searchsubmit/",
// data: {
// 'csrfmiddlewaretoken': document.getElementsByName('csrfmiddlewaretoken')[0].value,
// 'value': value
// },
// dataType: 'json',
// success: function(data) {
// console.log("DATA: ", data.polygonList);
// while (pol_element.firstChild) {
// pol_element.removeChild(pol_element.firstChild);
// }
// data.polygonList.forEach(function (polygon) {
// $('#polygon-list').append('<a href="#"><li class="pol">' + polygon.city + ", " + polygon.state + '</li></a>');
// });
// if (OPT_LIST_IS_HIDDEN) {
// $('#option-list').show();
// OPT_LIST_IS_HIDDEN = false;
// }
// }
// });
}); });
});
// $('#option-list').focusout(function () {
// $(this).hide();
// });
});
\ No newline at end of file
...@@ -194,8 +194,9 @@ ...@@ -194,8 +194,9 @@
<!-- AdminLTE App --> <!-- AdminLTE App -->
<script src="{% static 'adminlte/dist/js/adminlte.min.js' %}"></script> <script src="{% static 'adminlte/dist/js/adminlte.min.js' %}"></script>
{% block scripts %}{% endblock %}
<script src="{% static 'js/dataRetrieval.js' %}" type="text/javascript"></script> <script src="{% static 'js/dataRetrieval.js' %}" type="text/javascript"></script>
{% block scripts %}{% endblock %}
</body> </body>
</html> </html>
...@@ -30,7 +30,7 @@ def map(request): ...@@ -30,7 +30,7 @@ def map(request):
form = ASFSearchForm(request.POST) form = ASFSearchForm(request.POST)
# Render the HTML template index.html with the data in the context variable # Render the HTML template index.html with the data in the context variable
return render(request,'map.html',{"searchForm":form}) return render(request, 'map.html', { "searchForm": form })
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def productList(request): def productList(request):
......
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