diff --git a/eli-library.js b/eli-library.js index e400379..9ecc5de 100755 --- a/eli-library.js +++ b/eli-library.js @@ -889,3 +889,102 @@ function doneBTN(data=""){ document.querySelector(".modal.active")?.classList.remove('active'); },3000) } + + +function doneFormBTN(data="",embed=false){ + var tag = "Success"; + var tag2 = "success"; + + if(typeof data == 'string'){ + var datax = data; + } + else + { + var datax = data.result; + } + +if(embed){ + document.querySelector(embed).innerHTML = datax; +} +else +{ + if(datax.indexOf(tag) !== -1 || datax.indexOf(tag2) !== -1){ + + const Toast = Swal.mixin({ + toast: true, + position: 'top-end', + showConfirmButton: false, + timer: 1500, + timerProgressBar: true, + onOpen: (toast) => { + toast.addEventListener('mouseenter', Swal.stopTimer) + toast.addEventListener('mouseleave', Swal.resumeTimer) + } + }) + + Toast.fire({ + icon: 'success', + title: datax + }) + + var type = "success"; + + + } + else + { + + const Toast = Swal.mixin({ + toast: true, + position: 'top-end', + showConfirmButton: false, + timer: 3000, + timerProgressBar: true, + onOpen: (toast) => { + toast.addEventListener('mouseenter', Swal.stopTimer) + toast.addEventListener('mouseleave', Swal.resumeTimer) + } + }) + + Toast.fire({ + icon: 'error', + title: datax + }) + + + var type = "fail"; + } +} + + + +// =================== + + + document.querySelector(".processbtn")?.classList.add("donebtn"); + document.querySelector(".processbtn")?.classList.add(type); + document.querySelector(".processbtn")?.classList.remove("processbtn"); + + setTimeout(function(){ + document.querySelector(".donebtn")?.classList.remove(type); + document.querySelector(".donebtn")?.classList.remove("donebtn"); + document.querySelector(".modal.active")?.classList.remove('active'); + },3000) +} + + +function eliFormBTN(el){ + // Correct the typo in getAttribute + var action = el.getAttribute("action"); + var datax = el.getAttribute("data") || ""; + var method = el.getAttribute("method") || 'POST'; + var embed = el.getAttribute("embed") || false; // Convert string to boolean + + // Encode datax properly for URL encoding + datax = encodeURIComponent(datax); + el.classList.add("processbtn"); + // Assuming epost is a defined function that handles the request + epost(action, "data=" + datax, function(data){ + doneFormBTN(data,embed); + }); +} \ No newline at end of file diff --git a/eli.js b/eli.js index 2a6e5a2..10ef234 100755 --- a/eli.js +++ b/eli.js @@ -327,6 +327,16 @@ window.addEventListener('load', async function(){ setTimeout(UpdateFields,3000); } + // FormBTN + if(document.querySelector('formbtn')){ + document.querySelectorAll('formbtn').forEach(fbtn=>{ + fbtn.addEventListener("click",function(e){ + eliFormBTN(fbtn); + }) + }) + } + + await checkmobility(); // == Loading ==