2019-05-21 19:37:11 +05:30
|
|
|
|
2019-05-24 14:41:30 +05:30
|
|
|
let currDir = {'loc':'','contents':null}
|
|
|
|
let currSel = {'loc':null,'name':null}
|
2019-05-21 19:37:11 +05:30
|
|
|
|
2019-05-23 20:23:32 +05:30
|
|
|
function doUpdate(ele,isDir=false){
|
|
|
|
//console.log(ele.attr('data-choice'));
|
2019-05-22 17:09:45 +05:30
|
|
|
if(ele.hasClass('file-isDir')){
|
2019-05-24 14:41:30 +05:30
|
|
|
currDir.loc = ele.attr('data-choice')
|
2019-05-22 17:09:45 +05:30
|
|
|
populateContents();
|
|
|
|
}
|
2019-05-23 20:23:32 +05:30
|
|
|
if(!isDir){
|
2019-05-24 14:41:30 +05:30
|
|
|
currSel.loc = ele.attr('data-choice')
|
|
|
|
$('.nav-bottom-text').html(currSel.name = ele.html())
|
2019-05-23 20:23:32 +05:30
|
|
|
|
|
|
|
}
|
2019-05-22 17:09:45 +05:30
|
|
|
//$()
|
|
|
|
//$(this).
|
|
|
|
}
|
|
|
|
|
2019-05-21 20:31:41 +05:30
|
|
|
function updateContents(contents){
|
2019-05-23 20:23:32 +05:30
|
|
|
//console.log(contents)
|
2019-05-22 20:22:59 +05:30
|
|
|
|
|
|
|
// Change top header contents
|
2019-05-24 11:04:51 +05:30
|
|
|
$('#files-location').html(contents.loc)
|
2019-05-22 20:22:59 +05:30
|
|
|
|
|
|
|
// if empty, return null, this shouldnt execute if the server is responding properly but ok
|
|
|
|
if(contents===null) {
|
|
|
|
$('#files-table').append(`<tr><td>null</td><td class="file-handlers"></td></tr>`)
|
|
|
|
}
|
2019-05-21 20:31:41 +05:30
|
|
|
else
|
2019-05-22 17:09:45 +05:30
|
|
|
{
|
2019-05-23 20:23:32 +05:30
|
|
|
$('#files-table').hide().empty();
|
2019-05-22 17:09:45 +05:30
|
|
|
contents.contents.forEach(element => {
|
2019-05-23 20:23:32 +05:30
|
|
|
$('#files-table').append(`<tr class="files-row box-shadow-1-active"><td onclick="doUpdate($(this),${element.isDir})" class="file-name ${(element.isDir?'file-isDir':'file-isFile')}" data-choice="${element.path}">${element.name}</td></tr>`)
|
2019-05-22 17:09:45 +05:30
|
|
|
});
|
2019-05-22 20:22:59 +05:30
|
|
|
if(contents.back!=null){
|
2019-05-24 21:38:31 +05:30
|
|
|
$('#files-table').prepend(`<tr class="files-row box-shadow-1-active"><td onclick="doUpdate($(this),true)" class="file-name file-isDir file-isBack" data-choice="${contents.back}">..</td></tr>`)
|
2019-05-22 20:22:59 +05:30
|
|
|
}
|
2019-05-23 20:23:32 +05:30
|
|
|
$('#files-table').fadeIn()
|
2019-05-22 17:09:45 +05:30
|
|
|
}
|
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();
|
2019-05-24 14:41:30 +05:30
|
|
|
$('.file-download-button').click(()=>{
|
|
|
|
console.log(currSel)
|
|
|
|
$.ajax('/files/cat',{
|
|
|
|
method:'post',
|
|
|
|
data:currSel,
|
|
|
|
xhrFields: {
|
|
|
|
responseType: 'blob'
|
|
|
|
},
|
|
|
|
success:(msg)=>{
|
|
|
|
//console.log(msg)
|
|
|
|
$('.file-download-button').after(`<a id="down-temp" href="${window.URL.createObjectURL(msg)}" download="${currSel.name}"></a>`)
|
|
|
|
document.getElementById('down-temp').click()
|
|
|
|
$('#down-temp').remove();
|
|
|
|
},
|
|
|
|
error: err=>console.log(err)
|
|
|
|
})
|
|
|
|
})
|
2019-05-24 21:38:31 +05:30
|
|
|
$('.close-rename').click(()=>{
|
|
|
|
$('.rename-window').fadeOut('fast')
|
|
|
|
$("#cover").fadeOut('fast')
|
|
|
|
})
|
|
|
|
$('.close-upload').click(()=>{
|
|
|
|
$('.upload-window').fadeOut('fast')
|
|
|
|
$("#cover").fadeOut('fast')
|
|
|
|
})
|
|
|
|
$('.file-rename-button').click(()=>{
|
|
|
|
$('#cover').fadeIn('fast')
|
|
|
|
$('.rename-window').fadeIn('fast')
|
|
|
|
})
|
|
|
|
$('.nav-bottom-button').click(()=>{
|
|
|
|
$('#cover').fadeIn('fast')
|
|
|
|
$('.upload-window').fadeIn('fast')
|
|
|
|
})
|
2019-05-21 20:31:41 +05:30
|
|
|
})
|