function initPendingNotifications() {
pendingNotifications();
- notificationIntervalId = setInterval(pendingNotifications, 10000);
+ notificationIntervalId = setInterval(pendingNotifications, 600000);
}
// Останавливаем polling когда вкладка неактивна — экономим соединения и трафик
} else {
if (!notificationIntervalId) {
pendingNotifications();
- notificationIntervalId = setInterval(pendingNotifications, 10000);
+ notificationIntervalId = setInterval(pendingNotifications, 600000);
}
}
});
}
function pendingNotifications() {
+ // Не отправляем запросы пока идёт загрузка формы — освобождаем соединения
+ if (window._uploadInProgress) return;
+
$.ajax({
method: 'POST',
url: window.location.origin + '/notification/pending',
}
});
+ // Останавливаем notification polling — освобождаем соединения для upload
+ window._uploadInProgress = true;
+
// Индикатор загрузки
var submitBtn = yiiform.find('.submitter');
var originalText = submitBtn.text();
submitBtn.prop('disabled', true).text('Загрузка...');
+ // Прогресс-бар загрузки файлов
+ var $progressWrap = yiiform.find('#upload-progress-wrap');
+ if ($progressWrap.length === 0) {
+ submitBtn.after(
+ '<div id="upload-progress-wrap" style="max-width:500px; margin-top:10px;">' +
+ ' <div class="progress" style="height:22px;">' +
+ ' <div id="upload-progress-bar" class="progress-bar bg-primary progress-bar-striped progress-bar-animated"' +
+ ' role="progressbar" style="width:0%">0%</div>' +
+ ' </div>' +
+ ' <small id="upload-progress-text" class="text-muted"></small>' +
+ '</div>'
+ );
+ $progressWrap = yiiform.find('#upload-progress-wrap');
+ }
+ $progressWrap.show();
+ var $bar = $progressWrap.find('#upload-progress-bar');
+ var $text = $progressWrap.find('#upload-progress-text');
+ var uploadStartTime = Date.now();
+
var xhr = new XMLHttpRequest();
+
+ // Прогресс отправки файлов на сервер
+ xhr.upload.addEventListener('progress', function (e) {
+ if (e.lengthComputable) {
+ var percent = Math.round(e.loaded / e.total * 100);
+ $bar.css('width', percent + '%').text(percent + '%');
+
+ var elapsed = (Date.now() - uploadStartTime) / 1000;
+ var speedMbps = elapsed > 0 ? (e.loaded / 1024 / 1024) / elapsed : 0;
+ var remaining = speedMbps > 0 ? ((e.total - e.loaded) / 1024 / 1024) / speedMbps : 0;
+
+ var speedText = speedMbps >= 1
+ ? speedMbps.toFixed(1) + ' МБ/с'
+ : (speedMbps * 1024).toFixed(0) + ' КБ/с';
+
+ var remainText = '';
+ if (remaining > 0 && percent < 100) {
+ if (remaining < 60) {
+ remainText = ' — осталось ~' + Math.ceil(remaining) + ' сек';
+ } else {
+ remainText = ' — осталось ~' + Math.ceil(remaining / 60) + ' мин';
+ }
+ }
+
+ var loadedMb = (e.loaded / 1024 / 1024).toFixed(1);
+ var totalMb = (e.total / 1024 / 1024).toFixed(1);
+ $text.text(loadedMb + ' / ' + totalMb + ' МБ · ' + speedText + remainText);
+ }
+ });
+
+ xhr.upload.addEventListener('loadend', function () {
+ $bar.css('width', '100%').text('100%');
+ $bar.removeClass('progress-bar-animated');
+ $text.text('Файлы загружены. Обработка на сервере...');
+ });
+
xhr.open('POST', form.action, true);
xhr.onload = function () {
+ window._uploadInProgress = false;
+ $progressWrap.hide();
if (xhr.status === 200) {
var responseURL = xhr.responseURL || '';
if (responseURL && responseURL !== window.location.href) {
};
xhr.onerror = function () {
+ window._uploadInProgress = false;
+ $progressWrap.hide();
alert('Ошибка сети. Проверьте подключение и попробуйте снова.');
submitBtn.prop('disabled', false).text(originalText);
};
+ xhr.ontimeout = function () {
+ window._uploadInProgress = false;
+ $progressWrap.hide();
+ alert('Таймаут загрузки. Файлы слишком большие для текущего соединения.');
+ submitBtn.prop('disabled', false).text(originalText);
+ };
+
xhr.send(formData);
}