Widget:Multi upload: verschil tussen versies
Uit Dorpsbelang Den Hout
(6 tussenliggende versies door dezelfde gebruiker niet weergegeven) | |||
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 128: | 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 }}