aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/common/js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/common/js')
-rw-r--r--assets/common/js/thumbnails-update.js14
1 files changed, 8 insertions, 6 deletions
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 @@
10 * It contains a recursive call to retrieve the thumb of the next link when it succeed. 10 * It contains a recursive call to retrieve the thumb of the next link when it succeed.
11 * It also update the progress bar and other visual feedback elements. 11 * It also update the progress bar and other visual feedback elements.
12 * 12 *
13 * @param {string} basePath Shaarli subfolder for XHR requests
13 * @param {array} ids List of LinkID to update 14 * @param {array} ids List of LinkID to update
14 * @param {int} i Current index in ids 15 * @param {int} i Current index in ids
15 * @param {object} elements List of DOM element to avoid retrieving them at each iteration 16 * @param {object} elements List of DOM element to avoid retrieving them at each iteration
16 */ 17 */
17function updateThumb(ids, i, elements) { 18function updateThumb(basePath, ids, i, elements) {
18 const xhr = new XMLHttpRequest(); 19 const xhr = new XMLHttpRequest();
19 xhr.open('POST', '?do=ajax_thumb_update'); 20 xhr.open('PATCH', `${basePath}/admin/shaare/${ids[i]}/update-thumbnail`);
20 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 21 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
21 xhr.responseType = 'json'; 22 xhr.responseType = 'json';
22 xhr.onload = () => { 23 xhr.onload = () => {
@@ -29,17 +30,18 @@ function updateThumb(ids, i, elements) {
29 elements.current.innerHTML = i; 30 elements.current.innerHTML = i;
30 elements.title.innerHTML = response.title; 31 elements.title.innerHTML = response.title;
31 if (response.thumbnail !== false) { 32 if (response.thumbnail !== false) {
32 elements.thumbnail.innerHTML = `<img src="${response.thumbnail}">`; 33 elements.thumbnail.innerHTML = `<img src="${basePath}/${response.thumbnail}">`;
33 } 34 }
34 if (i < ids.length) { 35 if (i < ids.length) {
35 updateThumb(ids, i, elements); 36 updateThumb(basePath, ids, i, elements);
36 } 37 }
37 } 38 }
38 }; 39 };
39 xhr.send(`id=${ids[i]}`); 40 xhr.send();
40} 41}
41 42
42(() => { 43(() => {
44 const basePath = document.querySelector('input[name="js_base_path"]').value;
43 const ids = document.getElementsByName('ids')[0].value.split(','); 45 const ids = document.getElementsByName('ids')[0].value.split(',');
44 const elements = { 46 const elements = {
45 progressBar: document.querySelector('.progressbar > div'), 47 progressBar: document.querySelector('.progressbar > div'),
@@ -47,5 +49,5 @@ function updateThumb(ids, i, elements) {
47 thumbnail: document.querySelector('.thumbnail-placeholder'), 49 thumbnail: document.querySelector('.thumbnail-placeholder'),
48 title: document.querySelector('.thumbnail-link-title'), 50 title: document.querySelector('.thumbnail-link-title'),
49 }; 51 };
50 updateThumb(ids, 0, elements); 52 updateThumb(basePath, ids, 0, elements);
51})(); 53})();