Spaces:
Running
Running
| // script-modularized/utils.js | |
| export function generateAvatarUrl(name, background = '3b82f6', color = 'fff') { | |
| return `https://ui-avatars.com/api/?name=${encodeURIComponent(name || '')}&background=${background}&color=${color}`; | |
| } | |
| export function escapeHtml(text) { | |
| if (!text) return ''; | |
| return text.replace(/[&<>"]/g, c => { | |
| return { | |
| '&': '&', | |
| '<': '<', | |
| '>': '>', | |
| '"': '"' | |
| }[c]; | |
| }); | |
| } | |
| export function escapeJs(text) { | |
| if (!text) return ''; | |
| return text | |
| .replace(/\\/g, '\\\\') | |
| .replace(/`/g, '\\`') | |
| .replace(/\$/g, '\\$') | |
| .replace(/'/g, "\\'") | |
| .replace(/\"/g, '\\"'); | |
| } | |
| export function formatDate(timestamp) { | |
| return timestamp?.toDate ? moment(timestamp.toDate()).format('HH:mm DD/MM/YYYY') : ''; | |
| } | |
| export function toggleButtonLoading(buttonId, isLoading) { | |
| const button = document.getElementById(buttonId); | |
| if (!button) return; | |
| const defaultText = button.getAttribute('data-original-text') || button.innerText; | |
| if (!button.hasAttribute('data-original-text')) { | |
| button.setAttribute('data-original-text', defaultText); | |
| } | |
| if (isLoading) { | |
| button.disabled = true; | |
| button.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i>Đang xử lý...'; | |
| button.classList.add('opacity-50', 'cursor-not-allowed'); | |
| } else { | |
| button.disabled = false; | |
| button.innerHTML = defaultText; | |
| button.classList.remove('opacity-50', 'cursor-not-allowed'); | |
| } | |
| } |