{% extends "base.html" %} {% block title %}{% if post %}Edycja Posta #{{ post.id }}{% else %}Nowy Post{% endif %} - Social Media{% endblock %} {% block extra_css %} {% endblock %} {% block content %}

{% if post %}Edycja Posta #{{ post.id }}{% else %}Nowy Post{% endif %}

Powrot do listy
Jak działa publikacja postów na Facebooku?
📝
Szkic
Post zapisany w systemie, nie wysłany na FB
Publikuj (debug)
➡️
🔒
Debug na FB
Widoczny tylko dla adminów strony FB
Opublikuj publicznie
➡️
🌐
Publiczny
Widoczny dla wszystkich na Facebooku
⬅️ ⬅️ ⬅️ Usuń z FB → powrót do szkicu (Facebook nie pozwala cofnąć publikacji)
{% if post %}
Status: {% if post.status == 'draft' %}Szkic {% elif post.status == 'approved' %}Zatwierdzony {% elif post.status == 'scheduled' %}Zaplanowany {% elif post.status == 'published' %}Opublikowany {% elif post.status == 'failed' %}Błąd publikacji — sprawdź połączenie z Facebookiem w Integracje. Jeśli połączenie działa, kliknij "Spróbuj ponownie". {% else %}{{ post.status }}{% endif %} {% if post.creator %} | Autor: {{ post.creator.name }} {% endif %} {% if post.ai_model %} | Model AI: {{ post.ai_model }} {% endif %} {% if post.published_at %} | Opublikowano: {{ post.published_at|local_time('%Y-%m-%d %H:%M') }} {% endif %} {% if post.status == 'published' and post.meta_post_id %} | {% if post.is_live %} Publiczny {% else %} Debug (tylko admin) {% endif %} {% endif %}
{% endif %}
{% if configured_companies %}

Strona Facebook, na ktorej zostanie opublikowany post

{% endif %}

Firma, którą chcesz zaprezentować w poście

Wydarzenie powiązane z postem

Kontekst dla AI

0 znaków

Hashtagi oddzielone spacjami

Silnik AI: Google Gemini. Domyslny model (Gemini 3 Flash) jest szybki i tani. Dla lepszej jakosci wybierz Gemini 3 Pro — lepsza kreatywnosc i styl, ale ~4x wyzszy koszt.
Anuluj {% set is_debug = configured_companies and configured_companies|selectattr('debug_mode')|list|length > 0 %} {% if post %} {% if post.status == 'draft' %} {% endif %} {% if post.status in ['draft', 'approved', 'failed'] %} {% if is_debug %} {% endif %} {% endif %} {% if post.status != 'published' %} {% endif %} {% else %} {% if is_debug %} {% endif %} {% endif %}
{% if post and post.status == 'published' and post.meta_post_id %}

Widoczność na Facebooku

{% if post.is_live %}
Publiczny Post jest widoczny dla wszystkich użytkowników Facebooka.

Uwaga: Facebook nie pozwala na cofnięcie publikacji posta. Jedyną opcją jest usunięcie posta z Facebooka — post zniknie ze strony FB, ale jego treść pozostanie w naszym systemie jako szkic i będzie można go opublikować ponownie.

{% else %}
Debug (tylko admin) Post jest widoczny tylko dla administratorów strony na Facebooku.
{% endif %}
{% endif %} {% if post and post.status == 'published' %} {% endif %}
{% endblock %} {% block extra_js %} function showAiError(msg) { const el = document.getElementById('ai-error-msg'); el.textContent = msg; el.style.display = 'block'; } function hideAiError() { document.getElementById('ai-error-msg').style.display = 'none'; } // AI generation document.getElementById('btn-generate-ai')?.addEventListener('click', async function() { const postType = document.getElementById('post_type').value; const companyId = document.getElementById('company_id')?.value; const eventId = document.getElementById('event_id')?.value; const tone = document.getElementById('tone')?.value || ''; const aiModel = document.getElementById('ai_model')?.value || ''; if (!postType) { showAiError('Wybierz typ posta przed generowaniem.'); return; } const customContext = {}; const topicEl = document.getElementById('custom_topic'); if (topicEl) customContext.topic = topicEl.value; const detailsEl = document.getElementById('custom_details'); if (detailsEl) customContext.details = detailsEl.value; const factsEl = document.getElementById('custom_facts'); if (factsEl) customContext.facts = factsEl.value; const sourceEl = document.getElementById('custom_source'); if (sourceEl) customContext.source = sourceEl.value; this.disabled = true; this.textContent = 'Generowanie...'; try { const resp = await fetch("{{ url_for('admin.social_publisher_generate') }}", { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRFToken': document.querySelector('[name=csrf_token]')?.value || '' }, body: JSON.stringify({ post_type: postType, company_id: companyId || null, event_id: eventId || null, publishing_company_id: document.getElementById('publishing_company_id')?.value || null, tone: tone, ai_model: aiModel, custom_context: customContext }) }); const data = await resp.json(); if (data.success) { document.getElementById('content').value = data.content; if (data.hashtags) { document.getElementById('hashtags').value = data.hashtags; } updateContentCounter(); hideAiError(); if (data.model) { document.getElementById('ai-model-used-name').textContent = data.model; document.getElementById('ai-model-used').style.display = 'inline'; } } else { showAiError(data.error || 'Nie udalo sie wygenerowac tresci. Sprobuj ponownie.'); } } catch (err) { showAiError('Blad polaczenia z serwerem. Sprawdz polaczenie internetowe i sprobuj ponownie.'); } finally { this.disabled = false; this.textContent = 'Generuj AI'; } }); // Hashtag generation document.getElementById('btn-generate-hashtags')?.addEventListener('click', async function() { const content = document.getElementById('content').value.trim(); const errEl = document.getElementById('hashtag-error-msg'); if (!content) { errEl.textContent = 'Wpisz najpierw tresc posta, aby wygenerowac hashtagi.'; errEl.style.display = 'block'; return; } errEl.style.display = 'none'; this.disabled = true; this.textContent = 'Generowanie...'; try { const resp = await fetch("{{ url_for('admin.social_publisher_generate_hashtags') }}", { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRFToken': document.querySelector('[name=csrf_token]')?.value || '' }, body: JSON.stringify({ content: content, post_type: document.getElementById('post_type')?.value || '', ai_model: document.getElementById('ai_model')?.value || '' }) }); const data = await resp.json(); if (data.success) { document.getElementById('hashtags').value = data.hashtags; errEl.style.display = 'none'; } else { errEl.textContent = data.error || 'Nie udalo sie wygenerowac hashtagow.'; errEl.style.display = 'block'; } } catch (err) { errEl.textContent = 'Blad polaczenia z serwerem.'; errEl.style.display = 'block'; } finally { this.disabled = false; this.textContent = 'Generuj hashtagi AI'; } }); // Show/hide context fields based on post type document.getElementById('post_type')?.addEventListener('change', function() { const type = this.value; document.getElementById('company-field')?.classList.toggle('d-none', type !== 'member_spotlight'); document.getElementById('event-field')?.classList.toggle('d-none', !type.startsWith('event_')); document.getElementById('custom-context-field')?.classList.toggle('d-none', !['regional_news', 'chamber_news'].includes(type)); }); // Trigger on load document.getElementById('post_type')?.dispatchEvent(new Event('change')); // Character counter function updateContentCounter() { const content = document.getElementById('content'); const counter = document.getElementById('content-counter'); if (content && counter) { const len = content.value.length; counter.textContent = len + ' znaków'; counter.classList.remove('warning', 'over'); if (len > 2000) counter.classList.add('over'); else if (len > 1500) counter.classList.add('warning'); } } document.getElementById('content')?.addEventListener('input', updateContentCounter); updateContentCounter(); // Custom confirm modal let confirmCallback = null; function showConfirm(opts) { document.getElementById('confirmIcon').textContent = opts.icon || '❓'; document.getElementById('confirmTitle').textContent = opts.title || 'Potwierdzenie'; const msgEl = document.getElementById('confirmMessage'); msgEl.innerHTML = ''; (opts.message || '').split('\n').forEach(function(line, i) { if (i > 0) msgEl.appendChild(document.createElement('br')); msgEl.appendChild(document.createTextNode(line)); }); const okBtn = document.getElementById('confirmOk'); okBtn.textContent = opts.okText || 'OK'; okBtn.className = opts.okClass || 'btn btn-primary'; if (opts.form) { confirmCallback = function() { document.getElementById(opts.form).submit(); }; } else if (opts.submitAction) { confirmCallback = function() { const form = document.getElementById('postForm'); const hidden = document.createElement('input'); hidden.type = 'hidden'; hidden.name = 'action'; hidden.value = opts.submitAction; form.appendChild(hidden); form.submit(); }; } document.getElementById('confirmOverlay').classList.add('active'); } function hideConfirm() { document.getElementById('confirmOverlay').classList.remove('active'); confirmCallback = null; } document.getElementById('confirmOk')?.addEventListener('click', function() { if (confirmCallback) confirmCallback(); hideConfirm(); }); document.getElementById('confirmCancel')?.addEventListener('click', hideConfirm); document.getElementById('confirmOverlay')?.addEventListener('click', function(e) { if (e.target === this) hideConfirm(); }); document.addEventListener('keydown', function(e) { if (e.key === 'Escape') hideConfirm(); }); {% endblock %}