diff --git a/index.html b/index.html
index 1e694ff..311e7ba 100644
--- a/index.html
+++ b/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 `
${num}
-
-
-
-
-
-
-
+
+
+
+
+
+
+
`;
}
+function escAttr(s){return (s||'').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()?`✏️
+ `:
+ `только чтение`;
+ return `
| ${a.number||'—'} |
${a.date} |
@@ -986,12 +997,9 @@ function renderHistory(){
${a.workType||'—'} |
${a.overallSafe?'Безопасно':'Нарушения'} |
${a.totalViolations||0} |
-
- 👁️
-
- |
-
- `).join('');
+ ${adminBtns} |
+ `;
+ }).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();