fix: preventDefault on dragover/drop + proper file upload loop
This commit is contained in:
parent
657b715f29
commit
eaef9e9596
@ -59,7 +59,7 @@
|
||||
"widgettype": "VBox",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"cheight": 6,
|
||||
"cheight": 8,
|
||||
"bgcolor": "#f8f9fa",
|
||||
"padding": "16px",
|
||||
"css": "card",
|
||||
@ -77,7 +77,7 @@
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "script",
|
||||
"script": "var inp=document.createElement('input');inp.type='file';inp.multiple=true;inp.onchange=function(){var fd=new FormData();for(var f of inp.files){fd.append('file',f)};var xhr=new XMLHttpRequest();xhr.open('POST','/api/doc/upload?kb_id={{params_kw.kb_id}}&file_name='+encodeURIComponent(inp.files[0].name));xhr.onload=function(){var d=JSON.parse(xhr.responseText);if(d.status=='SUCCEEDED'){location.reload()}};xhr.send(inp.files[0])};inp.click()"
|
||||
"script": "(function(){var s=document.createElement('script');s.text='document.addEventListener(\"dragover\",function(e){e.preventDefault();e.stopPropagation()});document.addEventListener(\"drop\",function(e){e.preventDefault();e.stopPropagation();var files=e.dataTransfer.files;if(!files.length)return;for(var i=0;i<files.length;i++){var f=files[i];var xhr=new XMLHttpRequest();var kb=\"{{params_kw.kb_id}}\";xhr.open(\"POST\",\"/api/doc/upload?kb_id=\"+kb+\"&file_name=\"+encodeURIComponent(f.name));xhr.onload=function(){if(xhr.status===200){location.reload()}};xhr.send(f)}}});var inp=document.createElement(\"input\");inp.type=\"file\";inp.multiple=true;inp.onchange=function(){for(var j=0;j<inp.files.length;j++){var f=inp.files[j];var xhr=new XMLHttpRequest();var kb=\"{{params_kw.kb_id}}\";xhr.open(\"POST\",\"/api/doc/upload?kb_id=\"+kb+\"&file_name=\"+encodeURIComponent(f.name));xhr.onload=function(){if(xhr.status===200){location.reload()}};xhr.send(f)}};inp.click()';document.body.appendChild(s)})()"
|
||||
}]
|
||||
}
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user