X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=assets%2Fdefault%2Fjs%2Fbase.js;h=2793882349ad9fd1503eef0bf5baf5681f9f2b0f;hb=949a0953109c2738ecd973c44cd728cddc120164;hp=8cc7eed59f735f87a1935e712de5e3a27e29740e;hpb=8eac2e54882d8adae8cbb45386dca1b465242632;p=github%2Fshaarli%2FShaarli.git diff --git a/assets/default/js/base.js b/assets/default/js/base.js index 8cc7eed5..27938823 100644 --- a/assets/default/js/base.js +++ b/assets/default/js/base.js @@ -25,12 +25,18 @@ function findParent(element, tagName, attributes) { /** * Ajax request to refresh the CSRF token. */ -function refreshToken() { +function refreshToken(basePath, callback) { const xhr = new XMLHttpRequest(); - xhr.open('GET', './?do=token'); + xhr.open('GET', `${basePath}/admin/token`); xhr.onload = () => { - const token = document.getElementById('token'); - token.setAttribute('value', xhr.responseText); + const elements = document.querySelectorAll('input[name="token"]'); + [...elements].forEach((element) => { + element.setAttribute('value', xhr.responseText); + }); + + if (callback) { + callback(xhr.response); + } }; xhr.send(); } @@ -215,6 +221,8 @@ function init(description) { } (() => { + const basePath = document.querySelector('input[name="js_base_path"]').value; + /** * Handle responsive menu. * Source: http://purecss.io/layouts/tucked-menu-vertical/ @@ -461,7 +469,7 @@ function init(description) { }); if (window.confirm(message)) { - window.location = `?delete_link&lf_linkdate=${ids.join('+')}&token=${token.value}`; + window.location = `${basePath}/admin/shaare/delete?id=${ids.join('+')}&token=${token.value}`; } }); } @@ -483,7 +491,8 @@ function init(description) { }); const ids = links.map(item => item.id); - window.location = `?change_visibility&token=${token.value}&newVisibility=${visibility}&ids=${ids.join('+')}`; + window.location = + `${basePath}/admin/shaare/visibility?token=${token.value}&newVisibility=${visibility}&id=${ids.join('+')}`; }); }); } @@ -546,7 +555,7 @@ function init(description) { const refreshedToken = document.getElementById('token').value; const fromtag = block.getAttribute('data-tag'); const xhr = new XMLHttpRequest(); - xhr.open('POST', './manage-tags'); + xhr.open('POST', `${basePath}/admin/tags`); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onload = () => { if (xhr.status !== 200) { @@ -558,8 +567,12 @@ function init(description) { input.setAttribute('value', totag); findParent(input, 'div', { class: 'rename-tag-form' }).style.display = 'none'; block.querySelector('a.tag-link').innerHTML = htmlEntities(totag); - block.querySelector('a.tag-link').setAttribute('href', `./?searchtags=${encodeURIComponent(totag)}`); - block.querySelector('a.rename-tag').setAttribute('href', `./manage-tags?fromtag=${encodeURIComponent(totag)}`); + block + .querySelector('a.tag-link') + .setAttribute('href', `${basePath}/?searchtags=${encodeURIComponent(totag)}`); + block + .querySelector('a.rename-tag') + .setAttribute('href', `${basePath}/admin/tags?fromtag=${encodeURIComponent(totag)}`); // Refresh awesomplete values existingTags = existingTags.map(tag => (tag === fromtag ? totag : tag)); @@ -567,7 +580,7 @@ function init(description) { } }; xhr.send(`renametag=1&fromtag=${encodeURIComponent(fromtag)}&totag=${encodeURIComponent(totag)}&token=${refreshedToken}`); - refreshToken(); + refreshToken(basePath); }); }); @@ -593,13 +606,13 @@ function init(description) { if (confirm(`Are you sure you want to delete the tag "${tag}"?`)) { const xhr = new XMLHttpRequest(); - xhr.open('POST', './manage-tags'); + xhr.open('POST', `${basePath}/admin/tags`); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onload = () => { block.remove(); }; xhr.send(encodeURI(`deletetag=1&fromtag=${tag}&token=${refreshedToken}`)); - refreshToken(); + refreshToken(basePath); existingTags = existingTags.filter(tagItem => tagItem !== tag); awesomepletes = updateAwesompleteList('.rename-tag-input', existingTags, awesomepletes); @@ -611,4 +624,15 @@ function init(description) { [...autocompleteFields].forEach((autocompleteField) => { awesomepletes.push(createAwesompleteInstance(autocompleteField)); }); + + const exportForm = document.querySelector('#exportform'); + if (exportForm != null) { + exportForm.addEventListener('submit', (event) => { + event.preventDefault(); + + refreshToken(basePath, () => { + event.target.submit(); + }); + }); + } })();