2024-08-05 11:42:32 +00:00
|
|
|
|
let rooms = {};
|
|
|
|
|
|
2024-08-10 03:09:51 +00:00
|
|
|
|
function openRoom(currentRoom) {
|
|
|
|
|
alert('Вы вошли в комнату: ' + currentRoom);
|
2024-08-05 11:42:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-10 03:09:51 +00:00
|
|
|
|
function closeAdd() {
|
|
|
|
|
document.getElementById('add_members').style.display = 'none';
|
2024-08-05 11:42:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-10 03:09:51 +00:00
|
|
|
|
function openAdd() {
|
|
|
|
|
document.getElementById('add_members').style.display = 'flex';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addMember() {
|
|
|
|
|
const login = document.getElementById('newMemberLogin').value;
|
|
|
|
|
if (login) {
|
|
|
|
|
alert(`Участник с никнеймом '${login}' добавлен`);
|
|
|
|
|
closeAdd();
|
2024-08-05 11:42:32 +00:00
|
|
|
|
} else {
|
2024-08-10 03:09:51 +00:00
|
|
|
|
alert('Пожалуйста, введите логин участника');
|
2024-08-05 11:42:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openCreateRoomModal() {
|
|
|
|
|
document.getElementById('createRoomModal').style.display = 'block';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeCreateRoomModal() {
|
|
|
|
|
document.getElementById('createRoomModal').style.display = 'none';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createRoom() {
|
|
|
|
|
const roomName = document.getElementById('newRoomName').value.trim();
|
2024-08-10 03:09:51 +00:00
|
|
|
|
if (roomName === '') {
|
2024-08-05 11:42:32 +00:00
|
|
|
|
alert('Пожалуйста, заполните все поля.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (rooms[roomName]) {
|
|
|
|
|
alert('Комната с таким названием уже существует.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-08-10 03:09:51 +00:00
|
|
|
|
rooms[roomName] = true;
|
2024-08-05 11:42:32 +00:00
|
|
|
|
addRoomToList(roomName);
|
|
|
|
|
closeCreateRoomModal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addRoomToList(roomName) {
|
|
|
|
|
const roomList = document.querySelector('.room-list');
|
|
|
|
|
const existingRoomItem = Array.from(roomList.children).find(item => item.querySelector('.room-name').textContent === roomName);
|
|
|
|
|
if (existingRoomItem) {
|
|
|
|
|
existingRoomItem.remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const roomItem = document.createElement('li');
|
|
|
|
|
roomItem.classList.add('room-item');
|
|
|
|
|
|
|
|
|
|
roomItem.innerHTML = `
|
|
|
|
|
<span class="room-name">${roomName}</span>
|
2024-08-10 03:09:51 +00:00
|
|
|
|
<button class="add-members-button" onclick="openAdd()">Добавить участников</button>
|
|
|
|
|
<button class="join-button" onclick="openRoom('${roomName}')">Войти</button>
|
2024-08-05 11:42:32 +00:00
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
roomList.appendChild(roomItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initializeRoomList() {
|
|
|
|
|
Object.keys(rooms).forEach(roomName => {
|
|
|
|
|
addRoomToList(roomName);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initializeRoomList();
|
|
|
|
|
|
|
|
|
|
window.onclick = function(event) {
|
|
|
|
|
if (event.target === document.getElementById('createRoomModal')) {
|
|
|
|
|
closeCreateRoomModal();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-10 03:09:51 +00:00
|
|
|
|
|
|
|
|
|
document.getElementById('newRoomName').addEventListener('keydown', function(event) {
|
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
|
createRoom();
|
|
|
|
|
}
|
|
|
|
|
});
|