File size: 3,012 Bytes
996fcf9
 
 
 
9aaf067
996fcf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9aaf067
 
 
996fcf9
 
 
 
 
9aaf067
996fcf9
 
 
 
 
9aaf067
996fcf9
 
 
 
9aaf067
996fcf9
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{% extends "base.html" %}
{% block title %}Dropdown Options — Admin{% endblock %}
{% block content %}
<div class="space-y-4">
    <a href="/admin/?token={{ token }}" class="text-sm text-gray-400 hover:text-gray-600">← Admin Panel</a>
    <h1 class="text-2xl font-bold sw-blue-text">Dropdown Options</h1>
    <p class="text-gray-500 text-sm">Manage the options shown in form dropdowns. Changes take effect immediately.</p>

    {% for category, options in grouped.items() %}
    <div class="bg-white rounded-lg shadow overflow-hidden">
        <div class="sw-blue text-white px-5 py-3 flex items-center justify-between">
            <span class="font-semibold capitalize">{{ category.replace('_', ' ') }}</span>
            <button onclick="addOption('{{ category }}')" class="bg-white/20 hover:bg-white/30 px-3 py-1 rounded text-sm">+ Add</button>
        </div>
        <div class="divide-y">
            {% for opt in options %}
            <div class="px-5 py-3 flex items-center justify-between {{ 'opacity-50' if not opt.is_active }}">
                <div>
                    <span class="text-sm font-medium">{{ opt.label }}</span>
                    {% if opt.value != opt.label %}
                    <span class="text-xs text-gray-400 ml-2">({{ opt.value }})</span>
                    {% endif %}
                </div>
                <div class="flex items-center space-x-3">
                    <button onclick="toggleOption({{ opt.id }})"
                            class="px-2 py-0.5 rounded text-xs font-semibold {{ 'bg-green-100 text-green-700' if opt.is_active else 'bg-red-100 text-red-700' }}">
                        {{ 'Active' if opt.is_active else 'Inactive' }}
                    </button>
                    <button onclick="deleteOption({{ opt.id }})" class="text-red-400 hover:text-red-600 text-xs">Delete</button>
                </div>
            </div>
            {% endfor %}
        </div>
    </div>
    {% endfor %}
</div>
<script>
const authToken = '{{ token }}';
const authHeaders = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + authToken};

async function addOption(category) {
    const label = prompt('Enter the display label for the new ' + category.replace('_',' ') + ' option:');
    if (!label) return;
    const value = prompt('Internal value (leave blank to use label):', label);
    await fetch('/admin/api/dropdowns/new', {
        method: 'POST', headers: authHeaders,
        body: JSON.stringify({ category, label, value: value || label }),
    });
    location.reload();
}
async function toggleOption(id) {
    await fetch('/admin/api/dropdowns/' + id + '/toggle', { method: 'POST', headers: {'Authorization': 'Bearer ' + authToken} });
    location.reload();
}
async function deleteOption(id) {
    if (!confirm('Delete this option permanently?')) return;
    await fetch('/admin/api/dropdowns/' + id, { method: 'DELETE', headers: {'Authorization': 'Bearer ' + authToken} });
    location.reload();
}
</script>
{% endblock %}