Difference between revisions of "Widget:Multi upload"

From cm2.liecourt.com
(Created page with "<div id="imgTest" class="upload-preview"></div> <label for="files" class="attachment"><i class="fa fa-paperclip"></i><input type="file" id="files" name="files[]" class="d-non...")
 
m (Reverted edits by Maintenance script (talk) to last revision by Merel)
(Tag: Rollback)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
<noinclude>{{Managed
 +
|Version=1.0
 +
|Version notes=1.0 - First managed version
 +
|Short description=
 +
}}
 +
 +
This is the '''Widget:Multi upload''' page. It should be called in the following format:
 +
 +
<pre>
 +
{{&#35;widget:Multi upload }}
 +
</pre>
 +
 +
</noinclude><includeonly>
 
<div id="imgTest" class="upload-preview"></div>
 
<div id="imgTest" class="upload-preview"></div>
  
<label for="files" class="attachment"><i class="fa fa-paperclip"></i><input type="file" id="files" name="files[]" class="d-none" multiple /></label><button id="upload-button">Upload</button><script>
+
<label for="files" class="attachment"><i class="fa fa-paperclip"></i><input type="file" id="files" name="files[]" class="d-none" multiple /></label><script>
 +
 
 +
function uuidv4() {
 +
  return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
 +
    (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
 +
  );
 +
}
 +
 
 +
var uuid = uuidv4();
  
 
var filedate = Date.now();
 
var filedate = Date.now();
Line 10: Line 31:
  
 
function uploadFiles(evt){
 
function uploadFiles(evt){
 +
  evt.classList.add('pending');
 +
  evt.disabled = true;
 
var files = document.getElementById('files').files;
 
var files = document.getElementById('files').files;
 
var proms = [];  
 
var proms = [];  
Line 21: Line 44:
 
       console.log(values);
 
       console.log(values);
 
           console.log('done');
 
           console.log('done');
 
+
        var codeid = document.createElement('input');
 +
        codeid.setAttribute('type','hidden')
 +
        codeid.setAttribute('name','uuid')
 +
        codeid.setAttribute('value', uuid)
 +
        document.getElementById('files').closest('form').appendChild(codeid)
 +
        submitRealField()
 
     });
 
     });
  
Line 66: Line 94:
 
   var filesSelected = document.getElementById("files").files;
 
   var filesSelected = document.getElementById("files").files;
 
     if (filesSelected.length > 0) {
 
     if (filesSelected.length > 0) {
 
+
    document.getElementById("imgTest").innerHTML = '';
 
     for(i = 0; i < filesSelected.length; ++i){
 
     for(i = 0; i < filesSelected.length; ++i){
  
Line 97: Line 125:
  
 
function editFilePage(file){
 
function editFilePage(file){
 +
 
 +
 
 +
<!--{if (isset($edit) && $edit!="")}-->
 +
 
  
var newWikitextEdit = '{{File for case|Case file=<!--{$id}-->|File uploaded by=User:'+mw.user.getName()+'|type='+file.substr( file.length -3 )+'}}';
+
 +
  uuid = '<!--{$id}-->';
 +
 
 +
<!--{/if}-->
 +
 
 +
var newWikitextEdit = '{{File for case|Case file='+uuid+'|File uploaded by=User:'+mw.user.getName()+'|type='+file.substr( file.length -3 )+'}}';
  
  
Line 116: Line 153:
  
 
document.getElementById('files').addEventListener('change', handleFileSelect, false); //is a <input type="file" id="files" name="files[]" multiple />
 
document.getElementById('files').addEventListener('change', handleFileSelect, false); //is a <input type="file" id="files" name="files[]" multiple />
document.getElementById('upload-button').addEventListener('click', uploadFiles, false);
 
  
  
 
</script>
 
</script>
 +
 +
</includeonly>

Latest revision as of 12:37, 24 February 2022


This is the Widget:Multi upload page. It should be called in the following format:

{{#widget:Multi upload }}