Widget:Multi upload: verschil tussen versies
Uit Dorpsbelang Den Hout
(8 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- | + | <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( | + | 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'); | |
− | + | // codeid.setAttribute('type','hidden') | |
− | + | // codeid.setAttribute('name','uuid') | |
− | + | // codeid.setAttribute('value', uuid) | |
− | + | // document.getElementById('files').closest('form').appendChild(codeid) | |
− | + | // 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", | + | 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 114: | Regel 119: | ||
for(i = 0; i < logos.length; ++i){ | for(i = 0; i < logos.length; ++i){ | ||
logos[i].src = srcData; | logos[i].src = srcData; | ||
+ | logos[i].srcset = ''; | ||
+ | logos[i].setAttribute('height', 'auto'); | ||
} | } | ||
// document.getElementById("imgTest").innerHTML = document.getElementById("imgTest").innerHTML+newImage.outerHTML; | // document.getElementById("imgTest").innerHTML = document.getElementById("imgTest").innerHTML+newImage.outerHTML; | ||
Regel 126: | Regel 133: | ||
} | } | ||
− | function editFilePage(file){ | + | function editFilePage(file, mode){ |
− | |||
− | |||
+ | 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:' | + | title: 'File:'+file, |
text: newWikitextEdit, | text: newWikitextEdit, | ||
format: 'json' | format: 'json' |
Huidige versie van 18 aug 2020 om 21:34
This is the Widget:Multi upload page. It should be called in the following format:
{{#widget:Multi upload }}