| | |
| | | </section> |
| | | |
| | | <section class="rounded-xl border border-gray-200 bg-white shadow-sm dark:border-gray-800 dark:bg-gray-900"> |
| | | <div class="border-b border-gray-200 px-4 py-3 font-semibold dark:border-gray-800 sm:px-5">Действия ({{ actions|length }})</div> |
| | | <div class="border-b border-gray-200 px-4 py-3 font-semibold dark:border-gray-800 sm:px-5">Действия (<span id="rp-action-count">{{ actions|length }}</span>)</div> |
| | | <div id="rp-actions-list" class="divide-y divide-gray-100 dark:divide-gray-800"> |
| | | {% if actions %} |
| | | <div class="divide-y divide-gray-100 dark:divide-gray-800"> |
| | | {% for a in actions %} |
| | | <div class="flex flex-col gap-3 px-4 py-4 text-sm sm:flex-row sm:items-center sm:justify-between sm:px-5"> |
| | | <div class="rp-action flex flex-col gap-3 px-4 py-4 text-sm sm:flex-row sm:items-center sm:justify-between sm:px-5" data-action-id="{{ a.id }}"> |
| | | <div class="min-w-0 flex-1 break-words"> |
| | | <div class="flex flex-wrap items-center gap-2 font-medium text-gray-900 dark:text-white"> |
| | | <span>{{ a.trigger }}</span> |
| | | {% if not a.enabled %}<span class="rounded-full bg-gray-100 px-2 py-0.5 text-xs text-gray-500 dark:bg-gray-800 dark:text-gray-400">Выключено</span>{% endif %} |
| | | <span class="rp-disabled-badge rounded-full bg-gray-100 px-2 py-0.5 text-xs text-gray-500 dark:bg-gray-800 dark:text-gray-400 {% if a.enabled %}hidden{% endif %}">Выключено</span> |
| | | </div> |
| | | <div class="mt-1 whitespace-pre-wrap text-gray-600 dark:text-gray-300">{{ a.response_text }}</div> |
| | | {% if a.gif_file_id %} |
| | |
| | | </div> |
| | | </div> |
| | | {% endfor %} |
| | | </div> |
| | | {% else %} |
| | | <div class="px-4 py-6 text-center text-sm text-gray-500 sm:px-5">Действий пока нет. Добавьте первое выше.</div> |
| | | <div id="rp-empty" class="px-4 py-6 text-center text-sm text-gray-500 sm:px-5">Действий пока нет. Добавьте первое выше.</div> |
| | | {% endif %} |
| | | </div> |
| | | </section> |
| | | </div> |
| | | |
| | |
| | | msgEl.className = 'mt-3 rounded-lg bg-green-50 px-3 py-2 text-sm text-green-700 dark:bg-green-950/40 dark:text-green-300'; |
| | | msgEl.textContent = 'Действие добавлено!'; |
| | | form.reset(); |
| | | setTimeout(() => location.reload(), 1000); |
| | | setTimeout(() => { |
| | | msgEl.classList.add('hidden'); |
| | | msgEl.textContent = ''; |
| | | }, 3000); |
| | | } else { |
| | | msgEl.className = 'mt-3 rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700 dark:bg-red-950/40 dark:text-red-300'; |
| | | msgEl.textContent = result.msg || 'Ошибка при добавлении действия'; |
| | |
| | | return result; |
| | | } |
| | | |
| | | function updateActionCount() { |
| | | document.getElementById('rp-action-count').textContent = document.querySelectorAll('.rp-action').length; |
| | | if (!document.querySelector('.rp-action') && !document.getElementById('rp-empty')) { |
| | | const empty = document.createElement('div'); |
| | | empty.id = 'rp-empty'; |
| | | empty.className = 'px-4 py-6 text-center text-sm text-gray-500 sm:px-5'; |
| | | empty.textContent = 'Действий пока нет. Добавьте первое выше.'; |
| | | document.getElementById('rp-actions-list').appendChild(empty); |
| | | } |
| | | } |
| | | |
| | | document.querySelectorAll('.rp-toggle').forEach(btn => { |
| | | btn.addEventListener('click', async () => { |
| | | btn.disabled = true; |
| | | try { |
| | | const row = btn.closest('.rp-action'); |
| | | const enabled = btn.dataset.enabled === '1'; |
| | | await postRpAction('/api/rp/toggle', { |
| | | action_id: btn.dataset.actionId, |
| | | chat_id: btn.dataset.chatId, |
| | | enabled: btn.dataset.enabled |
| | | }); |
| | | location.reload(); |
| | | btn.dataset.enabled = enabled ? '0' : '1'; |
| | | btn.textContent = enabled ? 'Включить' : 'Выключить'; |
| | | row.querySelector('.rp-disabled-badge').classList.toggle('hidden', enabled); |
| | | } catch (err) { |
| | | alert(err.message); |
| | | btn.disabled = false; |
| | |
| | | |
| | | try { |
| | | await postRpAction('/api/rp/delete', {action_id: actionId, chat_id: chatId}); |
| | | location.reload(); |
| | | btn.closest('.rp-action').remove(); |
| | | updateActionCount(); |
| | | } catch (err) { |
| | | alert('Ошибка сети: ' + err.message); |
| | | } |