diff --git a/assets/css/list-rooms.css b/assets/css/list-rooms.css new file mode 100644 index 0000000..5069dc5 --- /dev/null +++ b/assets/css/list-rooms.css @@ -0,0 +1,187 @@ + + + + + + Список Чат-Комнат + + + +
+

Выберите Чат-Комнату

+ + +
+ + + + + + + + + diff --git a/assets/html/list-rooms.html b/assets/html/list-rooms.html new file mode 100644 index 0000000..d4ce2e8 --- /dev/null +++ b/assets/html/list-rooms.html @@ -0,0 +1,52 @@ + + + + + + Список Чат-Комнат + + + +
+

Выберите Чат-Комнату

+ + +
+ + + + + + + + + diff --git a/assets/js/list-rooms.js b/assets/js/list-rooms.js new file mode 100644 index 0000000..081634c --- /dev/null +++ b/assets/js/list-rooms.js @@ -0,0 +1,83 @@ +let rooms = {}; + +function openModal(roomName) { + currentRoom = roomName; + document.getElementById('passwordModal').style.display = 'block'; +} + +function closeModal() { + document.getElementById('passwordModal').style.display = 'none'; +} + +function validatePassword() { + const enteredPassword = document.getElementById('roomPassword').value; + if (enteredPassword === rooms[currentRoom]) { + alert('Вы вошли в комнату: ' + currentRoom); + closeModal(); + } else { + alert('Неверный пароль. Попробуйте снова.'); + } +} + +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(); + const roomPassword = document.getElementById('newRoomPassword').value.trim(); + + if (roomName === '' || roomPassword === '') { + alert('Пожалуйста, заполните все поля.'); + return; + } + + if (rooms[roomName]) { + alert('Комната с таким названием уже существует.'); + return; + } + + rooms[roomName] = roomPassword; + 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 = ` + ${roomName} + + `; + + roomList.appendChild(roomItem); +} + +function initializeRoomList() { + Object.keys(rooms).forEach(roomName => { + addRoomToList(roomName); + }); +} + +initializeRoomList(); + +window.onclick = function(event) { + if (event.target === document.getElementById('passwordModal')) { + closeModal(); + } + if (event.target === document.getElementById('createRoomModal')) { + closeCreateRoomModal(); + } +}