File size: 14,089 Bytes
9da4125 |
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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
{% extends 'base.html' %}
{% block title %}Контакты{% endblock %}
{% block content %}
<div class="container-fluid py-4">
<div class="row">
<div class="col-12">
<div class="card mb-4">
<div class="card-header pb-0">
<h6>Мои контакты</h6>
<div class="d-flex justify-content-between align-items-center">
<div>
<button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addContactModal">
<i class="fas fa-user-plus"></i> Добавить контакт
</button>
</div>
<div class="input-group w-50">
<input type="text" id="searchInput" class="form-control" placeholder="Поиск контактов...">
<span class="input-group-text"><i class="fas fa-search"></i></span>
</div>
</div>
</div>
<div class="card-body px-0 pt-0 pb-2">
<div class="table-responsive p-0">
<table class="table align-items-center mb-0">
<thead>
<tr>
<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Пользователь</th>
<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Статус</th>
<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Действия</th>
</tr>
</thead>
<tbody>
{% if contacts|length > 0 %}
{% for contact in contacts %}
<tr>
<td>
<div class="d-flex px-2 py-1">
<div class="d-flex flex-column justify-content-center">
<h6 class="mb-0 text-sm">{{ contact.username }}</h6>
<p class="text-xs text-secondary mb-0">{{ contact.email }}</p>
</div>
</div>
</td>
<td>
<a href="{{ url_for('messages', contact_id=contact.contact_id) }}" class="btn btn-sm btn-primary">
<i class="fas fa-comments"></i> Сообщения
{% if contact.unread_count > 0 %}
<span class="badge bg-danger ms-1">{{ contact.unread_count }}</span>
{% endif %}
</a>
</td>
<td>
<form action="{{ url_for('remove_contact', contact_id=contact.id) }}" method="post" class="d-inline">
<button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Вы уверены, что хотите удалить этот контакт?')">
<i class="fas fa-user-minus"></i> Удалить
</button>
</form>
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="3" class="text-center py-4">
<p class="text-secondary mb-0">У вас пока нет контактов</p>
<button type="button" class="btn btn-primary btn-sm mt-2" data-bs-toggle="modal" data-bs-target="#addContactModal">
<i class="fas fa-user-plus"></i> Добавить контакт
</button>
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{% if incoming_requests|length > 0 %}
<div class="row">
<div class="col-12">
<div class="card mb-4">
<div class="card-header pb-0">
<h6>Входящие запросы <span class="badge bg-primary">{{ incoming_requests|length }}</span></h6>
</div>
<div class="card-body px-0 pt-0 pb-2">
<div class="table-responsive p-0">
<table class="table align-items-center mb-0">
<thead>
<tr>
<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Пользователь</th>
<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Действия</th>
</tr>
</thead>
<tbody>
{% for request in incoming_requests %}
<tr>
<td>
<div class="d-flex px-2 py-1">
<div class="d-flex flex-column justify-content-center">
<h6 class="mb-0 text-sm">{{ request.username }}</h6>
<p class="text-xs text-secondary mb-0">{{ request.email }}</p>
</div>
</div>
</td>
<td>
<form action="{{ url_for('accept_contact', contact_id=request.id) }}" method="post" class="d-inline">
<button type="submit" class="btn btn-sm btn-success">
<i class="fas fa-check"></i> Принять
</button>
</form>
<form action="{{ url_for('reject_contact', contact_id=request.id) }}" method="post" class="d-inline">
<button type="submit" class="btn btn-sm btn-danger">
<i class="fas fa-times"></i> Отклонить
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{% endif %}
{% if outgoing_requests|length > 0 %}
<div class="row">
<div class="col-12">
<div class="card mb-4">
<div class="card-header pb-0">
<h6>Исходящие запросы <span class="badge bg-primary">{{ outgoing_requests|length }}</span></h6>
</div>
<div class="card-body px-0 pt-0 pb-2">
<div class="table-responsive p-0">
<table class="table align-items-center mb-0">
<thead>
<tr>
<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Пользователь</th>
<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Статус</th>
</tr>
</thead>
<tbody>
{% for request in outgoing_requests %}
<tr>
<td>
<div class="d-flex px-2 py-1">
<div class="d-flex flex-column justify-content-center">
<h6 class="mb-0 text-sm">{{ request.username }}</h6>
<p class="text-xs text-secondary mb-0">{{ request.email }}</p>
</div>
</div>
</td>
<td>
<span class="badge bg-warning">Ожидает подтверждения</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{% endif %}
</div>
<!-- Модальное окно добавления контакта -->
<div class="modal fade" id="addContactModal" tabindex="-1" aria-labelledby="addContactModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addContactModalLabel">Добавить контакт</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="{{ url_for('add_contact') }}" method="post" id="addContactForm">
<div class="mb-3">
<label for="username_or_email" class="form-label">Имя пользователя или Email</label>
<input type="text" class="form-control" id="username_or_email" name="username_or_email" required>
</div>
<div id="searchResults" class="list-group mb-3" style="display: none;"></div>
<button type="submit" class="btn btn-primary">Добавить</button>
</form>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const searchInput = document.getElementById('username_or_email');
const searchResults = document.getElementById('searchResults');
searchInput.addEventListener('input', function() {
const query = this.value.trim();
if (query.length < 3) {
searchResults.style.display = 'none';
return;
}
fetch(`/search_users?q=${encodeURIComponent(query)}`)
.then(response => response.json())
.then(data => {
searchResults.innerHTML = '';
if (data.length === 0) {
searchResults.style.display = 'none';
return;
}
data.forEach(user => {
const item = document.createElement('a');
item.href = '#';
item.className = 'list-group-item list-group-item-action';
let statusBadge = '';
if (user.status === 'accepted') {
statusBadge = '<span class="badge bg-success float-end">В контактах</span>';
} else if (user.status === 'pending') {
statusBadge = '<span class="badge bg-warning float-end">Запрос отправлен</span>';
}
item.innerHTML = `
<div class="d-flex w-100 justify-content-between">
<h6 class="mb-1">${user.username}</h6>
${statusBadge}
</div>
<small>${user.email}</small>
`;
item.addEventListener('click', function(e) {
e.preventDefault();
searchInput.value = user.username;
searchResults.style.display = 'none';
});
searchResults.appendChild(item);
});
searchResults.style.display = 'block';
})
.catch(error => console.error('Ошибка при поиске пользователей:', error));
});
});
</script>
{% endblock %} |