File size: 11,527 Bytes
6ea020b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!-- templates/partners.html -->
{% extends "base.html" %}

{% block title %}Partners - NexLab{% endblock %}
{% block page_title %}Partner Definition{% endblock %}

{% block content %}
<!-- Tom Select CSS -->
<link href="/static/vendor/tom-select/tom-select.css" rel="stylesheet">

<div class="bg-white rounded-xl shadow-sm border border-slate-200">
    <div class="p-6 border-b border-slate-200 flex justify-between items-center">
        <div>
            <h3 class="text-lg font-semibold text-slate-800">Partner Definition</h3>
            <p class="text-sm text-slate-500">Define laboratory partners and referral centers</p>
        </div>
        <button onclick="toggleForm('addPartnerForm')" 

                class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition duration-200">
            <svg class="w-5 h-5 inline mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg>
            Add Partner
        </button>
    </div>

    <!-- Add/Edit Partner Form -->
    <div id="addPartnerForm" style="display: none;" class="p-6 bg-slate-50 border-b border-slate-200">
        <h4 class="text-md font-semibold text-slate-700 mb-4" id="formTitle">New Partner Details</h4>
        <form method="POST" id="partnerForm" action="/partners/create">
            <input type="hidden" id="partner_id" name="partner_id" value="">
            
            <!-- Basic Info -->
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-1">Partner Name *</label>
                    <input type="text" id="partner_name" name="partner_name" required placeholder="e.g., Al-Shifa Medical Center" 

                           class="w-full border border-slate-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-500 focus:outline-none">
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-1">Partner Weight</label>
                    <input type="number" id="partner_weight" name="partner_weight" step="0.01" placeholder="e.g., 1.0" 

                           class="w-full border border-slate-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-500 focus:outline-none">
                    <p class="text-xs text-slate-500 mt-1">Used for calculations and prioritization</p>
                </div>
                <div class="md:col-span-2">
                    <label class="block text-sm font-medium text-slate-700 mb-1">Partner Contact</label>
                    <input type="text" id="partner_contact" name="partner_contact" placeholder="e.g., Phone: +123456789, Email: contact@example.com" 

                           class="w-full border border-slate-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-500 focus:outline-none">
                </div>
                <div class="md:col-span-2">
                    <label class="block text-sm font-medium text-slate-700 mb-1">Partner Note</label>
                    <textarea id="partner_note" name="partner_note" rows="3" placeholder="e.g., Preferred partner for specialized tests..." 

                              class="w-full border border-slate-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-500 focus:outline-none"></textarea>
                </div>
            </div>
            
            <div class="flex gap-2">
                <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg text-sm font-medium">
                    <svg class="w-4 h-4 inline mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4"></path></svg>
                    Save Partner
                </button>
                <button type="button" onclick="toggleForm('addPartnerForm')" 

                        class="bg-white border border-slate-300 text-slate-700 px-4 py-2 rounded-lg text-sm font-medium hover:bg-slate-50">
                    Cancel
                </button>
            </div>
        </form>
    </div>

    <!-- Search Box -->
    <div class="p-6 border-b border-slate-200 bg-slate-50">
        <h5 class="text-sm font-semibold text-slate-700 mb-3">Search Partners</h5>
        <div class="max-w-md">
            <label class="block text-xs font-medium text-slate-600 mb-1">Partner Name</label>
            <select id="searchPartner" placeholder="Search partners..." class="w-full border border-slate-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:outline-none">
                <option value="">All Partners</option>
                {% for partner in partners %}
                <option value="{{ partner.partner_name|lower }}">{{ partner.partner_name }}</option>
                {% endfor %}
            </select>
        </div>
    </div>

    <!-- Partners Table -->
    <div class="overflow-x-auto">
        <table class="min-w-full divide-y divide-slate-200">
            <thead class="bg-slate-50">
                <tr>
                    <th class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">ID</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Partner Name</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Contact</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Weight</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Note</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Actions</th>
                </tr>
            </thead>
            <tbody class="bg-white divide-y divide-slate-200" id="partnersTableBody">
                {% for partner in partners %}
                <tr class="hover:bg-slate-50" data-partner-name="{{ partner.partner_name|lower }}">
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-slate-500">#{{ partner.id }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-slate-800">{{ partner.partner_name }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-slate-500 max-w-md truncate">{{ partner.partner_contact if partner.partner_contact else '-' }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-slate-500">{{ partner.partner_weight if partner.partner_weight else '-' }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-slate-500 max-w-md truncate">{{ partner.partner_note if partner.partner_note else '-' }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                        <div class="flex items-center space-x-3">
                            <button onclick='editPartner({{ partners_json[loop.index0] | tojson }})' 

                                    class="text-blue-600 hover:text-blue-900" title="Edit">
                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg>
                            </button>
                            <a href="javascript:void(0)" 

                               onclick="confirmDelete('/partners/delete/{{ partner.id }}')"

                               class="text-red-600 hover:text-red-900" title="Delete">
                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg>
                            </a>
                        </div>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
    
    {% if not partners %}
    <div class="text-center py-12">
        <svg class="mx-auto h-12 w-12 text-slate-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path>
        </svg>
        <h3 class="mt-2 text-sm font-medium text-slate-900">No partners defined</h3>
        <p class="mt-1 text-sm text-slate-500">Get started by adding a new partner definition.</p>
    </div>
    {% endif %}
</div>

<!-- Tom Select JS -->
<script src="/static/vendor/tom-select/tom-select.complete.min.js"></script>
<script>

let searchPartnerSelect;



function toggleForm(formId) {

    const form = document.getElementById(formId);

    form.style.display = form.style.display === 'none' ? 'block' : 'none';

    if (form.style.display === 'none') {

        document.getElementById('partnerForm').reset();

        document.getElementById('partner_id').value = '';

        document.getElementById('formTitle').textContent = 'New Partner Details';

    }

}



// Initialize Tom Select on page load

document.addEventListener('DOMContentLoaded', function() {

    // Initialize search dropdown

    searchPartnerSelect = new TomSelect('#searchPartner', {

        plugins: ['dropdown_input'],

        placeholder: 'Search partners...',

        create: false,

        maxItems: 1,

        onChange: function(value) {

            filterPartners();

        }

    });

});



function editPartner(partner) {

    document.getElementById('partner_id').value = partner.id;

    document.getElementById('partner_name').value = partner.partner_name;

    document.getElementById('partner_note').value = partner.partner_note || '';

    document.getElementById('partner_contact').value = partner.partner_contact || '';

    document.getElementById('partner_weight').value = partner.partner_weight || '';

    

    document.getElementById('formTitle').textContent = 'Edit Partner Details';

    document.getElementById('addPartnerForm').style.display = 'block';

    document.getElementById('partnerForm').action = '/partners/update/' + partner.id;

}



// Filter partners based on search selection

function filterPartners() {

    const partnerInput = (searchPartnerSelect?.getValue() || '').toLowerCase();

    const rows = document.querySelectorAll('#partnersTableBody tr');

    

    rows.forEach(row => {

        const partnerName = row.dataset.partnerName || '';

        

        if (!partnerInput || partnerName.includes(partnerInput)) {

            row.style.display = '';

        } else {

            row.style.display = 'none';

        }

    });

}

</script>
{% endblock %}