diff --git a/web/khira/app.js b/web/khira/app.js index fa037a1..6e24fec 100644 --- a/web/khira/app.js +++ b/web/khira/app.js @@ -247,9 +247,27 @@ function fld(n,l,o={}){ const rad=(n,items,cur)=>`
${items.map(([v,l])=>``).join('')}
`; function dlg(o){ - const d=$('#dlg');d.className=o.wide?'wide':''; - d.innerHTML=`

${o.title}

${o.sub?`

${o.sub}

`:''}
${o.body}
${o.alt?``:''}
`; + const d=$('#dlg'); + d.className = 'app-modal-dialog' + (o.wide ? ' wide' : ''); + d.innerHTML = `
+
+
+

${o.title}

+ ${o.sub ? `

${o.sub}

` : ''} +
+ +
+
${o.body}
+
+ ${o.alt ? `` : ''} + + +
+
`; const f=d.querySelector('form'); + f.querySelectorAll('[data-x]').forEach(btn => { + btn.onclick = () => { if(d.open) d.close(); }; + }); if(o.alt)f.querySelector('[data-alt]').onclick=o.alt[1]; if(o.init)o.init(f); f.onsubmit=async e=>{ @@ -2234,131 +2252,247 @@ function adminRollbackDB(){ /* โ”€โ”€ Profile & Avatar Selector โ”€โ”€ */ function profile(){ - const cur=S.u; - const isAdm=cur.username==='admin'||cur.role==='team_lead'||cur.role==='lead'; - let curType=cur.avatar_type||'emoji'; - let curEmoji=cur.avatar||'๐Ÿ‘ค'; - let curImgUrl=cur.profile_image||''; + const cur = S.u; + let curImgUrl = cur.profile_image || ''; + let curType = curImgUrl ? 'image' : (cur.avatar_type || 'initials'); + let curColor = cur.avatar_color || getUserColor(cur.username); - const updatePreview=()=>{ - const prevWrap=$('#avPreview'); - if(!prevWrap)return; - const tempUser={...cur,avatar_type:curType,avatar:curEmoji,profile_image:curImgUrl}; - prevWrap.innerHTML=avHtml(tempUser,88); + const getPreviewHtml = (imgUrl, color, name) => { + if (imgUrl) { + return `
+ ${esc(name || cur.name || '')} +
`; + } + const inits = getInitials(name || cur.name || cur.username); + return `
+ ${inits} +
`; }; + const colors = [ + { name: 'Blue', hex: '#3b82f6' }, + { name: 'Emerald', hex: '#10b981' }, + { name: 'Indigo', hex: '#6366f1' }, + { name: 'Amber', hex: '#f59e0b' }, + { name: 'Rose', hex: '#f43f5e' }, + { name: 'Purple', hex: '#8b5cf6' }, + { name: 'Cyan', hex: '#06b6d4' }, + { name: 'Slate', hex: '#475569' } + ]; + dlg({ - title:'Profile Settings', - sub:`@${cur.username} ยท ${cur.role_display}`, - wide:1, - body:` -
-
-
- - -
-
-
- ${isAdm?``:''} - ${EMOJIS.map(e=>``).join('')} + title: 'Account & Profile Settings', + sub: `@${cur.username} ยท ${cur.role_display}`, + wide: 1, + body: ` +
+
${getPreviewHtml(curImgUrl, curColor, cur.name)}
+
+

${esc(cur.name || cur.username)}

+
+ ${esc(cur.role_display)} + @${esc(cur.username)}
-
-
-
- - -

PNG, JPG or WebP. Max 5MB.

+
+ + +
- ${fld('name','Full name',{req:1,v:cur.name})} - - - + +
+ +
+ ${colors.map(c => ` + + `).join('')} +
+
+ +
+
+ + +
+ +
+ +
+ + ${ic('lock', 14)} +
+
+ +
+ + +
+ +
+ + +
+
+ +
+
+
+ ${ic('lock', 16)} + Change Password +
+ Optional +
+ +
+ + + + `, - ok:'Save Changes', - alt:['Sign out',async()=>{await api('/khira/api/auth/logout','POST');localStorage.removeItem('khira_active_user');location.reload()}], - init:f=>{ - updatePreview(); - const tabs=f.querySelectorAll('#avModeTabs button'); - const paneE=f.querySelector('#paneEmoji'); - const paneI=f.querySelector('#paneImage'); - const hidType=f.querySelector('#hidAvType'); - const hidEmoji=f.querySelector('#hidAvEmoji'); - const hidImg=f.querySelector('#hidAvImg'); + ok: 'Save Changes', + alt: ['Sign out', async () => { + await api('/khira/api/auth/logout', 'POST'); + localStorage.removeItem('khira_session_token'); + localStorage.removeItem('khira_active_user'); + location.reload(); + }], + init: f => { + const prev = f.querySelector('#profileAvatarPreview'); + const fileInp = f.querySelector('#profileFileInput'); + const btnUp = f.querySelector('#btnUploadPhoto'); + const btnInits = f.querySelector('#btnUseInitials'); + const hidImg = f.querySelector('#hidProfImg'); + const hidColor = f.querySelector('#hidProfColor'); + const hidType = f.querySelector('#hidProfType'); + const nameInp = f.querySelector('#profNameInp'); + const colorSec = f.querySelector('#initialsColorSection'); - tabs.forEach(btn=>{ - btn.onclick=()=>{ - tabs.forEach(b=>b.classList.remove('on')); - btn.classList.add('on'); - curType=btn.dataset.avm; - hidType.value=curType; - if(curType==='emoji'){ - paneE.hidden=false;paneI.hidden=true; - }else{ - paneE.hidden=true;paneI.hidden=false; - } - updatePreview(); + const refreshPreview = () => { + prev.innerHTML = getPreviewHtml(curImgUrl, curColor, nameInp.value); + colorSec.hidden = !!curImgUrl; + }; + + nameInp.addEventListener('input', refreshPreview); + + btnUp.onclick = () => fileInp.click(); + + btnInits.onclick = () => { + curImgUrl = ''; + curType = 'initials'; + hidImg.value = ''; + hidType.value = 'initials'; + refreshPreview(); + toast('Switched to initials avatar'); + }; + + f.querySelectorAll('.color-swatch-btn').forEach(b => { + b.onclick = () => { + f.querySelectorAll('.color-swatch-btn').forEach(btn => btn.classList.remove('active')); + b.classList.add('active'); + curColor = b.dataset.color; + hidColor.value = curColor; + refreshPreview(); }; }); - f.querySelectorAll('.av-opt').forEach(opt=>{ - opt.onclick=()=>{ - f.querySelectorAll('.av-opt').forEach(b=>b.classList.remove('on')); - opt.classList.add('on'); - curEmoji=opt.dataset.emoji; - hidEmoji.value=curEmoji; - curType='emoji'; - hidType.value='emoji'; - updatePreview(); - }; - }); - - const fileInp=f.querySelector('#avFileInput'); - if(fileInp){ - fileInp.onchange=async()=>{ - const file=fileInp.files[0]; - if(!file)return; - const fd=new FormData(); - fd.append('file',file); - try{ - toast('Uploading avatar photo...'); - const un=S.u?.username||ls('khira_active_user'); - const tok=ls('khira_session_token'); - const upHeaders={'X-Khira-User':un}; - if(tok)upHeaders['Authorization']='Bearer '+tok; - const upRes=await fetch('/khira/api/upload',{method:'POST',headers:upHeaders,credentials:'same-origin',body:fd}); - const upJson=await upRes.json(); - const url=upJson.url||upJson.attachment?.url; - if(url){ - curImgUrl=url; - hidImg.value=curImgUrl; - curType='image'; - hidType.value='image'; - tabs.forEach(b=>b.classList.toggle('on',b.dataset.avm==='image')); - paneE.hidden=true;paneI.hidden=false; - updatePreview(); - toast('Avatar uploaded'); - } - }catch(err){ - console.error('Failed to upload avatar',err); - toast('Failed to upload image','err'); + fileInp.onchange = async () => { + const file = fileInp.files[0]; + if (!file) return; + const fd = new FormData(); + fd.append('file', file); + try { + toast('Uploading avatar photo...'); + const un = S.u?.username || ls('khira_active_user'); + const tok = ls('khira_session_token'); + const upHeaders = { 'X-Khira-User': un }; + if (tok) upHeaders['Authorization'] = 'Bearer ' + tok; + const upRes = await fetch('/khira/api/upload', { + method: 'POST', + headers: upHeaders, + credentials: 'same-origin', + body: fd + }); + const upJson = await upRes.json(); + const url = upJson.url || upJson.attachment?.url; + if (url) { + curImgUrl = url; + curType = 'image'; + hidImg.value = url; + hidType.value = 'image'; + refreshPreview(); + toast('Avatar uploaded successfully'); + } else { + toast(upJson.error || 'Failed to upload image', 'err'); } - }; - } + } catch (err) { + toast('Failed to upload image', 'err'); + } + }; + + // Toggle Security accordion + const toggleBtn = f.querySelector('#btnToggleSecurity'); + const secBody = f.querySelector('#securityBody'); + toggleBtn.onclick = () => { + secBody.hidden = !secBody.hidden; + }; }, - go:async v=>{ - const r=await api('/khira/api/auth/profile','PUT',{ - name:v.name, - avatar_type:v.avatar_type, - avatar:v.avatar, - profile_image:v.profile_image - }); - if(r._f){toast(r.error||'Failed to update profile','err');return false} - S.u=r.user||{...S.u,...v}; + go: async v => { + // Validate password if supplied + if (v.new_password) { + if (!v.current_password) { + toast('Please enter your current password to set a new password', 'err'); + return false; + } + if (v.new_password.length < 6) { + toast('New password must be at least 6 characters', 'err'); + return false; + } + if (v.new_password !== v.confirm_password) { + toast('New passwords do not match', 'err'); + return false; + } + } + + const payload = { + name: v.name, + avatar_type: v.avatar_type || curType, + avatar: cur.avatar || '๐Ÿ‘ค', + profile_image: v.profile_image + }; + if (v.new_password) { + payload.current_password = v.current_password; + payload.new_password = v.new_password; + } + + const r = await api('/khira/api/auth/profile', 'PUT', payload); + if (r._f) { + toast(r.error || 'Failed to update profile', 'err'); + return false; + } + + S.u = r.user || { ...S.u, ...payload }; updateMe(S.u); - toast('Profile updated'); + toast('Profile updated successfully'); await refresh(); } }); diff --git a/web/khira/index.html b/web/khira/index.html index 9d04ee2..c8ca3d8 100644 --- a/web/khira/index.html +++ b/web/khira/index.html @@ -9,7 +9,7 @@ - + @@ -447,6 +447,6 @@
- + diff --git a/web/khira/styles.css b/web/khira/styles.css index a029c8e..402a598 100644 --- a/web/khira/styles.css +++ b/web/khira/styles.css @@ -2150,22 +2150,489 @@ button { z-index: 60; } -/* Generic Modal Dialog */ +/* โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• + Modal Dialog Framework & Unified Form System + โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• */ .app-modal-dialog { margin: auto; border: 1px solid var(--border-default); - border-radius: 10px; + border-radius: 12px; background: var(--bg-surface); color: var(--text-primary); - box-shadow: var(--shadow-lg); - padding: 24px; - max-width: 540px; - width: 90vw; + box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--border-subtle); + padding: 0; + width: min(540px, 94vw); + max-height: 88vh; + overflow: hidden; + outline: none; + z-index: 80; +} + +.app-modal-dialog.wide { + width: min(720px, 95vw); } .app-modal-dialog::backdrop { - background: rgba(0, 0, 0, 0.6); - backdrop-filter: blur(2px); + background: rgba(0, 0, 0, 0.7); + backdrop-filter: blur(4px); +} + +/* Dialog Shell (Form) */ +.dc { + display: flex; + flex-direction: column; + height: 100%; + max-height: 88vh; + overflow: hidden; +} + +/* Dialog Header */ +.dh { + padding: 18px 24px; + border-bottom: 1px solid var(--border-subtle); + background: var(--bg-surface); + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 16px; + flex-shrink: 0; +} + +.dh-titles h3 { + font-size: 17px; + font-weight: 600; + color: var(--text-primary); + letter-spacing: -0.01em; + margin: 0; + line-height: 1.3; +} + +.dh-titles .sub { + font-size: 13px; + color: var(--text-secondary); + margin-top: 3px; +} + +/* Dialog Body */ +.db { + padding: 24px; + overflow-y: auto; + display: flex; + flex-direction: column; + gap: 16px; + flex-grow: 1; +} + +/* Dialog Actions Footer */ +.da { + padding: 16px 24px; + border-top: 1px solid var(--border-subtle); + background: var(--bg-canvas); + display: flex; + align-items: center; + justify-content: flex-end; + gap: 10px; + flex-shrink: 0; +} + +/* Buttons in Dialog */ +.fb { + height: 34px; + padding: 0 16px; + border-radius: 6px; + background: var(--primary); + color: #ffffff; + font-size: 13px; + font-weight: 600; + border: none; + cursor: pointer; + display: inline-flex; + align-items: center; + justify-content: center; + gap: 6px; + transition: all 0.15s ease; +} + +.fb:hover { + background: var(--primary-hover); + transform: translateY(-1px); +} + +.fb:active { + transform: translateY(0); +} + +.tb { + height: 34px; + padding: 0 14px; + border-radius: 6px; + background: var(--bg-surface-elevated); + color: var(--text-secondary); + border: 1px solid var(--border-default); + font-size: 13px; + font-weight: 500; + cursor: pointer; + display: inline-flex; + align-items: center; + justify-content: center; + transition: all 0.15s ease; +} + +.tb:hover { + background: var(--bg-surface-hover); + color: var(--text-primary); + border-color: var(--border-hover); +} + +.btn-alt { + height: 34px; + padding: 0 14px; + border-radius: 6px; + background: rgba(239, 68, 68, 0.1); + color: #f87171; + border: 1px solid rgba(239, 68, 68, 0.25); + font-size: 13px; + font-weight: 500; + cursor: pointer; + display: inline-flex; + align-items: center; + justify-content: center; + gap: 6px; + margin-right: auto; + transition: all 0.15s ease; +} + +.btn-alt:hover { + background: rgba(239, 68, 68, 0.2); + color: #ef4444; + border-color: rgba(239, 68, 68, 0.4); +} + +/* โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• + Form Control Standards (.fld, .grp, .rg) + โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• */ +.fld { + display: flex; + flex-direction: column-reverse; + gap: 6px; + width: 100%; +} + +.fld span { + font-size: 11px; + font-weight: 600; + text-transform: uppercase; + letter-spacing: 0.04em; + color: var(--text-muted); +} + +.fld input, +.fld select, +.fld textarea { + width: 100%; + height: 36px; + padding: 0 12px; + border-radius: 6px; + background: var(--bg-input); + border: 1px solid var(--border-default); + color: var(--text-primary); + font-family: var(--font-sans); + font-size: 13px; + outline: none; + transition: border-color 0.15s ease, box-shadow 0.15s ease; +} + +.fld input:focus, +.fld select:focus, +.fld textarea:focus { + border-color: var(--primary); + box-shadow: 0 0 0 2px var(--primary-subtle); +} + +.fld textarea { + height: auto; + min-height: 80px; + padding: 10px 12px; + resize: vertical; + line-height: 1.5; +} + +.fld select { + cursor: pointer; +} + +.fld.mono input, +.fld.mono textarea { + font-family: var(--font-mono); + font-size: 12px; +} + +/* Radio Group (.rg) */ +.rg { + display: flex; + gap: 8px; + background: var(--bg-canvas); + padding: 4px; + border-radius: 8px; + border: 1px solid var(--border-subtle); +} + +.rg label { + flex: 1; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; + margin: 0; +} + +.rg label input[type="radio"] { + display: none; +} + +.rg label span { + width: 100%; + padding: 6px 12px; + text-align: center; + border-radius: 6px; + font-size: 12px; + font-weight: 500; + color: var(--text-secondary); + transition: all 0.15s ease; +} + +.rg label input[type="radio"]:checked + span { + background: var(--bg-surface-elevated); + color: var(--text-primary); + font-weight: 600; + box-shadow: var(--shadow-sm); +} + +/* Fieldset groups (.grp) */ +.grp { + border: 1px solid var(--border-subtle); + border-radius: 8px; + padding: 16px; + margin: 0; + display: flex; + flex-direction: column; + gap: 14px; + background: var(--bg-card); +} + +/* โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• + Enterprise Profile & Account Settings + โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• */ +.profile-card-hero { + display: flex; + align-items: center; + gap: 20px; + padding: 18px 20px; + background: var(--bg-card); + border: 1px solid var(--border-subtle); + border-radius: 10px; +} + +.profile-avatar-wrap { + width: 76px; + height: 76px; + border-radius: 50%; + overflow: hidden; + display: flex; + align-items: center; + justify-content: center; + border: 2px solid var(--border-default); + box-shadow: var(--shadow-md); + flex-shrink: 0; +} + +.profile-avatar-img { + width: 100%; + height: 100%; + object-fit: cover; +} + +.profile-avatar-initials { + font-size: 28px; + font-weight: 700; + letter-spacing: -0.02em; + font-family: var(--font-sans); +} + +.profile-hero-info { + display: flex; + flex-direction: column; + gap: 6px; + flex-grow: 1; +} + +.profile-hero-info h4 { + font-size: 16px; + font-weight: 600; + color: var(--text-primary); + margin: 0; +} + +.profile-tags-row { + display: flex; + align-items: center; + gap: 8px; +} + +.profile-avatar-actions { + display: flex; + align-items: center; + gap: 8px; + margin-top: 6px; +} + +.profile-palette-section { + display: flex; + flex-direction: column; + gap: 8px; + padding: 12px 16px; + background: var(--bg-card); + border: 1px solid var(--border-subtle); + border-radius: 8px; +} + +.section-micro-label { + font-size: 11px; + font-weight: 600; + text-transform: uppercase; + letter-spacing: 0.04em; + color: var(--text-muted); +} + +.color-swatches-grid { + display: flex; + align-items: center; + gap: 10px; +} + +.color-swatch-btn { + width: 24px; + height: 24px; + border-radius: 50%; + background: var(--swatch); + border: 2px solid transparent; + cursor: pointer; + transition: transform 0.15s ease, border-color 0.15s ease; + padding: 0; +} + +.color-swatch-btn:hover { + transform: scale(1.15); +} + +.color-swatch-btn.active { + border-color: #ffffff; + box-shadow: 0 0 0 2px var(--swatch); + transform: scale(1.1); +} + +.profile-fields-grid { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 14px; +} + +@media (max-width: 600px) { + .profile-fields-grid { + grid-template-columns: 1fr; + } +} + +.profile-form-group { + display: flex; + flex-direction: column; + gap: 6px; +} + +.profile-form-group label { + font-size: 11px; + font-weight: 600; + text-transform: uppercase; + letter-spacing: 0.04em; + color: var(--text-muted); +} + +.profile-form-group input { + width: 100%; + height: 36px; + padding: 0 12px; + border-radius: 6px; + background: var(--bg-input); + border: 1px solid var(--border-default); + color: var(--text-primary); + font-size: 13px; + outline: none; + transition: border-color 0.15s ease, box-shadow 0.15s ease; +} + +.profile-form-group input:focus { + border-color: var(--primary); + box-shadow: 0 0 0 2px var(--primary-subtle); +} + +.profile-form-group input:disabled, +.profile-form-group input[readonly] { + background: var(--bg-canvas); + color: var(--text-secondary); + border-color: var(--border-subtle); + cursor: not-allowed; +} + +.input-with-lock { + position: relative; + display: flex; + align-items: center; +} + +.input-with-lock input { + padding-right: 32px; +} + +.input-with-lock .lock-icon { + position: absolute; + right: 10px; + color: var(--text-muted); + display: flex; + align-items: center; + pointer-events: none; +} + +/* Security & Password Accordion */ +.profile-security-accordion { + border: 1px solid var(--border-subtle); + border-radius: 8px; + background: var(--bg-card); + overflow: hidden; +} + +.security-accordion-header { + padding: 12px 16px; + display: flex; + align-items: center; + justify-content: space-between; + cursor: pointer; + background: var(--bg-card); + transition: background 0.15s ease; +} + +.security-accordion-header:hover { + background: var(--bg-surface-hover); +} + +.security-accordion-header strong { + font-size: 13px; + font-weight: 600; + color: var(--text-primary); +} + +.security-accordion-body { + padding: 0 16px 16px 16px; + border-top: 1px solid var(--border-subtle); } /* Responsive adjustments */