Files
backPRO/assets/js/app.js
2026-02-15 11:37:27 +01:00

77 lines
3.3 KiB
JavaScript

// BackPRO - Frontend Scripts
document.addEventListener('DOMContentLoaded', function () {
// Test connection buttons
document.querySelectorAll('.btn-test-connection').forEach(function (btn) {
btn.addEventListener('click', function () {
var siteId = this.dataset.siteId;
var button = this;
var originalHtml = button.innerHTML;
button.innerHTML = '<span class="spinner-border spinner-border-sm"></span>';
button.disabled = true;
fetch('/sites/' + siteId + '/test', { method: 'POST' })
.then(function (r) { return r.json(); })
.then(function (data) {
if (data.success) {
button.innerHTML = '<i class="bi bi-check-lg"></i>';
button.classList.remove('btn-outline-success');
button.classList.add('btn-success');
} else {
button.innerHTML = '<i class="bi bi-x-lg"></i>';
button.classList.remove('btn-outline-success');
button.classList.add('btn-danger');
alert('Błąd połączenia: ' + data.message);
}
})
.catch(function () {
button.innerHTML = '<i class="bi bi-x-lg"></i>';
button.classList.add('btn-danger');
alert('Błąd sieci');
})
.finally(function () {
button.disabled = false;
setTimeout(function () {
button.innerHTML = originalHtml;
button.className = button.className.replace('btn-success', 'btn-outline-success').replace('btn-danger', 'btn-outline-success');
}, 3000);
});
});
});
// Topic edit buttons
document.querySelectorAll('.btn-edit-topic').forEach(function (btn) {
btn.addEventListener('click', function () {
var id = this.dataset.id;
var form = document.getElementById('topicForm');
var title = document.getElementById('topicFormTitle');
var submit = document.getElementById('topicFormSubmit');
form.action = '/topics/' + id + '/update';
title.textContent = 'Edytuj temat';
submit.textContent = 'Zapisz zmiany';
document.getElementById('topic_name').value = this.dataset.name;
document.getElementById('topic_description').value = this.dataset.description;
document.getElementById('topic_wp_category').value = this.dataset.wpCategory || '';
document.getElementById('topic_is_active').checked = this.dataset.active === '1';
var globalSelect = document.getElementById('topic_global_id');
if (globalSelect) {
globalSelect.value = this.dataset.globalTopic || '';
}
});
});
// Highlight active sidebar link
var currentPath = window.location.pathname;
document.querySelectorAll('.sidebar .nav-link').forEach(function (link) {
var href = link.getAttribute('href');
if (currentPath === href || (href !== '/' && currentPath.startsWith(href))) {
link.classList.add('active');
}
});
});