402 lines
20 KiB
HTML
402 lines
20 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width,initial-scale=1" maximum-scale="1" />
|
||
<title>Job Info — Vanilla JS</title>
|
||
<style>
|
||
/*impersonate styling*/
|
||
body { font-family: sans-serif; margin: 0; }
|
||
#impersonationBanner {
|
||
position: fixed;
|
||
top: 0;
|
||
left: 0;
|
||
right: 0;
|
||
background: #ffcc00;
|
||
color: #000;
|
||
padding: 10px;
|
||
font-weight: bold;
|
||
text-align: center;
|
||
z-index: 9999;
|
||
display: none;
|
||
}
|
||
#impersonationBanner button {
|
||
margin-left: 10px;
|
||
padding: 4px 8px;
|
||
cursor: pointer;
|
||
}
|
||
|
||
/* Basic layout */
|
||
:root { --accent:#0d6efd; --muted:#6b7280; --card-bg:#ffffff; --card-border:#d1e7ff; }
|
||
body{font-family:Inter,Arial,Helvetica,sans-serif;background:#f3f4f6;margin:0;color:#111; overflow-x: hidden; touch-action: pan-y;}
|
||
.wrap{max-width:100%-5px;box-sizing:border-box;margin:18px auto;padding:16px;font-size:17px;}
|
||
h1{margin:0 0 12px;text-align:center;color:var(--accent);font-size:33px;font-weight:700;}
|
||
|
||
/* Progress */
|
||
.progress-wrap{width:100%;background:#e6edf7;height:6px;border-radius:4px;overflow:hidden;margin-bottom:12px;}
|
||
.progress-bar{height:100%;width:0;background:var(--accent);transition:width .18s linear;}
|
||
|
||
/* Search + filter toggle */
|
||
#searchBox{width:100%;padding:10px;border-radius:8px;border:1px solid #d1d5db;margin-bottom:8px;box-sizing:border-box;font-size: 18px;}
|
||
#searchBox::placeholder{color:#9ca3af;}
|
||
#filterToggle{background:var(--accent);color:#fff;padding:8px 10px;border-radius:8px;border:none;cursor:pointer;margin-bottom:8px;display:inline-block;}
|
||
|
||
/* Filters panel */
|
||
#filtersPanel{display:none;background:#fff;border:1px solid #e5e7eb;border-radius:8px;padding:10px;margin-bottom:10px;}
|
||
.filter-group{margin-bottom:8px;font-size:14px;}
|
||
.filter-group label{margin-right:8px;cursor:pointer;color:var(--muted);}
|
||
|
||
/* Results/cards */
|
||
#results{display:flex;flex-direction:column;gap:12px;max-height:56vh;overflow:auto;padding:4px;}
|
||
.card{background:var(--card-bg);border-radius:10px;padding:10px;border:1px solid #e6f0ff;box-shadow:0 6px 14px rgba(14,30,37,0.04);cursor:pointer;position:relative;display:flex;flex-direction:column;justify-content:center;box-sizing:border-box;gap:4px;}
|
||
.card-row{display:flex;align-items:center;gap:8px;font-size:18px;line-height:1.2;margin-bottom:2px;}
|
||
.card-label{font-weight:700;color:#374151;min-width:72px;white-space:nowrap;}
|
||
.card-info{color:#111;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;}
|
||
.active-dot{position:absolute;top:10px;right:10px;width:14px;height:14px;border-radius:999px;border:2px solid #fff;box-shadow:0 1px 2px rgba(0,0,0,0.12);}
|
||
|
||
/* Modal */
|
||
#detailModal{display:none;position:fixed;inset:0;background:rgba(0,0,0,0.45);align-items:flex-start;justify-content:center;padding-top:2vh;z-index:999;}
|
||
#detailBox{margin-block-start:0;margin-block-end:0;background:#fff;border-radius:10px;padding:2px 12px 6px 10px;max-width:380px;width:92%;max-height:84vh;overflow:auto;box-sizing:border-box;}
|
||
.h2{margin-top:0; margin-bottom:2px;margin-block-end:0;}
|
||
.detail-table{margin-top: 0;width:100%;border-collapse:collapse;margin-bottom:4px;}
|
||
.detail-table td{border:1px solid #eef2ff;padding:0px 6px 6px 6px;font-size:13px;vertical-align:top;}
|
||
.detail-table td.label{width:40%;background:#fbfdff;font-weight:700;color:#374151;}
|
||
#jobFolderLink{margin-bottom:10px;font-size:13px;}
|
||
#jobFolderLink a, #jobFolderLink span{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
|
||
|
||
/* Notes */
|
||
#jobNotes{min-height:120px;max-height:200px;overflow:auto;padding:4px;border:1px solid #e6e9ef;border-radius:4px;font-size:11px;background:transparent;}
|
||
#newNote{min-height:56px;max-height:120px;overflow:auto;padding:8px;border:1px solid #d7dbe3;border-radius:8px;font-size:16px;background:transparent;margin-top:6px;}
|
||
.toolbar{display:flex;flex-wrap:wrap;margin-bottom:3px;margin-top:5px} /* small space below toolbar */
|
||
.toolbar button{
|
||
height:28px;
|
||
width:32px;
|
||
font-size:12px;
|
||
padding:0 4px;
|
||
border-radius:6px;
|
||
border:1px solid #ccc;
|
||
background:#ccc;
|
||
color:#111;
|
||
cursor:pointer;
|
||
display:flex;
|
||
align-items:center;
|
||
justify-content:center;
|
||
margin: 1px;
|
||
}
|
||
.toolbar button#tbClear{
|
||
width:auto;
|
||
padding:4px 8px;
|
||
background:#9ca3af; /* slightly darker gray */
|
||
color:#fff;
|
||
}
|
||
.toolbar button.active{
|
||
background:#d1e7ff;
|
||
color:#111;
|
||
border-color:#0d6efd;
|
||
}
|
||
|
||
.modal-actions{display:flex;gap:8px;margin-top:6px;margin-bottom:50px;}
|
||
.btn{padding:8px 10px;border-radius:8px;border:none;color:#fff;cursor:pointer;}
|
||
.btn.green{background:#16a34a;} .btn.gray{background:#6b7280;} .btn.red{background:#dc2626;}
|
||
|
||
/* responsive small */
|
||
@media (max-width:380px){ .wrap{padding:12px;} .card{height:98px;} }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<!-- Load MSAL from CDN (required for vanilla) -->
|
||
<script src="https://alcdn.msauth.net/browser/2.36.1/js/msal-browser.min.js"></script>
|
||
<script type="module" src="/src/app.js"></script>
|
||
|
||
<!-- Banner UI for impersonation mode -->
|
||
<div id="impersonationBanner">
|
||
⚠️ Impersonation Mode Active – Actions are logged as the impersonated user
|
||
<button id="exitImpersonation">Return to Admin</button>
|
||
</div>
|
||
<div class="wrap">
|
||
<h1>Job Info</h1>
|
||
|
||
<div class="progress-wrap">
|
||
<div id="progressBar" class="progress-bar"></div>
|
||
</div>
|
||
|
||
<input id="searchBox" placeholder="Search jobs (just start typing)">
|
||
|
||
<button id="filterToggle">Show Filters</button>
|
||
|
||
<div id="filtersPanel">
|
||
<div class="filter-group">
|
||
<strong>Division</strong><br/>
|
||
<label><input type="checkbox" class="filter-division" value="C#"> Commercial</label>
|
||
<label><input type="checkbox" class="filter-division" value="R#"> Residential</label>
|
||
<label><input type="checkbox" class="filter-division" value="S#"> Small Jobs</label>
|
||
</div>
|
||
|
||
<div class="filter-group">
|
||
<strong>Active</strong><br/>
|
||
<label><input type="checkbox" class="filter-active" value="Yes"> Yes</label>
|
||
<label><input type="checkbox" class="filter-active" value="No"> No</label>
|
||
</div>
|
||
|
||
<div class="filter-group">
|
||
<strong>Status</strong><br/>
|
||
<label><input type="checkbox" class="filter-status" value="Estimating"> Estimating</label>
|
||
<label><input type="checkbox" class="filter-status" value="In Progress"> In Progress</label>
|
||
<label><input type="checkbox" class="filter-status" value="Awarded"> Awarded</label>
|
||
<label><input type="checkbox" class="filter-status" value="Billed (In Progress)"> Billed (In Progress)</label>
|
||
<label><input type="checkbox" class="filter-status" value="Not Bidding"> Not Bidding</label>
|
||
<label><input type="checkbox" class="filter-status" value="Est Sent"> Est Sent</label>
|
||
<label><input type="checkbox" class="filter-status" value="Not Awarded"> Not Awarded</label>
|
||
</div>
|
||
<button id="clearFilters" style="background:#6b7280;color:white;padding:8px;border-radius:8px;border:none;">Clear Filters</button>
|
||
</div>
|
||
|
||
<div id="results" aria-live="polite"></div>
|
||
</div>
|
||
|
||
<!-- Detail Modal -->
|
||
<div id="detailModal" role="dialog" aria-modal="true">
|
||
<div id="detailBox">
|
||
<h2 style="margin-top:0;color:var(--accent)">Job Detail</h2>
|
||
|
||
<table class="detail-table" id="detailTable"></table>
|
||
|
||
<div id="jobFolderLink"><strong>Job Folder Link</strong><div><span id="jobFolderAnchor">No Link Available</span></div></div>
|
||
|
||
<h3 style="margin:8px 0 6px 0">Notes</h3>
|
||
<div id="jobNotes"></div>
|
||
|
||
<div class="toolbar" id="toolbar">
|
||
<button data-cmd="bold" id="tbBold"><strong>B</strong></button>
|
||
<button data-cmd="italic" id="tbItalic"><em>I</em></button>
|
||
<button data-cmd="underline" id="tbUnderline"><u>U</u></button>
|
||
<button data-cmd="foreColor" data-val="#ff0000" id="tbRed" style="color:#ef4444">A</button>
|
||
<button data-cmd="foreColor" data-val="#0000ff" id="tbBlue" style="color:#2563eb">A</button>
|
||
<button data-cmd="foreColor" data-val="#000000" id="tbBlack" style="color:#000">A</button>
|
||
<button data-cmd="removeFormat" id="tbClear">Reset</button>
|
||
</div>
|
||
|
||
<div id="newNote" contenteditable="true" aria-label="New note"></div>
|
||
|
||
<div class="modal-actions">
|
||
<button class="btn green" id="btnSubmit">Submit</button>
|
||
<button class="btn gray" id="btnClearNote">Clear</button>
|
||
<button class="btn red" id="btnClose">Close</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="impersonationBanner" style="
|
||
display:none; position:fixed; top:0; left:0; right:0;
|
||
background:#ffcc00; color:#000; padding:10px; font-weight:bold;
|
||
text-align:center; z-index:9999;">
|
||
⚠️ Impersonation Mode Active — All actions are logged as the impersonated user
|
||
<button id="exitImpersonation"
|
||
style="margin-left:10px; padding:4px 8px; cursor:pointer;">Return to Admin</button>
|
||
</div>
|
||
|
||
<script>
|
||
(async function() {
|
||
// --- Tokens & impersonation ---
|
||
const impersonationToken = localStorage.getItem('pb_token');
|
||
const originalToken = localStorage.getItem('pb_original_token');
|
||
const banner = document.getElementById('impersonationBanner');
|
||
|
||
if (impersonationToken) {
|
||
if (window.pb) window.pb.authStore.save(impersonationToken, null);
|
||
banner.style.display = 'block';
|
||
}
|
||
|
||
// Exit impersonation button
|
||
document.getElementById('exitImpersonation')?.addEventListener('click', () => {
|
||
if (originalToken) {
|
||
localStorage.setItem('pb_token', originalToken);
|
||
localStorage.removeItem('pb_original_token');
|
||
} else {
|
||
localStorage.removeItem('pb_token');
|
||
}
|
||
banner.style.display = 'none';
|
||
location.reload();
|
||
});
|
||
|
||
window.addEventListener('keydown', e => {
|
||
if (e.ctrlKey && e.shiftKey && e.key.toLowerCase() === 'i') {
|
||
document.getElementById('exitImpersonation')?.click();
|
||
}
|
||
});
|
||
|
||
// --- Utility ---
|
||
const fetchNoCache = (url, options={}) => fetch(url + `&_ts=${Date.now()}`, options);
|
||
const PB_COLLECTION_URL = "http://10.10.1.109:8080/api/collections/pbc_1431294567/records";
|
||
const perPage = 50;
|
||
|
||
let jobsCache = [], visibleJobs = [], currentJob = null;
|
||
|
||
const progressBar = document.getElementById('progressBar');
|
||
const searchBox = document.getElementById('searchBox');
|
||
const resultsEl = document.getElementById('results');
|
||
const filtersPanel = document.getElementById('filtersPanel');
|
||
const filterToggle = document.getElementById('filterToggle');
|
||
|
||
const detailModal = document.getElementById('detailModal');
|
||
const detailTable = document.getElementById('detailTable');
|
||
const jobFolderAnchor = document.getElementById('jobFolderAnchor');
|
||
const jobNotes = document.getElementById('jobNotes');
|
||
const newNote = document.getElementById('newNote');
|
||
|
||
const toolbar = document.getElementById('toolbar');
|
||
const tbButtons = Array.from(toolbar.querySelectorAll('button'));
|
||
|
||
const safeLower = v => (v||'').toString().trim().toLowerCase();
|
||
|
||
let prog=0, progTimer=null;
|
||
function startProgress(){
|
||
prog=0; progressBar.style.width='0%';
|
||
if(progTimer) clearInterval(progTimer);
|
||
progTimer=setInterval(()=>{
|
||
if(prog<85){ prog+=Math.random()*6; progressBar.style.width=Math.min(85,prog).toFixed(2)+'%'; }
|
||
else clearInterval(progTimer);
|
||
},180);
|
||
}
|
||
function finishProgress(){ if(progTimer) clearInterval(progTimer); progressBar.style.width='100%'; setTimeout(()=>{progressBar.parentElement.style.display='none';},260); }
|
||
|
||
// --- Fetch all jobs ---
|
||
async function fetchAllJobs(){
|
||
startProgress(); jobsCache=[]; let page=1, totalItems=0;
|
||
try{
|
||
while(true){
|
||
const url = `${PB_COLLECTION_URL}?page=${page}&perPage=${perPage}`;
|
||
const res = await fetchNoCache(url);
|
||
if(!res.ok) throw new Error(`Fetch failed: ${res.status}`);
|
||
const data = await res.json();
|
||
const items = data.items || [];
|
||
jobsCache.push(...items);
|
||
totalItems = data.totalItems || (items.length + ((page-1)*perPage));
|
||
progressBar.style.width = Math.min(95, Math.floor((jobsCache.length / Math.max(1,totalItems)) * 95)) + '%';
|
||
if(jobsCache.length >= totalItems || items.length===0) break;
|
||
page++;
|
||
}
|
||
finishProgress();
|
||
applyFiltersAndRender();
|
||
}catch(err){ finishProgress(); alert('Failed to fetch jobs: '+err.message); console.error(err);}
|
||
}
|
||
|
||
function applyFiltersAndRender(){
|
||
const q = safeLower(searchBox.value||'');
|
||
const divisionVals = Array.from(document.querySelectorAll('.filter-division:checked')).map(i=>i.value);
|
||
const activeVals = Array.from(document.querySelectorAll('.filter-active:checked')).map(i=>i.value);
|
||
const statusVals = Array.from(document.querySelectorAll('.filter-status:checked')).map(i=>i.value);
|
||
|
||
visibleJobs = jobsCache.filter(job=>{
|
||
const searchable = [job.Job_Number, job.Job_Full_Name, job.Job_Address, job.Contact_Person, job.Company_Client, job.Notes].join(' ').toLowerCase();
|
||
if(q && !searchable.includes(q)) return false;
|
||
if(divisionVals.length && !divisionVals.includes(job.Job_Division)) return false;
|
||
if(activeVals.length && !activeVals.includes(job.Active)) return false;
|
||
if(statusVals.length && !statusVals.includes(job.Job_Status||'')) return false;
|
||
return true;
|
||
});
|
||
|
||
renderCards(visibleJobs);
|
||
}
|
||
|
||
function renderCards(list){
|
||
resultsEl.innerHTML='';
|
||
if(!list.length){ resultsEl.innerHTML = `<div style="padding:8px;color:#475569;background:#fff;border-radius:8px;border:1px solid #e6eefc">No results</div>`; return; }
|
||
for(const job of list){
|
||
const card=document.createElement('div'); card.className='card';
|
||
card.innerHTML=`
|
||
<div class="card-row"><div class="card-label">Job #:</div><div class="card-info">${escapeHtml(job.Job_Number||'')}</div></div>
|
||
<div class="card-row"><div class="card-label">Job Name:</div><div class="card-info">${escapeHtml(job.Job_Full_Name||'')}</div></div>
|
||
<div class="card-row"><div class="card-label">Contact:</div><div class="card-info">${escapeHtml(job.Contact_Person||'')}</div></div>
|
||
`;
|
||
const dot=document.createElement('div'); dot.className='active-dot';
|
||
dot.style.background=(String(job.Active||'').toLowerCase()==='yes')?'green':((String(job.Active||'').toLowerCase()==='no')?'red':'#cbd5e1');
|
||
card.appendChild(dot);
|
||
card.addEventListener('click',()=>openDetail(job));
|
||
resultsEl.appendChild(card);
|
||
}
|
||
}
|
||
function escapeHtml(str){ return String(str).replaceAll('&','&').replaceAll('<','<').replaceAll('>','>'); }
|
||
|
||
// --- Filters ---
|
||
filterToggle.addEventListener('click',()=>{ filtersPanel.style.display = filtersPanel.style.display==='block'?'none':'block'; filterToggle.textContent = filtersPanel.style.display==='block'?'Hide Filters':'Show Filters'; });
|
||
searchBox.addEventListener('input',()=>applyFiltersAndRender());
|
||
document.querySelectorAll('.filter-division').forEach(cb=>cb.addEventListener('change',()=>applyFiltersAndRender()));
|
||
document.querySelectorAll('.filter-active').forEach(cb=>{ cb.addEventListener('change',()=>{
|
||
if(cb.checked) document.querySelectorAll('.filter-active').forEach(o=>{if(o!==cb)o.checked=false;}); applyFiltersAndRender();
|
||
});});
|
||
document.querySelectorAll('.filter-status').forEach(cb=>cb.addEventListener('change',()=>applyFiltersAndRender()));
|
||
document.getElementById('clearFilters').addEventListener('click',()=>{
|
||
document.querySelectorAll('.filter-division, .filter-active, .filter-status').forEach(cb=>cb.checked=false);
|
||
applyFiltersAndRender();
|
||
});
|
||
|
||
// --- Modal & Notes ---
|
||
function openDetail(job){
|
||
currentJob = job;
|
||
detailTable.innerHTML = '';
|
||
const fields = ["Job_Full_Name","Job_Number","Company_Client","Manager","Contact_Person","Phone_Number","Job_Address","Start_Date","Tax_Exempt","Job_Status"];
|
||
for(const f of fields){
|
||
const tr = document.createElement('tr');
|
||
const tdLabel = document.createElement('td'); tdLabel.className='label'; tdLabel.textContent=f.replace(/_/g,' ');
|
||
const tdVal = document.createElement('td'); tdVal.textContent=job[f]||'';
|
||
tr.appendChild(tdLabel); tr.appendChild(tdVal); detailTable.appendChild(tr);
|
||
}
|
||
|
||
// Job folder link
|
||
jobFolderAnchor.innerHTML = '';
|
||
if(job.Job_Folder_Link && String(job.Job_Folder_Link).trim()!==''){
|
||
try{ const url=new URL(job.Job_Folder_Link); const a=document.createElement('a'); a.href=url.href; a.target='_blank'; a.rel='noopener noreferrer'; a.textContent=url.href; a.style.color='#0d6efd'; a.style.textDecoration='underline'; jobFolderAnchor.appendChild(a);
|
||
}catch(e){ jobFolderAnchor.textContent='No Link Available'; jobFolderAnchor.style.color='#374151'; jobFolderAnchor.style.textDecoration='none'; }
|
||
} else { jobFolderAnchor.textContent='No Link Available'; jobFolderAnchor.style.color='#374151'; jobFolderAnchor.style.textDecoration='none'; }
|
||
|
||
jobNotes.innerHTML = job.Notes || '';
|
||
newNote.innerHTML = '';
|
||
tbButtons.forEach(b=>b.classList.remove('active'));
|
||
detailModal.style.display='flex';
|
||
}
|
||
document.getElementById('btnClose').addEventListener('click',()=>{detailModal.style.display='none';});
|
||
|
||
// --- Toolbar ---
|
||
let savedSelection = null;
|
||
function saveSelection(){ const sel=window.getSelection(); if(sel.rangeCount>0)savedSelection=sel.getRangeAt(0);}
|
||
function restoreSelection(){ const sel=window.getSelection(); if(savedSelection){ sel.removeAllRanges(); sel.addRange(savedSelection);}}
|
||
newNote.addEventListener('mouseup',saveSelection); newNote.addEventListener('keyup',saveSelection); newNote.addEventListener('focus',saveSelection);
|
||
tbButtons.forEach(btn=>{
|
||
btn.addEventListener('mousedown', e=>{
|
||
e.preventDefault();
|
||
restoreSelection();
|
||
const cmd = btn.dataset.cmd;
|
||
if(!cmd) return;
|
||
if(cmd==='foreColor'){ const val=btn.dataset.val; document.execCommand(cmd,false,val); tbButtons.forEach(b=>{if(b.dataset.cmd==='foreColor'&&b!==btn)b.classList.remove('active');}); btn.classList.toggle('active'); }
|
||
else if(cmd==='removeFormat'){ restoreSelection(); const sel=window.getSelection(); if(sel.rangeCount>0){ const range=sel.getRangeAt(0); let content=range.toString(); range.deleteContents(); range.insertNode(document.createTextNode(content)); range.setStartAfter(range.startContainer); range.collapse(true); sel.removeAllRanges(); sel.addRange(range); } tbButtons.forEach(b=>b.classList.remove('active')); }
|
||
else{ document.execCommand(cmd,false,null); btn.classList.toggle('active'); }
|
||
newNote.focus(); saveSelection();
|
||
});
|
||
});
|
||
|
||
// --- Submit Note ---
|
||
document.getElementById('btnSubmit').addEventListener('click', async()=>{
|
||
const html=newNote.innerHTML.trim(); if(!html){alert('Enter note text'); return;}
|
||
const timestamp=new Date().toLocaleString();
|
||
const currentUserName = window.pb?.authStore?.model?.display_name || 'Unknown';
|
||
const formatted=`<p><strong>[${currentUserName} ${timestamp}]</strong> ${html}</p>`;
|
||
const updatedNotes = formatted + (currentJob.Notes||'');
|
||
try{
|
||
const res = await fetch(`${PB_COLLECTION_URL}/${currentJob.id}`,{method:'PATCH',headers:{'Content-Type':'application/json'},body:JSON.stringify({Notes:updatedNotes})});
|
||
if(!res.ok) throw new Error('Update failed: '+res.status);
|
||
const updated=await res.json();
|
||
const idx=jobsCache.findIndex(j=>j.id===currentJob.id); if(idx>=0) jobsCache[idx].Notes=updated.Notes; currentJob.Notes=updated.Notes;
|
||
jobNotes.innerHTML=updated.Notes; newNote.innerHTML='';
|
||
applyFiltersAndRender();
|
||
}catch(err){alert('Error saving note: '+err.message); console.error(err);}
|
||
});
|
||
document.getElementById('btnClearNote').addEventListener('click',()=>newNote.innerHTML='');
|
||
|
||
// --- Init ---
|
||
fetchAllJobs();
|
||
})();
|
||
</script>
|
||
v1.0.2
|
||
</body>
|
||
</html>
|