Админские права: только admin может редактировать и удалять
This commit is contained in:
parent
b567fa7d09
commit
2349fdcccb
87
index.html
87
index.html
@ -535,6 +535,8 @@ function getAllUsers(){return{...getRegisteredUsers(),...PREDEFINED_USERS}}
|
||||
// ========== STATE ==========
|
||||
let currentUser=null,currentPanel='newAudit',editId=null,charts={};
|
||||
|
||||
function isAdmin(){return currentUser&¤tUser.login==='admin'}
|
||||
|
||||
// ========== INIT ==========
|
||||
function init(){
|
||||
document.getElementById('pabDate').value=new Date().toISOString().split('T')[0];
|
||||
@ -667,20 +669,24 @@ function initVioRows(){
|
||||
container.innerHTML=html;
|
||||
}
|
||||
|
||||
function makeVioRow(num){
|
||||
function makeVioRow(num,data){
|
||||
const d=data||{};
|
||||
const sel=v=>v===d.type?' selected':'';
|
||||
return `<div class="vio-grid" id="vioRow${num}" style="display:grid">
|
||||
<span class="vio-row-num">${num}</span>
|
||||
<input placeholder="Описание несоответствия" class="v-nc">
|
||||
<input placeholder="Исполнитель" class="v-exec">
|
||||
<select class="v-type"><option>Нарушение</option><option>Замечание</option><option>Риск</option></select>
|
||||
<input placeholder="Корректирующие меры" class="v-measure">
|
||||
<input placeholder="Ответственный" class="v-resp">
|
||||
<input type="date" class="v-date">
|
||||
<input placeholder="Форма завершения" class="v-done">
|
||||
<input placeholder="Описание несоответствия" class="v-nc" value="${escAttr(d.nc||'')}">
|
||||
<input placeholder="Исполнитель" class="v-exec" value="${escAttr(d.executor||'')}">
|
||||
<select class="v-type"><option${sel('Нарушение')}>Нарушение</option><option${sel('Замечание')}>Замечание</option><option${sel('Риск')}>Риск</option></select>
|
||||
<input placeholder="Корректирующие меры" class="v-measure" value="${escAttr(d.measure||'')}">
|
||||
<input placeholder="Ответственный" class="v-resp" value="${escAttr(d.responsible||'')}">
|
||||
<input type="date" class="v-date" value="${escAttr(d.date||'')}">
|
||||
<input placeholder="Форма завершения" class="v-done" value="${escAttr(d.done||'')}">
|
||||
<button class="remove-vio-btn" onclick="removeVioRow(${num})" title="Удалить">×</button>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function escAttr(s){return (s||'').replace(/&/g,'&').replace(/"/g,'"').replace(/</g,'<').replace(/>/g,'>')}
|
||||
|
||||
function addVioRow(){
|
||||
vioRowCount++;
|
||||
const row=makeVioRow(vioRowCount);
|
||||
@ -719,6 +725,7 @@ function getVioRows(){
|
||||
|
||||
// ========== AUDIT SUBMIT ==========
|
||||
function submitAudit(){
|
||||
if(editId&&!isAdmin()){alert('Только администратор может редактировать аудиты');return;}
|
||||
const location=document.getElementById('pabLocation').value.trim();
|
||||
if(!location){alert('Укажите место проведения ПАБ');return;}
|
||||
|
||||
@ -976,7 +983,11 @@ function renderHistory(){
|
||||
const noData=document.getElementById('noDataRow');
|
||||
if(audits.length===0){tbody.innerHTML='';noData.style.display='block';return;}
|
||||
noData.style.display='none';
|
||||
tbody.innerHTML=audits.map(a=>`
|
||||
tbody.innerHTML=audits.map(a=>{
|
||||
const adminBtns=isAdmin()?`<a class="view-link" onclick="editAudit(${a.id})" title="Редактировать">✏️</a>
|
||||
<button class="btn btn-danger btn-sm" style="margin-left:6px" onclick="deleteAudit(${a.id})">🗑️</button>`:
|
||||
`<span style="color:var(--gray-500);font-size:11px">только чтение</span>`;
|
||||
return `
|
||||
<tr>
|
||||
<td>${a.number||'—'}</td>
|
||||
<td>${a.date}</td>
|
||||
@ -986,12 +997,9 @@ function renderHistory(){
|
||||
<td>${a.workType||'—'}</td>
|
||||
<td><span class="badge ${a.overallSafe?'badge-safe':'badge-danger'}">${a.overallSafe?'Безопасно':'Нарушения'}</span></td>
|
||||
<td>${a.totalViolations||0}</td>
|
||||
<td>
|
||||
<a class="view-link" onclick="viewAudit(${a.id})">👁️</a>
|
||||
<button class="btn btn-danger btn-sm" style="margin-left:6px" onclick="deleteAudit(${a.id})">🗑️</button>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
<td>${adminBtns}</td>
|
||||
</tr>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function viewAudit(id){
|
||||
@ -1019,11 +1027,60 @@ function viewAudit(id){
|
||||
}
|
||||
|
||||
function deleteAudit(id){
|
||||
if(!isAdmin()){alert('Только администратор может удалять записи');return;}
|
||||
if(!confirm('Удалить этот аудит?'))return;
|
||||
saveAudits(getAudits().filter(a=>a.id!==id));
|
||||
renderHistory();
|
||||
}
|
||||
|
||||
function editAudit(id){
|
||||
if(!isAdmin()){alert('Только администратор может редактировать');return;}
|
||||
const a=getAudits().find(x=>x.id===id);
|
||||
if(!a)return;
|
||||
editId=id;
|
||||
document.getElementById('pabNumber').value=a.number||'';
|
||||
document.getElementById('pabDate').value=a.date||'';
|
||||
document.getElementById('pabTimeStart').value=a.timeStart||'';
|
||||
document.getElementById('pabTimeEnd').value=a.timeEnd||'';
|
||||
document.getElementById('pabLocation').value=a.location||'';
|
||||
document.getElementById('pabWorkType').value=a.workType||'';
|
||||
document.getElementById('pabWorkerCount').value=a.workerCount||1;
|
||||
document.getElementById('pabObserver').value=a.observer||'';
|
||||
document.getElementById('pabObserverRole').value=a.observerRole||'';
|
||||
document.getElementById('pabSupervisor').value=a.supervisor||'';
|
||||
document.getElementById('pabSupervisorRole').value=a.supervisorRole||'';
|
||||
setOverall(a.overallSafe?'safe':'danger');
|
||||
CATEGORIES.forEach(cat=>{
|
||||
const cdata=a.categories&&a.categories[cat.id];
|
||||
const items=cdata?cdata.items:[];
|
||||
items.forEach(it=>{
|
||||
const idx=cat.items.indexOf(it.item);
|
||||
if(idx>=0){
|
||||
const cb=document.getElementById('cb-'+cat.id+'-'+idx);
|
||||
if(cb){cb.checked=true; updateCheckItemUI(cat.id,idx);}
|
||||
if(it.other){
|
||||
const other=document.getElementById('other-'+cat.id);
|
||||
if(other){other.value=it.other; other.style.display='block'; other.classList.add('visible');}
|
||||
}
|
||||
}
|
||||
});
|
||||
const allSafe=items.length===0;
|
||||
document.getElementById('allSafeCb-'+cat.id).checked=allSafe;
|
||||
document.getElementById('allSafeToggle-'+cat.id).classList.toggle('active',allSafe);
|
||||
updateCatTotal(cat.id);
|
||||
});
|
||||
document.getElementById('vioRows').innerHTML='';
|
||||
if(a.violations&&a.violations.length>0){
|
||||
vioRowCount=a.violations.length;
|
||||
document.getElementById('vioRows').innerHTML=a.violations.map((v,i)=>makeVioRow(i+1,v)).join('');
|
||||
}else{
|
||||
vioRowCount=1;
|
||||
document.getElementById('vioRows').innerHTML=makeVioRow(1);
|
||||
}
|
||||
switchPanel('newAudit',document.querySelector('[data-panel="newAudit"]'));
|
||||
window.scrollTo({top:0,behavior:'smooth'});
|
||||
}
|
||||
|
||||
// ========== EXPORT CSV ==========
|
||||
function exportCSV(){
|
||||
const audits=getAudits();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user