{% extends "base.html" %} {% block title %}Moderacja Rekomendacji - Norda Biznes Partner{% endblock %} {% block extra_css %} {% endblock %} {% block content %}

⭐ Moderacja Rekomendacji

Zarządzaj rekomendacjami firm członkowskich

{{ total_recommendations }}
Wszystkich
{{ pending_count }}
Oczekujących
{{ approved_count }}
Zatwierdzonych
{{ rejected_count }}
Odrzuconych

Rekomendacje

{% if recommendations %} {% for rec in recommendations %} {% endfor %}
Firma Rekomendujący Treść Data Status Akcje
{{ rec.company.name }} {% if rec.service_category %}
{{ rec.service_category }}
{% endif %}
{{ rec.user.name or rec.user.email.split('@')[0] }} {% if rec.user.company %}
{{ rec.user.company.name }} {% endif %}
{{ rec.recommendation_text }}
{{ rec.created_at.strftime('%d.%m.%Y') }} {% if rec.status == 'pending' %} Oczekuje {% elif rec.status == 'approved' %} Zatwierdzona {% elif rec.status == 'rejected' %} Odrzucona {% endif %}
{% if rec.status == 'pending' %} {% elif rec.status == 'rejected' %} {% endif %}
{% else %}

Brak rekomendacji

{% endif %}
{% endblock %} {% block extra_js %} const csrfToken = '{{ csrf_token() }}'; let currentRecommendationId = null; let confirmResolve = null; function showConfirm(message, options = {}) { return new Promise(resolve => { confirmResolve = resolve; document.getElementById('confirmModalIcon').textContent = options.icon || '❓'; document.getElementById('confirmModalTitle').textContent = options.title || 'Potwierdzenie'; document.getElementById('confirmModalMessage').innerHTML = message; document.getElementById('confirmModalOk').textContent = options.okText || 'OK'; document.getElementById('confirmModalOk').className = 'btn ' + (options.okClass || 'btn-primary'); document.getElementById('confirmModal').classList.add('active'); }); } function closeConfirm(result) { document.getElementById('confirmModal').classList.remove('active'); if (confirmResolve) { confirmResolve(result); confirmResolve = null; } } document.getElementById('confirmModalOk').addEventListener('click', () => closeConfirm(true)); document.getElementById('confirmModalCancel').addEventListener('click', () => closeConfirm(false)); document.getElementById('confirmModal').addEventListener('click', e => { if (e.target.id === 'confirmModal') closeConfirm(false); }); function showToast(message, type = 'info', duration = 4000) { const container = document.getElementById('toastContainer'); const icons = { success: '✓', error: '✕', warning: '⚠', info: 'ℹ' }; const toast = document.createElement('div'); toast.className = `toast ${type}`; toast.innerHTML = `${icons[type]||'ℹ'}${message}`; container.appendChild(toast); setTimeout(() => { toast.style.animation = 'toastOut 0.3s ease forwards'; setTimeout(() => toast.remove(), 300); }, duration); } function showMessage(message, type) { showToast(message, type === 'error' ? 'error' : 'success'); } // Filter tabs functionality document.querySelectorAll('.filter-tab').forEach(tab => { tab.addEventListener('click', function() { // Update active tab document.querySelectorAll('.filter-tab').forEach(t => t.classList.remove('active')); this.classList.add('active'); // Filter rows const filter = this.dataset.filter; document.querySelectorAll('[data-recommendation-id]').forEach(row => { if (filter === 'all' || row.dataset.status === filter) { row.style.display = ''; } else { row.style.display = 'none'; } }); }); }); async function approveRecommendation(recommendationId) { try { const response = await fetch(`/admin/recommendations/${recommendationId}/approve`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrfToken } }); const data = await response.json(); if (data.success) { location.reload(); } else { showMessage(data.error || 'Wystąpił błąd', 'error'); } } catch (error) { showMessage('Błąd połączenia', 'error'); } } function openRejectModal(recommendationId, companyName) { currentRecommendationId = recommendationId; document.getElementById('rejectionReason').value = ''; document.getElementById('rejectModal').classList.add('active'); } function closeRejectModal() { currentRecommendationId = null; document.getElementById('rejectModal').classList.remove('active'); } async function confirmReject() { if (!currentRecommendationId) return; const reason = document.getElementById('rejectionReason').value.trim(); try { const response = await fetch(`/admin/recommendations/${currentRecommendationId}/reject`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrfToken }, body: JSON.stringify({ reason: reason }) }); const data = await response.json(); if (data.success) { closeRejectModal(); location.reload(); } else { showMessage(data.error || 'Wystąpił błąd', 'error'); } } catch (error) { showMessage('Błąd połączenia', 'error'); } } async function deleteRecommendation(recommendationId, companyName) { const confirmed = await showConfirm(`Czy na pewno chcesz usunąć rekomendację dla firmy "${companyName}"?

Ta operacja jest nieodwracalna.`, { icon: '🗑️', title: 'Usuwanie rekomendacji', okText: 'Usuń', okClass: 'btn-danger' }); if (!confirmed) return; try { const response = await fetch(`/api/recommendations/${recommendationId}/delete`, { method: 'DELETE', headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrfToken } }); const data = await response.json(); if (data.success) { document.querySelector(`tr[data-recommendation-id="${recommendationId}"]`).remove(); showToast('Rekomendacja została usunięta', 'success'); } else { showMessage(data.error || 'Wystąpił błąd', 'error'); } } catch (error) { showMessage('Błąd połączenia', 'error'); } } // Close modal on background click document.getElementById('rejectModal').addEventListener('click', function(e) { if (e.target === this) { closeRejectModal(); } }); {% endblock %}