fix: idbPut reads first then opens tx; file metadata synced to localStorage for reports
This commit is contained in:
parent
0890704801
commit
4494b455f7
32
index.html
32
index.html
@ -975,14 +975,17 @@ function openDB(cb){
|
||||
r.onsuccess=function(e){gdb=e.target.result;cb(gdb)};
|
||||
r.onerror=function(){cb(null)}
|
||||
}
|
||||
function idbPut(id,blob,name,size,type,cb){
|
||||
openDB(function(db){if(!db){cb(false);return}
|
||||
var tx=db.transaction("files","readwrite");var st=tx.objectStore("files");
|
||||
var fr=new FileReader();fr.onload=function(){
|
||||
function idbPut(id,file,name,size,type,cb){
|
||||
var fr=new FileReader();
|
||||
fr.onload=function(){
|
||||
openDB(function(db){if(!db){cb(false);return}
|
||||
var tx=db.transaction("files","readwrite");var st=tx.objectStore("files");
|
||||
st.put({id:id,name:name,size:size,type:type,data:fr.result});
|
||||
tx.oncomplete=function(){cb(true)};tx.onerror=function(){cb(false)}
|
||||
};fr.readAsArrayBuffer(new Blob([blob],{type:type||"application/octet-stream"}))
|
||||
})
|
||||
})
|
||||
};
|
||||
fr.onerror=function(){cb(false)};
|
||||
fr.readAsArrayBuffer(file)
|
||||
}
|
||||
function idbGetAll(prefix,cb){
|
||||
openDB(function(db){if(!db){cb([]);return}
|
||||
@ -1324,7 +1327,8 @@ function openEv(id,subIdx){
|
||||
h+="<button class='btn btn-sm' style='margin-left:8px;background:#E2E8F0;color:#0B1A2E' onclick='closeModal()'>Отмена</button></div>";
|
||||
h+="</div>";
|
||||
showModal(h);
|
||||
idbGetAll(fk+"_m"+selMonth,function(files){
|
||||
var fk2=fk+"_m"+selMonth;
|
||||
idbGetAll(fk2,function(files){
|
||||
var fdiv=document.getElementById("fl_"+e.id);if(!fdiv)return;
|
||||
if(!files||!files.length){fdiv.innerHTML="\u041D\u0435\u0442 \u0444\u0430\u0439\u043B\u043E\u0432";return}
|
||||
var fh="";var groups={};
|
||||
@ -1338,9 +1342,8 @@ function openEv(id,subIdx){
|
||||
for(var j=0;j<groups[bi].length;j++){
|
||||
var f=groups[bi][j];var kb=Math.round(f.size/1024);
|
||||
var sz=kb<1024?kb+" KB":(kb/1024).toFixed(1)+" MB";
|
||||
var d=new Date(f.name.length>0?0:0);var ds="";
|
||||
try{var dd=new Date(parseInt(f.id.split("_").pop()));ds=dd.getDate()+"."+String(dd.getMonth()+1).padStart(2,"0")+"."+dd.getFullYear()}catch(e){}
|
||||
fh+="<div class='file-item'><span class='fn'>"+esc(f.name)+"</span><span class='fs'>("+sz+(ds?", "+ds:"")+")</span><a onclick='idbGet(\""+f.id+"\",function(ff){if(!ff)return;var blob=new Blob([ff.data],{type:ff.type||\"\"});var url=URL.createObjectURL(blob);var a=document.createElement(\"a\");a.href=url;a.download=ff.name;document.body.appendChild(a);a.click();document.body.removeChild(a);setTimeout(function(){URL.revokeObjectURL(url)},5000)})'>\u0421\u043A\u0430\u0447\u0430\u0442\u044C</a><a style='color:#EF4444;margin-left:4px' onclick='idbDel(\""+f.id+"\",function(o){if(o)openEv("+e.id+(subIdx!==undefined?","+subIdx:"")+")})'>\u0423\u0434\u0430\u043B\u0438\u0442\u044C</a></div>"
|
||||
var ds="";var ts=parseInt(f.id.split("_").pop());if(ts>100000){var dd=new Date(ts);ds=dd.getDate()+"."+String(dd.getMonth()+1).padStart(2,"0")+"."+dd.getFullYear()}
|
||||
fh+="<div class='file-item'><span class='fn'>"+esc(f.name)+"</span><span class='fs'>("+sz+(ds?", "+ds:"")+")</span><a onclick="idbGet('"+f.id+"',function(ff){if(!ff)return;var b=new Blob([ff.data],{type:ff.type||''});var u=URL.createObjectURL(b);var a=document.createElement('a');a.href=u;a.download=ff.name;document.body.appendChild(a);a.click();document.body.removeChild(a);setTimeout(function(){URL.revokeObjectURL(u)},5000)})">\u0421\u043A\u0430\u0447\u0430\u0442\u044C</a><a style='color:#EF4444;margin-left:4px' onclick="idbDel('"+f.id+"',function(o){if(o)openEv("+e.id+(subIdx!==undefined?","+subIdx:"")+")})">\u0423\u0434\u0430\u043B\u0438\u0442\u044C</a></div>"
|
||||
}
|
||||
}
|
||||
fdiv.innerHTML=fh||"\u041D\u0435\u0442 \u0444\u0430\u0439\u043B\u043E\u0432"
|
||||
@ -1378,6 +1381,13 @@ function saveEvModal(id){
|
||||
if(inn)try{localStorage.setItem("sn_"+id+"_m"+mv,inn.value.trim())}catch(e){}
|
||||
if(inq)try{localStorage.setItem("sq_"+id+"_m"+mv,(parseInt(inq.value,10)||0).toString())}catch(e){}
|
||||
}
|
||||
var fk="sf_"+id;var mk=inm?"_m"+inm.value:"_m0";
|
||||
idbGetAll(fk+mk,function(files){
|
||||
if(files&&files.length){
|
||||
var meta=[];for(var i=0;i<files.length;i++){meta.push({n:files[i].name,s:files[i].size})}
|
||||
try{localStorage.setItem("rpt_"+fk+mk,JSON.stringify(meta))}catch(e){}
|
||||
}
|
||||
});
|
||||
saveEv();
|
||||
closeModal();
|
||||
renderEv()
|
||||
@ -2045,6 +2055,6 @@ function dlAnalyticsWord(){
|
||||
var a=document.createElement("a");a.href=URL.createObjectURL(blob);a.download="analytics.doc";a.click()
|
||||
}
|
||||
|
||||
</script></script></script></script>
|
||||
</script></script></script></script></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user