function writeMessage(el){ $.ajax({ headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, url: '/ru/user_account/chats/', type: "POST", // async: true, cache: false, processData: false, contentType: false, // enctype: 'json', // data: formData, success: function(data){ if (data.user_alerts) { getNewMessageSession() } // location.href = '/profile' document.querySelector(".info_profile").innerHTML = data.html; let list_div = document.querySelectorAll('.menu_profile div'); list_div.forEach(el=>{ el.classList.remove('selected'); }); el.classList.add('selected') }, error: function (data, exception){ console.log(400) } }); } function technicalSupport(el){ $.ajax({ headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, url: '/ru/user_account/support_tickets/', type: "POST", // async: true, cache: false, processData: false, contentType: false, // enctype: 'json', // data: formData, success: function(data){ if (data.user_alerts) { getNewMessageSession() } getNewMessageSession() console.log('data received') // location.href = '/profile' document.querySelector(".info_profile").innerHTML = data.html; let list_div = document.querySelectorAll('.menu_profile div'); list_div.forEach(el=>{ el.classList.remove('selected'); }); el.classList.add('selected') }, error: function (data, exception){ console.log(400) } }); } function mySubscription(el){ $.ajax({ headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, url: '/ru/user_account/subscribe/', type: "POST", // async: true, cache: false, processData: false, contentType: false, // enctype: 'json', // data: formData, success: function(data){ if (data.user_alerts) { getNewMessageSession() } console.log('data received') // location.href = '/profile' document.querySelector(".info_profile").innerHTML = data.html; let list_div = document.querySelectorAll('.menu_profile div'); list_div.forEach(el=>{ el.classList.remove('selected'); }); el.classList.add('selected') }, error: function (data, exception){ console.log(400) } }); } function myProfile(el){ $.ajax({ headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, url: '/ru/user_account/change_profile/', type: "POST", // async: true, cache: false, processData: false, contentType: false, // enctype: 'json', // data: formData, success: function(data){ if (data.user_alerts) { getNewMessageSession() } console.log('data received') // location.href = '/profile' document.querySelector(".info_profile").innerHTML = data.html; let list_div = document.querySelectorAll('.menu_profile div'); list_div.forEach(el=>{ el.classList.remove('selected'); }); el.classList.add('selected') }, error: function (data, exception){ console.log(400) } }); } // function selectMenuItem() { // let list_div = document.querySelectorAll('.menu_profile div'); // // list_div.forEach(item =>{ // item.addEventListener('click', (e) =>{ // list_div.forEach(el=>{ el.classList.remove('selected'); }); // item.classList.add('selected') // }) // }) // // // } function confirmRemove(el) { // let new_button = document.querySelector('.cancel_remove') // if(!new_button){ // } el.setAttribute("id", "select-remove"); let btn = document.querySelector("#select-remove"); if(!btn.classList.contains('confirm_remove')){ btn.classList.add('confirm_remove') btn.innerText = 'Подтвердить удаление' // let place = document.querySelector('.button_remove_route') let cancel_button = document.createElement('button') cancel_button.className = "cancel_remove"; cancel_button.innerText = "Отменить удаление"; let place = btn.closest(".button_remove_route") place.insertBefore(cancel_button, btn.nextSibling); } btn.removeAttribute("id", "select-remove") } function searchTown(el){ if(el.value.length>=3){ let timer = null if (timer) { clearTimeout(timer); } timer = setTimeout(function(){ timer = null; 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}); get_address_point['ctrl_name'] = el.name; $.ajax({ headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, url: '/ru/reference_data/get_address_point/', type: "POST", // async: true, cache: false, processData: false, contentType: false, // enctype: 'json', data: JSON.stringify(get_address_point), success: function(data){ getNewMessageSession() return insertSearchList(data, el.name + '_list') }, error: function (data){ console.log('Error') } }); }, 1500); } } function selectItemAddrPoint(id, name, ctrl_name,){ let input_list = document.getElementsByName(ctrl_name + '_list')[0]; let tap_txt_cont = document.querySelector("#id_" + ctrl_name); tap_txt_cont.value = name; let tap_cont = document.querySelector("#id_" + ctrl_name.slice(0, -4)); tap_cont.value = id; input_list.classList.remove('show'); } function insertSearchList(data, ctrl_name) { let input_list = document.getElementsByName(ctrl_name)[0]; let divs = data.res_search_list; if (divs.length > 0) { input_list.classList.add("show"); input_list.innerHTML = divs; } else { input_list.classList.remove("show"); } } function showSearchList(el) { if(el.classList.contains('from_address_point_txt')){ let input_list = document.querySelectorAll('.input_list') let value = input_list[0].classList.contains('show') if(value === false && input_list[0].childElementCount > 0){ input_list[0].classList.add("show"); } }else if (el.classList.contains('to_address_point_txt')) { let input_list = document.querySelectorAll('.input_list') let value = input_list[1].classList.contains('show') if(value === false && input_list[1].childElementCount > 0){ input_list[1].classList.add("show"); } } } function onblurInputField(event,el){ // if(el.classList.contains("from_country_container")){ let search_list = document.getElementsByName(el.name + '_list')[0]; let parent_event = $(event.explicitOriginalTarget).parents('.input_list' ); if(!parent_event || parent_event[0] !== search_list){ search_list.classList.remove('show') } // } } // function hideErrorMsg(el) { // let hide_element = document.querySelector() // if(el.value !== 0){ // hide_element.classList.add('hide') // } // // } function sliderInit() { let $range = $("#id_weight"), $input = $(".js-input"), instance, min = 0, max = 1000, start_value = document.querySelector(".range-slider").value; $range.ionRangeSlider({ skin: "round", type: "single", min: min, max: max, from: start_value, step: 1, grid: true, grid_num: 5, onStart: function(data) { if(data.from > 0){ $input.prop("value", data.from); } }, onChange: function(data) { $input.prop("value", data.from); } }); instance = $range.data("ionRangeSlider"); $input.on("change keyup", function() { let val = $(this).prop("value"); // validate if (val < min) { val = min; } else if (val > max) { val = max; } instance.update({ from: val }); }); } function sendRoute(el, routeID = null){ event.preventDefault() let form = el.form; let formData = new FormData(form); let url = '/ru/routes/create_or_change_route/' if (routeID !== null){ url = '/ru/routes/change_route/' + routeID + '/' } $.ajax({ headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, url: url, type: "POST", // async: true, cache: false, processData: false, contentType: false, // enctype: 'json', data: formData, success: function(data){ if (data.user_alerts) { getNewMessageSession() } 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; sliderInit(); } }); } // function maxLength(el) { // if (el.value.length > el.maxLength){ // el.value = el.value.slice(0, el.maxLength); // } // // } //cleaning route inputs after selection changes function OnSelectionChange(el) { event.preventDefault() let form = el.form; let formData = new FormData(form); // let data = {}; // data['csrfmiddlewaretoken'] = $('input[name="csrfmiddlewaretoken"]')[0].value; // data['type_transport'] = $('select[name="type_transport"]')[0].value; $.ajax({ headers: {"X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val()}, url: '/ru/user_account/new_route_view/', type: "POST", // async: true, cache: false, processData: false, contentType: false, // enctype: 'json', // data: JSON.stringify(data), data: formData, success: function (data) { console.log('data.html'); // location.href = '/profile' document.querySelector(".info_profile").innerHTML = data.html // let checkbox_width = document.querySelector('.checkbox_cargo_type'); if(checkbox_width.childElementCount === 4){ checkbox_width.classList.add('width') } sliderInit(); } }); }; function createRoute(el){ $.ajax({ headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, url: '/ru/user_account/new_route_view/', type: "POST", // async: true, cache: false, processData: false, contentType: false, // enctype: 'json', // data: {}, success: function(data){ if (data.user_alerts) { getNewMessageSession() } // console.log('data received') // location.href = '/profile' document.querySelector(".info_profile").innerHTML = data.html let list_div = document.querySelectorAll('.menu_profile div'); list_div.forEach(el=>{ el.classList.remove('selected'); }); el.classList.add('selected') //get dynamic value // let fromCountry = document.getElementById('id_from_country'); // let toCounytry = document.getElementById('id_to_country') // // toCounytry.oninput = function (){ // console.log(toCounytry.value) // } // fromCountry.oninput = function (){ // console.log(fromCountry.value) // // }; } }); } function getRoute(el){ $.ajax({ headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, url: '/ru/routes/get_routes/', type: "POST", // async: true, cache: false, processData: false, contentType: false, // enctype: 'json', // data: formData, success: function(data){ if (data.user_alerts) { getNewMessageSession() } console.log('data received') // location.href = '/profile' document.querySelector(".info_profile").innerHTML = data.html; let list_div = document.querySelectorAll('.menu_profile div'); list_div.forEach(el=>{ el.classList.remove('selected'); }); el.classList.add('selected') }, error: function (data, exception){ console.log(101) } }); }function editRoute(id) { let route_obj = { 'route_id': id } $.ajax({ headers: {"X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val()}, url: '/ru/routes/edit_route/', type: "POST", // async: true, cache: false, processData: false, contentType: false, // enctype: 'json', data: JSON.stringify(route_obj), success: function (data) { console.log('data received') // location.href = '/profile' document.querySelector(".info_profile").innerHTML = data.html; sliderInit(); }, error: function (data, exception) { console.log(101) } }); }