Widget:Multi upload: verschil tussen versies

Uit Dorpsbelang Den Hout
Ga naar:navigatie, zoeken
(Nieuwe pagina aangemaakt met '<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...')
 
 
(9 tussenliggende versies door dezelfde gebruiker niet weergegeven)
Regel 14: Regel 14:
 
<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><script>
+
<label for="files" class="attachment"><i class="fa fa-edit"></i><input type="file" id="files" name="files[]" class="d-none" multiple /></label><script>
  
 
function uuidv4() {
 
function uuidv4() {
Regel 30: Regel 30:
 
}
 
}
  
function uploadFiles(evt){
+
function uploadFiles(mode){
 
var files = document.getElementById('files').files;
 
var files = document.getElementById('files').files;
 
var proms = [];  
 
var proms = [];  
 
     for(i = 0; i < files.length; ++i){
 
     for(i = 0; i < files.length; ++i){
 
         file = files[i];
 
         file = files[i];
 +
      if(mode == "logo"){
 +
        var fileName = document.querySelector('input[name="Domein"]').value.replace('.','-')+'-logo.png';
 +
      }else{
 
         var fileName = files[i].name;
 
         var fileName = files[i].name;
var prom =  doApiCall(file, fileName);
+
        }
 +
var prom =  doApiCall(file, fileName, mode);
 
         proms.push(prom)
 
         proms.push(prom)
 
     }
 
     }
Regel 42: Regel 46:
 
       console.log(values);
 
       console.log(values);
 
           console.log('done');
 
           console.log('done');
        var codeid = document.createElement('input');
+
      //  var codeid = document.createElement('input');
        codeid.setAttribute('type','hidden')
+
      //  codeid.setAttribute('type','hidden')
        codeid.setAttribute('name','uuid')
+
      //  codeid.setAttribute('name','uuid')
        codeid.setAttribute('value', uuid)
+
    //    codeid.setAttribute('value', uuid)
        document.getElementById('files').closest('form').appendChild(codeid)
+
    //    document.getElementById('files').closest('form').appendChild(codeid)
        submitRealField()
+
    //  submitRealField()
 +
  document.getElementById('real-submit').click();
 
     });
 
     });
  
Regel 53: Regel 58:
  
  
function doApiCall(fileToUpload,fileName){
+
function doApiCall(fileToUpload,fileName, mode){
 
return new Promise(function(resolve, reject){
 
return new Promise(function(resolve, reject){
 
formdata = new FormData();  
 
formdata = new FormData();  
 
formdata.append("action", "upload");
 
formdata.append("action", "upload");
formdata.append("filename", filedate+fileName);
+
formdata.append("filename", fileName);
 
//formdata.append("filename", fileName);
 
//formdata.append("filename", fileName);
 
formdata.append("token", mw.user.tokens.get( 'editToken' ) );
 
formdata.append("token", mw.user.tokens.get( 'editToken' ) );
Regel 78: Regel 83:
 
                         resolve(data)
 
                         resolve(data)
 
                 //  setTimeout(function(){
 
                 //  setTimeout(function(){
                       editFilePage(fileName);
+
                       editFilePage(fileName, mode);
 
                 //  },100)
 
                 //  },100)
 
},
 
},
Regel 111: Regel 116:
 
         newImage.src = srcData;
 
         newImage.src = srcData;
  
         document.getElementById("imgTest").innerHTML = document.getElementById("imgTest").innerHTML+newImage.outerHTML;
+
         var logos = document.querySelectorAll('[alt="Logo.png"]'), i;
 +
        for(i = 0; i < logos.length; ++i){
 +
          logos[i].src = srcData;
 +
          logos[i].srcset = '';
 +
          logos[i].setAttribute('height', 'auto');
 +
        }
 +
      //  document.getElementById("imgTest").innerHTML = document.getElementById("imgTest").innerHTML+newImage.outerHTML;
 
       //  alert("Converted Base64 version is " + document.getElementById("imgTest").innerHTML);
 
       //  alert("Converted Base64 version is " + document.getElementById("imgTest").innerHTML);
 
     //  console.log("Converted Base64 version is " + document.getElementById("imgTest").innerHTML);
 
     //  console.log("Converted Base64 version is " + document.getElementById("imgTest").innerHTML);
Regel 122: Regel 133:
 
}
 
}
  
function editFilePage(file){
+
function editFilePage(file, mode){
 
 
var newWikitextEdit = '{{File for case|Case file='+uuid+'|File uploaded by=User:'+mw.user.getName()+'|type='+file.substr( file.length -3 )+'}}';
 
  
 +
  if(mode == "logo"){
 +
    var newWikitextEdit = '{{Domein logo|Domein='+document.querySelector('input[name="Domein"]').value+'|File uploaded by=User:'+mw.user.getName()+'|type='+file.substr( file.length -3 )+'}}';
 +
  }else{
 +
      var newWikitextEdit = '{{Bericht file|Bericht='+document.querySelector('input[name="Domein"]').value.replace('.','-')+'/'+document.querySelector('input[name="Titel"]').value.replace(' ','-')+'|Domein='+document.querySelector('input[name="Domein"]').value+'|File uploaded by=User:'+mw.user.getName()+'|type='+file.substr( file.length -3 )+'}}';
 +
  }
  
 
     var params = {
 
     var params = {
 
         action: 'edit',
 
         action: 'edit',
         title: 'File:'+filedate+file,
+
         title: 'File:'+file,
 
         text: newWikitextEdit,
 
         text: newWikitextEdit,
 
         format: 'json'
 
         format: 'json'

Huidige versie van 18 aug 2020 om 21:34

Sjabloon:Managed

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

{{#widget:Multi upload }}