document.addEventListener('DOMContentLoaded', function () { // Password visibility toggle const togglePasswordButtons = document.querySelectorAll('.btn-toggle-password'); togglePasswordButtons.forEach(button => { button.addEventListener('click', function () { const targetInput = document.querySelector(this.dataset.target); const icon = this.querySelector('i'); if (targetInput.type === 'password') { targetInput.type = 'text'; icon.classList.remove('bi-eye-slash'); icon.classList.add('bi-eye'); } else { targetInput.type = 'password'; icon.classList.remove('bi-eye'); icon.classList.add('bi-eye-slash'); } }); }); // Copy password to clipboard const copyPasswordButtons = document.querySelectorAll('.btn-copy-password'); copyPasswordButtons.forEach(button => { button.addEventListener('click', function () { const targetInput = document.querySelector(this.dataset.target); navigator.clipboard.writeText(targetInput.value).then(() => { // Visual feedback const originalIcon = 'bi-clipboard'; const successIcon = 'bi-check-lg'; const icon = this.querySelector('i'); icon.classList.remove(originalIcon); icon.classList.add(successIcon); setTimeout(() => { icon.classList.remove(successIcon); icon.classList.add(originalIcon); }, 1500); }).catch(err => { console.error('Failed to copy password: ', err); alert('Failed to copy password.'); }); }); }); // Client search filtering const clientSearchInput = document.getElementById('client-search'); if (clientSearchInput) { clientSearchInput.addEventListener('keyup', function () { const searchTerm = this.value.toLowerCase(); const clientList = document.getElementById('client-list'); const clients = clientList.getElementsByTagName('tr'); for (let i = 0; i < clients.length; i++) { const client = clients[i]; const clientId = client.getElementsByTagName('td')[0].textContent.toLowerCase(); const clientName = client.getElementsByTagName('td')[1].textContent.toLowerCase(); if (clientId.includes(searchTerm) || clientName.includes(searchTerm)) { client.style.display = ''; } else { client.style.display = 'none'; } } }); } // AJAX for adding a new note const addNoteForm = document.getElementById('add-note-form'); if (addNoteForm) { addNoteForm.addEventListener('submit', function (e) { e.preventDefault(); const formData = new FormData(this); const noteTextarea = this.querySelector('textarea[name="note"]'); fetch('add-note.php', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { if (data.success) { // Create the new note element const newNote = data.note; const noteElement = document.createElement('div'); noteElement.classList.add('card', 'mb-2'); noteElement.innerHTML = `
"${newNote.note.replace(/\n/g, '
')}"