123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- <html>
- <head>
- <title>Trash Bin</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
- <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
- <script type="text/javascript" src="../../script/jquery.min.js"></script>
- <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
- <script type="text/javascript" src="../../script/ao_module.js"></script>
- <style>
- body{
- background-color:white;
- }
- .banner{
- background-color:#4287f5;
- height:50px;
- padding:12px;
- padding-left:20px;
- padding-top:16px;
- }
- #opricon{
- position:absolute;
- top:0px;
- right:0px;
- width:80px;
- height:80px;
- }
- .title{
- color:white;
- font-size:130%;
- }
- .content{
- padding:12px;
- }
-
- .info{
- margin-top:3px;
- width:80%;
- }
-
- </style>
- </head>
- <body>
- <span class="normalview">
- <div class="ui menu">
- <div class="header item">
- <img class="ui middle aligned mini image" src="trashbin_img/small_icon.png" style="margin-right:8px; height:28px; width:28px;"></img> Trash Bin
- </div>
- <div class="right item">
- <button class="ui negative small button" onclick="clearAll();">Delete All</button>
- </div>
- </div>
- <div class="ui container">
- <div class="ui segment">
- <table class="ui celled table">
- <thead>
- <tr><th>Filename</th>
- <th>Delete Time</th>
- <th>Details</th>
- <th>Restore</th>
- </tr></thead>
- <tbody id="trashList">
- </tbody>
- </table>
- <div class="ui message" id="scanning">
- <i class="loading spinner icon"></i> Scanning for trash in all disks...
- </div>
- </div>
- </div>
- </span>
- <div class="confirmRemove" style="display:none;">
- <div class="banner">
- <div class="title">Move <span id="fcount">0 File</span> to Trash Bin?</div>
- <img id="opricon" src="trashbin_img/trashopr.png" class="ui image"></img>
- </div>
- <div class="content">
- <div class="info">Deleting: <span class="filename"></span></div>
- <div style="position:absolute; bottom:8px;right:4px;">
- <button class="ui small button" onclick="ao_module_close();">Cancel</button>
- <button class="ui primary small button" onclick="confirmDelete();">Confirm</button>
- </div>
- </div>
- </div>
- <div class="ui modal" style="overflow-y:auto; overflow-x:hidden;">
- <i class="close icon"></i>
- <div class="header filename">
- No File Selected
- </div>
- <div class="ui basic segment">
- <table class="ui very basic celled table">
- <thead>
- <tr>
- <th>Property</th>
- <th>Value</th>
- </tr>
- </thead>
- <tbody id="detailList">
-
- </tbody>
- </table>
- </div>
- <div class="actions">
- <div class="ui icon blue button" onclick=" $('.ui.modal').modal('hide');">
- OK
- </div>
- </div>
- </div>
- <script>
- var deletePendingFiles = ao_module_loadInputFiles();
- var previousTrashbinFilelist = [];
- var legacyMode = !('WebSocket' in window || 'MozWebSocket' in window);
- if (deletePendingFiles != null && deletePendingFiles.length > 0){
- //Handle trash treatment
- console.log(deletePendingFiles);
- ao_module_setFixedWindowSize();
- ao_module_setWindowSize(400,200);
- $(".normalview").hide();
- $(".confirmRemove").show();
- //Update graphical information
- var displayname = deletePendingFiles[0].filename;
- $("#fcount").text("1 File");
- if (deletePendingFiles.length > 1){
- displayname = displayname + " and " + (deletePendingFiles.length - 1) + " more";
- $("#fcount").text(deletePendingFiles.length + " Files");
- }
- $(".filename").text(displayname);
- }else{
- initList();
- }
- //Initialize the trash list
- function initList(){
- $("#trashList").html("");
- $("#scanning").show();
- if (!legacyMode){
- //Use WebSocket for rendering
- var ws = new WebSocket(getWSEndpoint() + `/system/file_system/ws/listTrash`);
-
- ws.onopen = function() {
- previousTrashbinFilelist = [];
- console.log("TrashBin WebSocket Opened");
- };
-
- ws.onmessage = function (evt) {
- var data = evt.data;
- var thisFile = JSON.parse(data);
- var filedata = encodeURIComponent(JSON.stringify(thisFile));
- //console.log(thisFile);
- $("#trashList").append(`<tr>
- <td>${thisFile.OriginalFilename}</td>
- <td>${thisFile.RemoveDate}</td>
- <td><button filedata="${filedata}" class="ui tiny button" onclick="showDetail(this);">Details</button></td>
- <td><button filedata="${filedata}" class="ui green tiny button" onclick="restore(this);">Restore</button></td>
- </tr>`);
- previousTrashbinFilelist.push(thisFile);
- };
-
- ws.onclose = function() {
- console.log("TrashBin WebSocket transfer completed");
- if (previousTrashbinFilelist.length == 0){
- $("#trashList").append(`<tr><td colspan="4"><i class="checkmark icon"></i> There are no files or folders in Trashbin.</td></tr>`);
- }
- $("#scanning").hide();
- };
- ws.onerror = function(){
- console.log("Open failed. Fallback to legacy mode");
- legacyMode = true;
- initList();
- }
- }else{
- //Use AJAX (Slower)
- $.get("../../system/file_system/listTrash",function(data){
- if (data.error !== undefined){
- $("#scanning").hide();
- alert(data.error);
- }else{
- previousTrashbinFilelist = [];
- for (var i =0; i < data.length; i++){
- var thisFile = data[i];
- var filedata = encodeURIComponent(JSON.stringify(thisFile));
- $("#trashList").append(`<tr>
- <td>${thisFile.OriginalFilename}</td>
- <td>${thisFile.RemoveDate}</td>
- <td><button filedata="${filedata}" class="ui tiny button" onclick="showDetail(this);">Details</button></td>
- <td><button filedata="${filedata}" class="ui green tiny button" onclick="restore(this);">Restore</button></td>
- </tr>`);
- previousTrashbinFilelist.push(thisFile);
- }
- if (data.length == 0){
- $("#trashList").append(`<tr><td colspan="4"><i class="checkmark icon"></i> There are no files or folders in Trashbin.</td></tr>`);
- }
- $("#scanning").hide();
- }
- });
- }
- }
- function getWSEndpoint(){
- //Open opeartion in websocket
- let protocol = "wss://";
- if (location.protocol !== 'https:') {
- protocol = "ws://";
- }
- wsControlEndpoint = (protocol + window.location.hostname + ":" + window.location.port);
- return wsControlEndpoint;
- }
-
- //Listen to the change of the trashbin
- setInterval(function(){
- $.get("../../system/file_system/listTrash",function(data){
- if (data.length != previousTrashbinFilelist.length){
- //Change of the trashbin file. Update the list
- initList();
- }
- });
- }, 30000);
- function showDetail(object){
- var filedata = JSON.parse(decodeURIComponent($(object).attr("filedata")));
- $(".filename").text(filedata.OriginalFilename);
- $("#detailList").html("");
- var keyMapping = {
- "Filename": "Storage Filename",
- "Filepath": "Storage Filepath",
- "FileExt": "File Extension",
- "IsDir": "Is Directory",
- "Filesize": "File Size",
- "RemoveTimestamp": "Remove Timestamp",
- "RemoveDate": "Remove Datetime",
- "OriginalPath": "Original Path",
- "OriginalFilename": "Original Filename"
- }
- for (var [key, value] of Object.entries(filedata)) {
- console.log(key, value);
- var displayKey = keyMapping[key];
- if (key == "Filesize"){
- value = bytesToSize(value);
- }
- $("#detailList").append(`<tr>
- <td>
- ${displayKey}
- </td>
- <td>
- ${value}
- </td>
- </tr>`);
- }
-
- $('.ui.modal').modal('show').css({"overflow-y":"auto","overflow-x": "hidden", "max-height":window.innerHeight - 30 + "px"});
- }
- function bytesToSize(bytes) {
- var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
- if (bytes == 0) return '0 Byte';
- var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
- return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
- }
- function clearAll(){
- if (confirm("Confirm deleting ALL FILE PERMANENTLY?")){
- $.get("../../system/file_system/clearTrash",function(data){
- initList();
- });
- }
- }
- function restore(obj){
- var filedata = JSON.parse(decodeURIComponent($(obj).attr("filedata")));
- var filepath = filedata.Filepath;
- $.ajax({
- url: "../../system/file_system/restoreTrash",
- method: "POST",
- data: {"src" : filepath},
- success: function(data){
- if (data.error !== undefined){
- alert(data.error);
- }else{
- initList();
- parent.refresh(undefined, true);
- }
- }
- })
- }
- function confirmDelete(){
- //Confirm delete of the files in the list
- var deleteFileList = [];
- for (var i =0; i <deletePendingFiles.length; i++){
- deleteFileList.push(deletePendingFiles[i].filepath);
- }
- $.ajax({
- url: "../../system/file_system/fileOpr",
- method:"POST",
- data: {opr: "recycle", src: JSON.stringify(deleteFileList)},
- success: function(data){
- if (data.error !== undefined){
- console.log("Delete failed! " + data.error)
- }else{
- //Delete completed. Close this window
- parent.refresh(undefined, true);
- ao_module_close();
- }
- }
- });
- }
- </script>
- </body>
- </html>
|