Files
nodejs-fm/static/base.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-05-21 19:37:11 +05:30
2019-05-21 20:31:41 +05:30
let currDir = {'loc':'','contents':null};
2019-05-21 19:37:11 +05:30
2019-05-22 17:09:45 +05:30
function doUpdate(ele){
console.log(ele.attr('data-choice'));
if(ele.hasClass('file-isDir')){
currDir.loc = currDir.loc+ "/"+ ele.attr('data-choice');
populateContents();
}
//$()
//$(this).
}
2019-05-21 20:31:41 +05:30
function updateContents(contents){
2019-05-22 17:09:45 +05:30
//console.log(contents)
$('#files-location').html(currDir.loc)
2019-05-21 20:31:41 +05:30
if(contents===null) $('#files-table').append(`<tr><td>null</td><td class="file-handlers"></td></tr>`)
else
2019-05-22 17:09:45 +05:30
{
$('#files-table').empty();
contents.contents.forEach(element => {
$('#files-table').append(`<tr class="files-row"><td onclick="doUpdate($(this))" class="file-name ${(element.type?'file-isDir':'file-isFile')}" data-choice="${element.name}">${element.name}</td><td class="file-handlers"></td></tr>`)
});
}
2019-05-21 20:31:41 +05:30
}
2019-05-21 19:37:11 +05:30
//set table details
2019-05-21 20:31:41 +05:30
function populateContents(){
2019-05-22 17:09:45 +05:30
$.ajax('/files/ls',{
2019-05-21 20:31:41 +05:30
method:'post',
data: currDir,
success:(msg)=>{
updateContents(msg)
}
2019-05-21 19:37:11 +05:30
2019-05-21 20:31:41 +05:30
})
return null;
2019-05-21 19:37:11 +05:30
}
2019-05-21 20:31:41 +05:30
$(document).ready(()=>{
populateContents();
//updateContents();
})