-
-
- {{ form.delivery_cost }}
- {% if form.delivery_cost.errors %}
-
{{ form.delivery_cost.errors }}
- {% endif %}
+
+
+
+
+ {{ form.delivery_cost }}
+ {% if form.delivery_cost.errors %}
+
{{ form.delivery_cost.errors }}
+ {% endif %}
+
@@ -859,115 +812,6 @@ window.openCreateCustomerModal = function(searchText = '') {
createCustomerModal.show();
};
-// === ИНИЦИАЛИЗАЦИЯ РЕЖИМОВ АДРЕСА (вне jQuery зависимости) ===
-function initAddressModeToggle() {
- console.log('[ADDRESS MODE] Initializing address mode toggle');
-
- const addressModeRadios = document.querySelectorAll('input[name="address_mode"]');
- const addressHistoryMode = document.getElementById('address-history-mode');
- const addressNewMode = document.getElementById('address-new-mode');
- const customerSelect = document.getElementById('id_customer');
-
- if (!addressHistoryMode || !addressNewMode) {
- console.error('[ADDRESS MODE] address-history-mode or address-new-mode not found in DOM');
- return;
- }
-
- function toggleAddressMode() {
- console.log('[ADDRESS MODE] toggleAddressMode() called');
- const checkedRadio = document.querySelector('input[name="address_mode"]:checked');
- if (!checkedRadio) {
- console.log('[ADDRESS MODE] No radio checked, setting default to "empty"');
- const emptyRadio = document.querySelector('input[name="address_mode"][value="empty"]');
- if (emptyRadio) {
- emptyRadio.checked = true;
- }
- }
-
- const selectedMode = document.querySelector('input[name="address_mode"]:checked').value;
- console.log('[ADDRESS MODE] Selected mode:', selectedMode);
-
- // Убираем класс visible со всех режимов
- addressHistoryMode.classList.remove('visible');
- addressNewMode.classList.remove('visible');
-
- if (selectedMode === 'history') {
- console.log('[ADDRESS MODE] Showing history mode');
- addressHistoryMode.classList.add('visible');
- loadAddressHistory();
- } else if (selectedMode === 'new') {
- console.log('[ADDRESS MODE] Showing new address mode');
- addressNewMode.classList.add('visible');
- } else {
- console.log('[ADDRESS MODE] Empty mode - hiding all sections');
- }
- }
-
- function loadAddressHistory() {
- console.log('[ADDRESS MODE] loadAddressHistory() called');
- const customerId = customerSelect.value;
- console.log('[ADDRESS MODE] Customer ID:', customerId);
-
- if (!customerId) {
- const addressSelect = document.getElementById('id_address_from_history');
- addressSelect.innerHTML = '
';
- return;
- }
-
- fetch(`{% url 'orders:api-customer-address-history' %}?customer_id=${customerId}`)
- .then(response => response.json())
- .then(data => {
- console.log('[ADDRESS MODE] Address history data:', data);
- const addressSelect = document.getElementById('id_address_from_history');
-
- if (!data.success || data.count === 0) {
- addressSelect.innerHTML = '
';
- return;
- }
-
- let optionsHTML = '
';
- data.addresses.forEach(addr => {
- optionsHTML += `
`;
- });
- addressSelect.innerHTML = optionsHTML;
-
- // Если есть Select2, обновляем его
- if (typeof $ !== 'undefined' && $(addressSelect).data('select2')) {
- $(addressSelect).trigger('change');
- }
- })
- .catch(error => {
- console.error('[ADDRESS MODE] Error loading address history:', error);
- const addressSelect = document.getElementById('id_address_from_history');
- addressSelect.innerHTML = '
';
- });
- }
-
- // Добавляем обработчики на radio кнопки
- addressModeRadios.forEach(radio => {
- console.log('[ADDRESS MODE] Adding listener to radio:', radio.value);
- radio.addEventListener('change', function() {
- console.log('[ADDRESS MODE] Radio changed to:', this.value);
- toggleAddressMode();
- });
- });
-
- // Загружаем адреса при изменении клиента
- if (customerSelect) {
- customerSelect.addEventListener('change', function() {
- console.log('[ADDRESS MODE] Customer changed');
- loadAddressHistory();
- });
- }
-
- // Инициализация при загрузке
- console.log('[ADDRESS MODE] Initial toggle call');
- toggleAddressMode();
-}
-
-// Вызываем инициализацию адреса СРАЗУ (не зависит от jQuery)
-initAddressModeToggle();
-
// Вызываем инициализацию Select2 для customer
initCustomerSelect2();