]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Перенос JS
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 2 Oct 2025 12:20:21 +0000 (15:20 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 2 Oct 2025 12:20:21 +0000 (15:20 +0300)
erp24/web/js/matrix-erp/index.js [new file with mode: 0644]

diff --git a/erp24/web/js/matrix-erp/index.js b/erp24/web/js/matrix-erp/index.js
new file mode 100644 (file)
index 0000000..a8edda7
--- /dev/null
@@ -0,0 +1,67 @@
+// Matrix ERP Feed Active Toggle Functions
+
+function toggleFeedActive(id, isActive) {
+    // Попробуем получить CSRF токен из мета-тега
+    let csrfToken = $('meta[name=csrf-token]').attr('content');
+    if (!csrfToken) {
+        csrfToken = window.csrfToken || '';
+    }
+
+    $.ajax({
+        url: window.matrixErpToggleFeedActiveUrl,
+        type: 'POST',
+        data: {
+            id: id,
+            is_feed_active: isActive ? 1 : 0,
+            _csrf: csrfToken
+        },
+        success: function(response) {
+            showAlert(response.success ? 'success' : 'danger', response.message);
+        },
+        error: function(xhr, status, error) {
+            let message = 'Произошла ошибка при обновлении статуса фида';
+            if (xhr.responseJSON && xhr.responseJSON.message) {
+                message = xhr.responseJSON.message;
+            }
+            showAlert('danger', message);
+        }
+    });
+}
+
+function showAlert(type, message) {
+    // Проверяем, что jQuery доступен
+    if (typeof $ === 'undefined') {
+        console.error('jQuery not found!');
+        alert(message); // fallback
+        return;
+    }
+
+    const alertContainer = $('#feed-alert-container');
+    if (alertContainer.length === 0) {
+        console.error('Alert container not found!');
+        alert(message); // fallback
+        return;
+    }
+
+    const alertId = 'alert-' + Date.now();
+    const alertHtml = `
+        <div id="${alertId}" class="alert alert-${type} alert-dismissible fade show" role="alert" style="margin-bottom: 0px;">
+            ${message}
+            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">&times;</button>
+        </div>
+    `;
+
+    alertContainer.append(alertHtml);
+
+    // Auto remove after 5 seconds
+    setTimeout(function() {
+        const alertElement = $('#' + alertId);
+        if (alertElement.length > 0) {
+            alertElement.fadeOut(function() {
+                $(this).remove();
+            });
+        }
+    }, 5000);
+}
+
+// Functions for Matrix ERP Feed Active Toggle