INIT
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// PocketBase auth bootstrap shared by pages
|
||||
(function (global) {
|
||||
const pb = new PocketBase('https://pocketbase.ccllc.pro');
|
||||
|
||||
function authHeaders() {
|
||||
if (pb.authStore.isValid && pb.authStore.token) {
|
||||
return { Authorization: `Bearer ${pb.authStore.token}` };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
function getDisplayName() {
|
||||
const model = pb.authStore.model || {};
|
||||
return (
|
||||
model.display_name ||
|
||||
model.name ||
|
||||
model.email ||
|
||||
model.username ||
|
||||
'Unknown'
|
||||
);
|
||||
}
|
||||
|
||||
async function ensureAuth() {
|
||||
if (pb.authStore.isValid) return true;
|
||||
const path = new URL(window.location.href).pathname;
|
||||
if (!path.endsWith('signin.html')) {
|
||||
window.location.href = 'signin.html';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
global.Auth = { pb, authHeaders, ensureAuth, getDisplayName };
|
||||
})(window);
|
||||
@@ -0,0 +1,459 @@
|
||||
<!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>
|
||||
<script src="https://cdn.jsdelivr.net/npm/pocketbase@0.26.5/dist/pocketbase.umd.js"></script>
|
||||
<script src="auth.js"></script>
|
||||
<style>
|
||||
|
||||
/* 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:hidden; touch-action: pan-y; height:100vh; display:flex; flex-direction:column;}
|
||||
.wrap{max-width:100%;box-sizing:border-box;margin:0;padding:16px;font-size:17px;display:flex;flex-direction:column;flex:1;overflow:hidden;}
|
||||
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 0.3s ease-out;}
|
||||
|
||||
/* 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;flex:1;overflow:auto;padding:0;}
|
||||
.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;white-space:pre-wrap;word-wrap:break-word;}
|
||||
#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;}
|
||||
|
||||
/* Footer */
|
||||
.footer{text-align:right;font-size:12px;color:var(--muted);margin-top:20px;padding-top:12px;border-top:1px solid #e5e7eb;}
|
||||
|
||||
/* responsive small */
|
||||
@media (max-width:380px){ .wrap{padding:12px;} .card{height:98px;} }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<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>Estimator</strong><br/>
|
||||
<label><input type="checkbox" class="filter-estimator" value="Steve Brewer"> Steve</label>
|
||||
<label><input type="checkbox" class="filter-estimator" value="Beth Cardoza"> Beth</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 class="footer">v1.0.0-beta2</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>
|
||||
|
||||
<script>
|
||||
(async function() {
|
||||
const { pb, authHeaders, ensureAuth, getDisplayName } = window.Auth;
|
||||
const authed = await ensureAuth();
|
||||
if (!authed) return;
|
||||
|
||||
// --- Utility ---
|
||||
const fetchNoCache = (url, options={}) => {
|
||||
const headers = { ...(options.headers||{}), ...authHeaders() };
|
||||
return fetch(url + `&_ts=${Date.now()}`, { ...options, headers });
|
||||
};
|
||||
const PB_COLLECTION_URL = "https://pocketbase.ccllc.pro/api/collections/pbc_1431294567/records";
|
||||
const NOTES_COLLECTION_URL = "https://pocketbase.ccllc.pro/api/collections/notes/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 progTimer=null;
|
||||
function startProgress(){
|
||||
progressBar.style.width='0%';
|
||||
if(progTimer) clearInterval(progTimer);
|
||||
let simulatedProg=0;
|
||||
progTimer=setInterval(()=>{
|
||||
if(simulatedProg<65){ simulatedProg+=0.8; progressBar.style.width=Math.min(65,simulatedProg).toFixed(1)+'%'; }
|
||||
},150);
|
||||
}
|
||||
function finishProgress(){ if(progTimer) clearInterval(progTimer); progressBar.style.width='100%'; setTimeout(()=>{progressBar.parentElement.style.display='none';},400); }
|
||||
|
||||
// --- Fetch all jobs ---
|
||||
async function fetchAllJobs(){
|
||||
startProgress(); jobsCache=[]; visibleJobs=[]; resultsEl.innerHTML = '<div style="padding:8px;color:#475569;background:#fff;border-radius:8px;border:1px solid #e6eefc">Loading…</div>';
|
||||
let page=1, totalItems=0; let firstBatchRendered=false;
|
||||
try{
|
||||
while(true){
|
||||
const url = `${PB_COLLECTION_URL}?page=${page}&perPage=${perPage}&sort=-Job_Number`;
|
||||
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));
|
||||
|
||||
// Render first 40 immediately
|
||||
if(!firstBatchRendered && jobsCache.length >= 40){
|
||||
firstBatchRendered=true;
|
||||
renderInitialBatch(jobsCache.slice(0,40));
|
||||
}
|
||||
|
||||
if(progTimer) clearInterval(progTimer);
|
||||
const realProg=Math.min(95, Math.floor((jobsCache.length / Math.max(1,totalItems)) * 95));
|
||||
progressBar.style.width=realProg+'%';
|
||||
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 renderInitialBatch(jobs){
|
||||
resultsEl.innerHTML='';
|
||||
for(const job of jobs){
|
||||
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 jobNumberValue(job){
|
||||
const raw = String(job.Job_Number||'');
|
||||
const match = raw.match(/[0-9]+\.?[0-9]*/);
|
||||
if(!match) return null;
|
||||
const num = parseFloat(match[0]);
|
||||
return isNaN(num) ? null : num;
|
||||
}
|
||||
|
||||
function sortJobsDescending(jobs){
|
||||
return jobs.sort((a,b)=>{
|
||||
const na = jobNumberValue(a);
|
||||
const nb = jobNumberValue(b);
|
||||
if(nb!==null && na!==null){ return nb - na; }
|
||||
if(nb!==null) return 1;
|
||||
if(na!==null) return -1;
|
||||
return String(b.Job_Number||'').localeCompare(String(a.Job_Number||''));
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
const estimatorVals = Array.from(document.querySelectorAll('.filter-estimator: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;
|
||||
if(estimatorVals.length && !estimatorVals.includes(job.Estimator||'')) return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
// Data already sorted from PocketBase, only re-sort if filters applied
|
||||
if(q || divisionVals.length || activeVals.length || statusVals.length || estimatorVals.length){
|
||||
sortJobsDescending(visibleJobs);
|
||||
}
|
||||
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; }
|
||||
|
||||
const firstChunk = list.slice(0,20);
|
||||
const remaining = list.slice(20);
|
||||
|
||||
for(const job of firstChunk){
|
||||
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);
|
||||
}
|
||||
|
||||
if(remaining.length){
|
||||
setTimeout(()=>{
|
||||
for(const job of remaining){
|
||||
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);
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
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-estimator').forEach(cb=>{ cb.addEventListener('change',()=>{
|
||||
if(cb.checked) document.querySelectorAll('.filter-estimator').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, .filter-estimator').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 now = new Date();
|
||||
const timestamp = now.toLocaleString('en-US', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: true });
|
||||
const currentUserName = getDisplayName();
|
||||
const formatted=`[${currentUserName} - ${timestamp}] [Job #${currentJob?.Job_Number||'N/A'}] ${html}\n\n`;
|
||||
const updatedNotes = formatted + (currentJob.Notes||'');
|
||||
try{
|
||||
const payloadNote = {
|
||||
Note: formatted.trim(),
|
||||
Job_Number: currentJob?.Job_Number || '', // text value
|
||||
Job_Number_Id: currentJob?.id || '' // id value
|
||||
};
|
||||
const userId = pb.authStore?.record?.id || pb.authStore?.model?.id;
|
||||
if (userId) payloadNote.user = userId;
|
||||
|
||||
const [resJob, resNote] = await Promise.all([
|
||||
fetch(`${PB_COLLECTION_URL}/${currentJob.id}`,{
|
||||
method:'PATCH',
|
||||
headers:{'Content-Type':'application/json', ...authHeaders()},
|
||||
body:JSON.stringify({Notes:updatedNotes})
|
||||
}),
|
||||
fetch(`${NOTES_COLLECTION_URL}`,{
|
||||
method:'POST',
|
||||
headers:{'Content-Type':'application/json', ...authHeaders()},
|
||||
body:JSON.stringify(payloadNote)
|
||||
})
|
||||
]);
|
||||
|
||||
if(!resJob.ok) throw new Error('Job_Info update failed: '+resJob.status);
|
||||
if(!resNote.ok){
|
||||
const errText = await resNote.text().catch(()=> '');
|
||||
throw new Error('Notes create failed: '+resNote.status+' '+errText);
|
||||
}
|
||||
|
||||
const updated=await resJob.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='';
|
||||
fetch('/log-change',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({action:'update-notes',user:currentUserName,target:currentJob.id,detail:'Job_Info notes updated + notes record created'})}).catch(()=>{});
|
||||
applyFiltersAndRender();
|
||||
}catch(err){alert('Error saving note: '+err.message); console.error(err);}
|
||||
});
|
||||
document.getElementById('btnClearNote').addEventListener('click',()=>newNote.innerHTML='');
|
||||
|
||||
// --- Init ---
|
||||
fetchAllJobs();
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,216 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Sign In</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/pocketbase@0.26.5/dist/pocketbase.umd.js"></script>
|
||||
<script src="auth.js"></script>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.container {
|
||||
background: white;
|
||||
padding: 3rem;
|
||||
border-radius: 1rem;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
|
||||
text-align: center;
|
||||
max-width: 400px;
|
||||
width: 90%;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
margin-bottom: 0.5rem;
|
||||
font-size: 1.75rem;
|
||||
}
|
||||
p {
|
||||
color: #666;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
button {
|
||||
background: #0078d4;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.875rem 2rem;
|
||||
font-size: 1rem;
|
||||
border-radius: 0.375rem;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
font-weight: 500;
|
||||
}
|
||||
button:hover:not(:disabled) {
|
||||
background: #005a9e;
|
||||
}
|
||||
button:disabled {
|
||||
background: #ccc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.user-info {
|
||||
display: none;
|
||||
margin-top: 2rem;
|
||||
text-align: left;
|
||||
background: #f8f9fa;
|
||||
padding: 1.5rem;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
.user-info h2 {
|
||||
font-size: 1.125rem;
|
||||
margin-bottom: 1rem;
|
||||
color: #333;
|
||||
}
|
||||
.user-info p {
|
||||
margin-bottom: 0.75rem;
|
||||
color: #555;
|
||||
word-break: break-all;
|
||||
}
|
||||
.user-info strong {
|
||||
color: #333;
|
||||
}
|
||||
.error {
|
||||
color: #d32f2f;
|
||||
margin-top: 1rem;
|
||||
display: none;
|
||||
}
|
||||
.logout-btn {
|
||||
background: #6c757d;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
.logout-btn:hover {
|
||||
background: #5a6268;
|
||||
}
|
||||
.notes-section {
|
||||
display: none;
|
||||
margin-top: 2rem;
|
||||
text-align: left;
|
||||
}
|
||||
.notes-section h3 {
|
||||
font-size: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
color: #333;
|
||||
}
|
||||
textarea {
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 0.375rem;
|
||||
font-family: inherit;
|
||||
font-size: 0.9rem;
|
||||
resize: vertical;
|
||||
min-height: 80px;
|
||||
}
|
||||
textarea:focus {
|
||||
outline: none;
|
||||
border-color: #0078d4;
|
||||
}
|
||||
.submit-btn {
|
||||
margin-top: 0.75rem;
|
||||
width: 100%;
|
||||
}
|
||||
.success {
|
||||
color: #2e7d32;
|
||||
margin-top: 0.75rem;
|
||||
display: none;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Welcome</h1>
|
||||
<p>Sign in with your Microsoft account</p>
|
||||
|
||||
<button id="loginBtn" onclick="login()">Sign in with Microsoft</button>
|
||||
|
||||
<div class="error" id="error"></div>
|
||||
|
||||
<div class="user-info" id="userInfo">
|
||||
<h2>Signed in</h2>
|
||||
<p><strong>Name:</strong> <span id="displayName"></span></p>
|
||||
<p><strong>Email:</strong> <span id="email"></span></p>
|
||||
|
||||
<button id="continueBtn" style="display:none;margin-top:1rem;" onclick="goToIndex()">Continue to Job Info</button>
|
||||
<button class="logout-btn" onclick="logout()">Sign out</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const { pb, getDisplayName } = window.Auth;
|
||||
|
||||
const loginBtn = document.getElementById('loginBtn');
|
||||
const errorEl = document.getElementById('error');
|
||||
const userInfo = document.getElementById('userInfo');
|
||||
const continueBtn = document.getElementById('continueBtn');
|
||||
|
||||
function goToIndex() {
|
||||
window.location.href = 'index.html';
|
||||
}
|
||||
|
||||
function showAuthedUI(displayName, email) {
|
||||
loginBtn.style.display = 'none';
|
||||
loginBtn.disabled = false;
|
||||
loginBtn.textContent = 'Sign in with Microsoft';
|
||||
userInfo.style.display = 'block';
|
||||
continueBtn.style.display = 'block';
|
||||
document.getElementById('displayName').textContent = displayName || 'Unknown';
|
||||
document.getElementById('email').textContent = email || 'Not available';
|
||||
}
|
||||
|
||||
async function login() {
|
||||
loginBtn.disabled = true;
|
||||
loginBtn.textContent = 'Signing in...';
|
||||
errorEl.style.display = 'none';
|
||||
|
||||
try {
|
||||
const authData = await pb.collection('users').authWithOAuth2({
|
||||
provider: 'microsoft',
|
||||
});
|
||||
displayUserInfo(authData);
|
||||
} catch (error) {
|
||||
console.error('Login failed:', error);
|
||||
errorEl.textContent = error.message || 'Authentication failed. Please try again.';
|
||||
errorEl.style.display = 'block';
|
||||
loginBtn.disabled = false;
|
||||
loginBtn.textContent = 'Sign in with Microsoft';
|
||||
}
|
||||
}
|
||||
|
||||
function logout() {
|
||||
pb.authStore.clear();
|
||||
loginBtn.style.display = 'block';
|
||||
userInfo.style.display = 'none';
|
||||
continueBtn.style.display = 'none';
|
||||
loginBtn.disabled = false;
|
||||
loginBtn.textContent = 'Sign in with Microsoft';
|
||||
}
|
||||
|
||||
function displayUserInfo(authData) {
|
||||
const displayName = getDisplayName();
|
||||
const email = authData?.meta?.rawUser?.email || authData?.record?.email || pb.authStore.model?.email || 'Not available';
|
||||
showAuthedUI(displayName, email);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
if (pb.authStore.isValid) {
|
||||
try {
|
||||
const authData = await pb.collection('users').authRefresh();
|
||||
displayUserInfo(authData);
|
||||
} catch (err) {
|
||||
pb.authStore.clear();
|
||||
logout();
|
||||
}
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user