diff --git a/RoutesApp/models.py b/RoutesApp/models.py index 7631e11..4efc563 100644 --- a/RoutesApp/models.py +++ b/RoutesApp/models.py @@ -74,6 +74,29 @@ class Route(BaseModel): verbose_name_plural = _(u'Маршруты') ordering = ('name',) + def from_country_n_city_str(self): + country = 'Неизвестно' + if self.from_city: + city = self.from_city.name + if self.from_city.country: + country = self.from_city.country + else: + city = 'Неизвестно' + + return f'{city} / {country}' + + def to_country_n_city_str(self): + country = 'Неизвестно' + if self.to_city: + city = self.to_city.name + if self.to_city.country: + country = self.to_city.country + else: + city = 'Неизвестно' + + return f'{city} / {country}' + + def get_address_points(self): from ReferenceDataApp.models import Airport, City diff --git a/static/css/styles.css b/static/css/styles.css index c171e00..4101854 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -1632,25 +1632,26 @@ button#remove_route { } button.confirm_remove{ width: 49% !important; - background: #ff0000a8; + border: 1px solid #ff0000a8; border-radius: 10px; - color: white; + color: #ff0000a8; font-style: normal; font-weight: 600; margin-right: 3px; padding: 5px 0px 5px 0px; - - - + font-size: 16px; } + button.cancel_remove{ width: 48%; - background: #808080cc; + border: 1px solid #808080cc; border-radius: 10px; - color: white; + color: #808080cc; font-style: normal; font-weight: 600; padding: 5px 0px 5px 0px; + font-size: 16px; + } diff --git a/static/js/user_profile.js b/static/js/user_profile.js index 7c2872e..8da3e97 100644 --- a/static/js/user_profile.js +++ b/static/js/user_profile.js @@ -153,32 +153,92 @@ function myProfile(el){ +function removeRoute(el) { + let data = el.currentTarget.closest('.carrier-card'); + let remove_item = data.dataset.numberOfRoute + let remove_data = {} + let name_route = 'route_id' + remove_data[name_route] = remove_item + + // console.log(remove_item) + + $.ajax({ + headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, + url: '/ru/routes/del_route/', + type: "POST", + // async: true, + cache: false, + processData: false, + contentType: false, + // enctype: 'json', + data: JSON.stringify(remove_data) , + 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') + + //updating the url without reloading + window.history.pushState(null, null, '/ru/profile/page/change_profile/') + }, + error: function (data, exception){ + console.log(400) + + } + }); + + +} + +function cancelRemove() { + let parent_cancel_button = document.querySelector('.button_remove_route') + let cancel_button = document.querySelector('.cancel_remove') + parent_cancel_button.removeChild(cancel_button) + + let remove_button = document.querySelector('.confirm_remove'); + remove_button.classList.remove('confirm_remove'); + remove_button.innerText = 'Удалить'; + remove_button.setAttribute("id", "remove_route"); + + +} 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') + if (!btn.classList.contains('confirm_remove')) { + btn.classList.add('confirm_remove'); + btn.innerText = 'Подтвердить удаление'; + btn.addEventListener('click', removeRoute, { once: true }); + + let cancel_button = document.createElement('button'); cancel_button.className = "cancel_remove"; cancel_button.innerText = "Отменить удаление"; - let place = btn.closest(".button_remove_route") + cancel_button.addEventListener('click', cancelRemove) + + + let place = btn.closest(".button_remove_route"); place.insertBefore(cancel_button, btn.nextSibling); + + btn.removeAttribute( "select-remove"); + + } - btn.removeAttribute("id", "select-remove") } + + function searchTown(el){ if (el.value.length > 0){ diff --git a/templates/widgets/w_ac_input_address_point.html b/templates/widgets/w_ac_input_address_point.html index 3b9ba35..ec64cfe 100644 --- a/templates/widgets/w_ac_input_address_point.html +++ b/templates/widgets/w_ac_input_address_point.html @@ -1,4 +1,4 @@