/** * @fileoverview Manages room member management functionality. * This file handles: * - User selection interface using Select2 * - Adding new members to a room * - Removing existing members * - Form submission with member data */ /** * Initializes member management functionality when the document is ready. * Sets up: * - Select2 dropdown for user selection * - Member removal functionality * - Member addition functionality * - Form submission handling * @function */ $(document).ready(function() { // Initialize Select2 for user selection $('.select2').select2({ theme: 'bootstrap-5', width: '100%' }); /** * Handles member removal from the list. * Removes the member row from the UI when the remove button is clicked. * @event */ $(document).on('click', '.btn-remove-member', function() { const memberRow = $(this).closest('.member-row'); memberRow.remove(); }); /** * Handles adding a new member to the list. * Validates the selection and adds the member if not already present. * Creates a new member row with user details and adds it to the list. * @event */ $('#addMemberBtn').on('click', function() { const select = $('#user_id'); const selectedOption = select.find('option:selected'); const selectedValue = select.val(); if (!selectedValue) { return; } const userId = selectedValue; const userName = selectedOption.text(); const userEmail = selectedOption.data('email'); const userAvatar = selectedOption.data('avatar'); // Check if user is already in the list if ($(`.member-row[data-user-id="${userId}"]`).length > 0) { return; } // Create new member row const memberRow = `