X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=assets%2Fcommon%2Fjs%2Fthumbnails-update.js;h=3cd4c2a761f778989e682ee181421200abe012cc;hb=c94c32d1a3e86a479cb2582eadc668a5bb476fc6;hp=b66ca3ae1e5114bc8e3d2a73abb29d8b0d389a6d;hpb=905f8675a728841b03b300d2c7dc909a1c4f7f03;p=github%2Fshaarli%2FShaarli.git diff --git a/assets/common/js/thumbnails-update.js b/assets/common/js/thumbnails-update.js index b66ca3ae..3cd4c2a7 100644 --- a/assets/common/js/thumbnails-update.js +++ b/assets/common/js/thumbnails-update.js @@ -10,13 +10,14 @@ * It contains a recursive call to retrieve the thumb of the next link when it succeed. * It also update the progress bar and other visual feedback elements. * + * @param {string} basePath Shaarli subfolder for XHR requests * @param {array} ids List of LinkID to update * @param {int} i Current index in ids * @param {object} elements List of DOM element to avoid retrieving them at each iteration */ -function updateThumb(ids, i, elements) { +function updateThumb(basePath, ids, i, elements) { const xhr = new XMLHttpRequest(); - xhr.open('POST', '?do=ajax_thumb_update'); + xhr.open('PATCH', `${basePath}/admin/shaare/${ids[i]}/update-thumbnail`); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.responseType = 'json'; xhr.onload = () => { @@ -29,17 +30,18 @@ function updateThumb(ids, i, elements) { elements.current.innerHTML = i; elements.title.innerHTML = response.title; if (response.thumbnail !== false) { - elements.thumbnail.innerHTML = ``; + elements.thumbnail.innerHTML = ``; } if (i < ids.length) { - updateThumb(ids, i, elements); + updateThumb(basePath, ids, i, elements); } } }; - xhr.send(`id=${ids[i]}`); + xhr.send(); } (() => { + const basePath = document.querySelector('input[name="js_base_path"]').value; const ids = document.getElementsByName('ids')[0].value.split(','); const elements = { progressBar: document.querySelector('.progressbar > div'), @@ -47,5 +49,5 @@ function updateThumb(ids, i, elements) { thumbnail: document.querySelector('.thumbnail-placeholder'), title: document.querySelector('.thumbnail-link-title'), }; - updateThumb(ids, 0, elements); + updateThumb(basePath, ids, 0, elements); })();