master_template/public/assets/js/pages/file-manager.init.js

1 line
14 KiB
JavaScript
Raw Normal View History

2024-06-10 12:21:58 +00:00
function getChartColorsArray(e){if(null!==document.getElementById(e))return e=document.getElementById(e).getAttribute("data-colors"),(e=JSON.parse(e)).map(function(e){var t=e.replace(" ","");return-1===t.indexOf(",")?getComputedStyle(document.documentElement).getPropertyValue(t)||t:2==(e=e.split(",")).length?"rgba("+getComputedStyle(document.documentElement).getPropertyValue(e[0])+","+e[1]+")":t})}var options,chart,chartDonutBasicColors=getChartColorsArray("simple_dount_chart"),url=(chartDonutBasicColors&&(options={series:[27.01,20.87,33.54,37.58],chart:{height:330,type:"donut"},legend:{position:"bottom"},labels:["Documents","Media","Others","Free Space"],dataLabels:{dropShadow:{enabled:!1}},colors:chartDonutBasicColors},(chart=new ApexCharts(document.querySelector("#simple_dount_chart"),options)).render()),"assets/json/"),allFileList="",editFlag=!1,getJSON=function(e,t){var l=new XMLHttpRequest;l.open("GET",url+e,!0),l.responseType="json",l.onload=function(){var e=l.status;t(200===e?null:e,l.response)},l.send()};function loadFileData(e){document.querySelector("#file-list").innerHTML="",Array.from(e).forEach(function(e,t){var l=e.fileName.includes(".")?function(e){switch(e){case"png":case"jpg":return'<i class="ri-gallery-fill align-bottom text-success"></i>';case"pdf":return'<i class="ri-file-pdf-fill align-bottom text-danger"></i>';default:return'<i class="ri-file-text-fill align-bottom text-secondary"></i>'}}(e.fileName.split(".")[1]):'<i class="ri-folder-2-fill align-bottom text-warning"></i>',i=e.starred?"active":"";document.querySelector("#file-list").innerHTML+='<tr> <td> <input class="form-control filelist-id" type="hidden" value="'+e.id+'" id="filelist-'+e.id+'"> <div class="d-flex align-items-center"> <div class="flex-shrink-0 fs-17 me-2 filelist-icon">'+l+'</div> <div class="flex-grow-1 filelist-name">'+e.fileName+'</div> <div class="d-none filelist-type">'+e.filetype+"</div> </div> </td> <td>"+e.fileItem+'</td> <td class="filelist-size">'+e.fileSize+'</td> <td class="filelist-create">'+e.date+'</td> <td> <div class="d-flex gap-3 justify-content-center"> <button type="button" class="btn btn-ghost-primary btn-icon btn-sm favourite-btn '+i+'"> <i class="ri-star-fill fs-13 align-bottom"></i> </button> <div class="dropdown"> <button class="btn btn-light btn-icon btn-sm dropdown" type="button" data-bs-toggle="dropdown" aria-expanded="false"> <i class="ri-more-fill align-bottom"></i> </button> <ul class="dropdown-menu dropdown-menu-end"> <li><a class="dropdown-item viewfile-list" href="#">View</a></li> <li><a class="dropdown-item edit-list" href="#createFileModal" data-bs-toggle="modal" data-edit-id='+e.id+' role="button">Rename</a></li> <li class="dropdown-divider"></li> <li><a class="dropdown-item remove-list" href="#removeFileItemModal" data-id='+e.id+' data-bs-toggle="modal" role="button">Delete</a></li> </ul> </div> </div> </td> </tr>',favouriteBtn(),removeSingleItem(),editFileList(),fileDetailShow()})}function favouriteBtn(){Array.from(document.querySelectorAll(".favourite-btn")).forEach(function(e){e.addEventListener("click",function(){e.classList.contains("active")?e.classList.remove("active"):e.classList.add("active")})})}getJSON("filemanager-filelist.json",function(e,t){null!==e?console.log("Something went wrong: "+e):loadFileData(allFileList=t)}),favouriteBtn(),Array.from(document.querySelectorAll(".file-manager-menu a")).forEach(function(i){i.addEventListener("click",function(){var e,t=document.querySelector(".file-manager-menu a.active"),l=(t&&t.classList.remove("active"),i.classList.add("active"),i.querySelector(".file-list-link").innerHTML);document.getElementById("file-list").innerHTML="",document.getElementById("filetype-title").innerHTML="My Drive"!=l?l:"Recent file","