Heera/public/assets/js/pages/api-key.init.js

1 line
12 KiB
JavaScript
Raw Permalink Normal View History

2024-05-16 03:46:08 +00:00
var checkAll=document.getElementById("checkAll"),perPage=(checkAll&&(checkAll.onclick=function(){for(var e=document.querySelectorAll('.form-check-all input[type="checkbox"]'),t=document.querySelectorAll('.form-check-all input[type="checkbox"]:checked').length,n=0;n<e.length;n++)e[n].checked=this.checked,e[n].checked?e[n].closest("tr").classList.add("table-active"):e[n].closest("tr").classList.remove("table-active");document.getElementById("remove-actions").style.display=0<t?"none":"block"}),8),options={valueNames:["id","name","createBy","apikey","status","create_date","expiry_date"],page:perPage,pagination:!0,plugins:[ListPagination({left:2,right:2})]},apiKeyList=new List("apiKeyList",options).on("updated",function(e){0==e.matchingItems.length?document.getElementsByClassName("noresult")[0].style.display="block":document.getElementsByClassName("noresult")[0].style.display="none";var t=1==e.i,n=e.i>e.matchingItems.length-e.page;document.querySelector(".pagination-prev.disabled")&&document.querySelector(".pagination-prev.disabled").classList.remove("disabled"),document.querySelector(".pagination-next.disabled")&&document.querySelector(".pagination-next.disabled").classList.remove("disabled"),t&&document.querySelector(".pagination-prev").classList.add("disabled"),n&&document.querySelector(".pagination-next").classList.add("disabled"),e.matchingItems.length<=perPage?document.querySelector(".pagination-wrap").style.display="none":document.querySelector(".pagination-wrap").style.display="flex",e.matchingItems.length==perPage&&document.querySelector(".pagination.listjs-pagination").firstElementChild.children[0].click(),0<e.matchingItems.length?document.getElementsByClassName("noresult")[0].style.display="none":document.getElementsByClassName("noresult")[0].style.display="block"});const xhttp=new XMLHttpRequest;function isStatus(e){switch(e){case"Disable":return'<span class="badge bg-danger-subtle text-danger">'+e+"</span>";case"Active":return'<span class="badge bg-success-subtle text-success">'+e+"</span>"}}xhttp.onload=function(){var e=JSON.parse(this.responseText);Array.from(e).forEach(function(e){apiKeyList.add({id:'<a href="javascript:void(0);" class="fw-medium link-primary">#VZ'+e.id+"</a>",name:e.name,createBy:e.createBy,apikey:'<input type="text" class="form-control apikey-value" readonly value="'+e.apikey+'">',status:isStatus(e.status),create_date:e.create_date,expiry_date:e.expiry_date}),apiKeyList.sort("id",{order:"desc"}),"Active"==e.status?document.querySelector(".disable-btn").innerHTML="Disable":"Disable"==e.status&&(document.querySelector(".disable-btn").innerHTML="Enable"),refreshCallbacks()}),apiKeyList.remove("id",'<a href="javascript:void(0);" class="fw-medium link-primary">#VZ001</a>')},xhttp.open("GET","assets/json/api-key-list.json"),xhttp.send(),document.getElementById("api-key-modal").addEventListener("show.bs.modal",function(e){e.relatedTarget.classList.contains("edit-item-btn")?(document.getElementById("exampleModalLabel").innerHTML="Rename API name",document.getElementById("api-key-modal").querySelector(".modal-footer").style.display="block",document.getElementById("add-btn").style.display="none",document.getElementById("createApi-btn").style.display="none",document.getElementById("edit-btn").style.display="block"):e.relatedTarget.classList.contains("create-btn")?(document.getElementById("exampleModalLabel").innerHTML="Create API Key",document.getElementById("api-key-modal").querySelector(".modal-footer").style.display="block",document.getElementById("edit-btn").style.display="none",document.getElementById("createApi-btn").style.display="block",document.getElementById("add-btn").style.display="none"):e.relatedTarget.classList.contains("regenerate-api-btn")&&(document.getElementById("exampleModalLabel").innerHTML="Regenerate API",document.getElementById("api-key-modal").querySelector(".modal-footer").style.display="block",document.getElementById("add-btn").style.display="none",document.getElementById("createApi-btn").style.display="none",document.getElementById("edit-btn").style.display="block")});var