From f2019ec81bc1026a9f5468d9693d65e42ec2d0ff Mon Sep 17 00:00:00 2001 From: ArtemB Date: Thu, 20 Jul 2023 16:05:21 +0300 Subject: [PATCH] 0.0.22 autocomlitev2.js --- requirements.pip | 2 +- static/js/autocomlitev2.js | 53 +++++++++++++++++++++ static/js/autocomplete.js | 28 ++++++----- static/js/newRoute.js | 2 +- static/js/sendRoute.js | 12 +++++ templates/blocks/profile/b_new_route.html | 2 +- templates/forms/f_registration.html | 2 +- templates/pages/profile/p_user_profile.html | 2 +- 8 files changed, 86 insertions(+), 17 deletions(-) create mode 100644 static/js/autocomlitev2.js diff --git a/requirements.pip b/requirements.pip index 8330467..f4632b1 100644 --- a/requirements.pip +++ b/requirements.pip @@ -3,6 +3,6 @@ django-ckeditor==6.5.1 psycopg2-binary==2.9.6 requests Pillow -django-modeltranslation=0.18.10 +django-modeltranslation overpass geopy \ No newline at end of file diff --git a/static/js/autocomlitev2.js b/static/js/autocomlitev2.js new file mode 100644 index 0000000..b0ae835 --- /dev/null +++ b/static/js/autocomlitev2.js @@ -0,0 +1,53 @@ +function searchTown(el){ + let form = el.form; + let type_transport = form['type_transport'].value; + let search_str = el.value; + let get_address_point = new Object({type_transport, search_str}) + + + $.ajax({ + headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, + url: '/reference_data/get_address_point/', + type: "POST", + // async: true, + cache: false, + processData: false, + contentType: false, + // enctype: 'json', + data: get_address_point, + success: function(data){ + return data; + }, + error: function (data){ + console.log('++') + // document.querySelector(".button_register").innerHTML = data.responseJSON.html + } + }); +} + + + +function search(e) { + + let ac = document.querySelector("#id_from_country") + + if (ac.value.length > 0) { + + let results = searchTown(ac); + + var divs = results.map()(function(r, i) { + return '
' + + '
'+ r.iata +' - '+ r.name +'
' + + '
'+ r.city +', '+ r.country +'
' + + '
'; + }); + + selectedIndex = -1; + list.html(divs.join('')) + .attr('data-highlight', selectedIndex); + + } else { + numResults = 0; + list.empty(); + } +} \ No newline at end of file diff --git a/static/js/autocomplete.js b/static/js/autocomplete.js index edec1e3..027b924 100644 --- a/static/js/autocomplete.js +++ b/static/js/autocomplete.js @@ -18,25 +18,27 @@ function searchTown(el){ let form = el.form; - let formData = new FormData(form); + let type_transport = form['type_transport'].value; + let search_str = el.value; + let get_address_point = new Object({type_transport, search_str}) + $.ajax({ headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, - url: '/ru/routes/create_route/', + url: '/reference_data/get_address_point/', type: "POST", // async: true, cache: false, processData: false, contentType: false, // enctype: 'json', - data: formData, + data: get_address_point, success: function(data){ - console.log('data received') - // location.href = '/profile' - document.querySelector(".info_profile").innerHTML = data.html + return data; }, - error: function (data, exception){ - document.querySelector(".button_register").innerHTML = data.responseJSON.html + error: function (data){ + console.log('++') + // document.querySelector(".button_register").innerHTML = data.responseJSON.html } }); } @@ -45,7 +47,7 @@ var ac = $('#id_from_country') .on('click', function(e) { e.stopPropagation(); }) - .on('focus keyup', search) + .on('keyup', search) .on('keydown', onKeyDown); var wrap = $('
') @@ -93,13 +95,15 @@ function search(e) { return; } - if (ac.val().length > 0) { + let ac = document.querySelector("#id_from_country") + + if (ac.value.length > 0) { // results = _.take(fuse.search(ac.val()), 7); // numResults = results.length; - results = searchTown.success(data); + let results = searchTown(ac); - var divs = results.map(function(r, i) { + var divs = results.map()(function(r, i) { return '
' + '
'+ r.iata +' - '+ r.name +'
' + '
'+ r.city +', '+ r.country +'
' diff --git a/static/js/newRoute.js b/static/js/newRoute.js index edb9cf5..017e6f0 100644 --- a/static/js/newRoute.js +++ b/static/js/newRoute.js @@ -11,7 +11,7 @@ function createRoute(){ // enctype: 'json', // data: {}, success: function(data){ - console.log('data received') + // console.log('data received') // location.href = '/profile' document.querySelector(".info_profile").innerHTML = data.html diff --git a/static/js/sendRoute.js b/static/js/sendRoute.js index 04419bc..782a5ed 100644 --- a/static/js/sendRoute.js +++ b/static/js/sendRoute.js @@ -17,9 +17,21 @@ function sendRoute(el){ console.log('data received') // location.href = '/profile' document.querySelector(".info_profile").innerHTML = data.html + }, error: function (data, exception){ document.querySelector(".info_profile").innerHTML = data.responseJSON.html + + $('#id_weight').ionRangeSlider({ + skin: "round", + type: "single", + min: 0, + max: 1000, + from: 500, + step: 1, + grid: true, + grid_num: 5, + }); } }); } diff --git a/templates/blocks/profile/b_new_route.html b/templates/blocks/profile/b_new_route.html index ed6d1dd..3f4011b 100644 --- a/templates/blocks/profile/b_new_route.html +++ b/templates/blocks/profile/b_new_route.html @@ -40,7 +40,7 @@
- + {% if form.errors and form.errors.from_country %} {{ form.errors.from_country }} {% endif %} diff --git a/templates/forms/f_registration.html b/templates/forms/f_registration.html index 8f91851..0c89671 100644 --- a/templates/forms/f_registration.html +++ b/templates/forms/f_registration.html @@ -1,7 +1,7 @@

Регистрация

-
+ {% csrf_token %} {#
#} diff --git a/templates/pages/profile/p_user_profile.html b/templates/pages/profile/p_user_profile.html index a0c555d..776e419 100644 --- a/templates/pages/profile/p_user_profile.html +++ b/templates/pages/profile/p_user_profile.html @@ -8,7 +8,7 @@ - +