X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/905f0895c2fa97abaa331e8a667ada80128be19b..6ae326cb8d203015fa158b04e5b3b584f86c3654:/js/bs-modal.js diff --git a/js/bs-modal.js b/js/bs-modal.js index d87f6c1..2a9466a 100644 --- a/js/bs-modal.js +++ b/js/bs-modal.js @@ -6,13 +6,14 @@ * @param {string} footer - HTML for the footer * * Optional: - * @param {string} size - the bootstrap size category for modals (sm, lg, xl) - * @param {boolean} static - whether or not to make the backdrop static, forcing the user to respond to the dialog - * @param {boolean} show - whether or not to automatically show the modal + * @param {string|null} size - the bootstrap size category for modals (sm, lg, xl). Default is null. + * @param {boolean} static - whether or not to make the backdrop static, forcing the user to respond to the dialog. Default is false + * @param {boolean} show - whether or not to automatically show the modal. Default is false. + * @param {boolean} closebutton - display and allow the close button. Default is true. * @returns {string} returns the ID */ -function bsModal(title, body, footer, size = null, static = false, show = false) +function bsModal(title, body, footer, size = null, static = false, show = false, closebutton = true) { /* generate a random number between 1000 and 90000 to use as an id */ const min = 1000; @@ -46,9 +47,11 @@ function bsModal(title, body, footer, size = null, static = false, show = false) mHeader.classList.add("modal-header"); mHeader.id = id + "-header"; - mHeader.innerHTML =` - `; + mHeader.innerHTML =``; + + if (closebutton) + mHeader.innerHTML += ``; mBody.classList.add("modal-body"); mBody.id = id + "-body"; @@ -71,4 +74,187 @@ function bsModal(title, body, footer, size = null, static = false, show = false) if (show) $('#' + m1.id).modal('show'); + + return m1.id; +} + + +function create_plugin_info_modal(modname) +{ + let found = false; + fetch(BASE_URL + 'api/plugin.php') + .then(response => response.json()) // Parse the response as JSON + .then(data => { + for (let i = 0; data.list[i]; i++) + { + if (data.list[i].name == modname) + { + found = true; + const modal = bsModal( + "Information about " + data.list[i].title + "", // title + "
", + "
Close
", null, true, true, true + ); + let modalclose = document.getElementById(modal); + modalclose.addEventListener('click', (e) => { + $("#"+modal).modal('hide'); + }); + boobs = document.getElementById(modal + '-body'); + boobs.innerHTML = ""; + if (data.list[i].screenshot.length) + { + boobs.innerHTML += `
+ ` + data.list[i].screenshot[1] + ` style= +
`; + } + boobs.innerHTML += "

Description:
" + atob(data.list[i].readme.replace(["\n",""],["
","
"])) + "

"; + boobs.innerHTML += `
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Title`+data.list[i].title+`
Description`+data.list[i].description+`
Version`+data.list[i].version+`
Author`+data.list[i].author+`
Min Version Required`+data.list[i].minver+`
Max Version`+data.list[i].maxver+`
+
`; + } + } + if (!found) + { + bsModal("Hmmm. Something went wrong.", "It seems we can't find any information about that plugin! Maybe it's built-in? If not, please report this via GitHub or email. ", "", null, null, true, true); + } + }) + .catch(error => { + // Handle any errors that occur during the request + bsModal("Hmmm. Something went wrong.", "It seems we can't query our own API! Please report this via GitHub or email. ", "", null, null, true, true); + }); +} + + +function requestInstall(name, uninstall = false) +{ + let inst = (uninstall) ? "uninstall" : "install"; + var xhr = new XMLHttpRequest(); + + xhr.onload = function() { + if (xhr.status === 200) { + var response = JSON.parse(xhr.responseText); + console.log(response.success); + let install_button = document.getElementById(name+'install'); + if (response.success !== undefined) + { + if (install_button) + { + install_button.innerHTML = (inst == "uninstall") ? "Install" : "Uninstall"; + install_button.classList.replace('btn-secondary', (inst == "uninstall") ? 'btn-primary' : 'btn-outline-danger'); + setTimeout(() => { location.reload() }, 500); + } + } + else + { + if (install_button) + { + install_button.innerHTML = (inst == "uninstall") ? "Uninstall" : "Install"; + install_button.classList.replace('btn-secondary', (inst == "uninstall") ? 'btn-outline-danger' : 'btn-primary'); + setTimeout(() => { location.reload() }, 2000); + } + } + } + }; + + xhr.open('GET', BASE_URL + 'api/plugin.php?'+inst+'=' + name, true); + xhr.send(); + return true; +} + + +function create_plugin_info_modal(modname) +{ + let found = false; + fetch(BASE_URL + 'api/plugin.php') + .then(response => response.json()) // Parse the response as JSON + .then(data => { + for (let i = 0; data.list[i]; i++) + { + if (data.list[i].name == modname) + { + found = true; + const modal = bsModal( + "Information about " + data.list[i].title + "", // title + "
", + "
Close
", null, true, true, true + ); + let modalclose = document.getElementById(modal); + modalclose.addEventListener('click', (e) => { + $("#"+modal).modal('hide'); + }); + boobs = document.getElementById(modal + '-body'); + boobs.innerHTML = ""; + if (data.list[i].screenshot.length) + { + boobs.innerHTML += `
+ ` + data.list[i].screenshot[1] + ` style= +
`; + } + boobs.innerHTML += "

Description:
" + atob(data.list[i].readme.replace(["\n",""],["
","
"])) + "

"; + boobs.innerHTML += `
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Title`+data.list[i].title+`
Description`+data.list[i].description+`
Version`+data.list[i].version+`
Author`+data.list[i].author+`
Min Version Required`+data.list[i].minver+`
Max Version`+data.list[i].maxver+`
+
`; + } + } + if (!found) + { + bsModal("Hmmm. Something went wrong.", "It seems we can't find any information about that plugin! Maybe it's built-in? If not, please report this via GitHub or email. ", "", null, null, true, true); + } + }) + .catch(error => { + // Handle any errors that occur during the request + bsModal("Hmmm. Something went wrong.", "It seems we can't query our own API! Please report this via GitHub or email. ", "", null, null, true, true); + }); }