personal-website/resources/sys/wde/file-view.js
2023-05-04 03:38:24 +03:00

58 lines
1.7 KiB
JavaScript

class FileView{
parentElem = undefined
selected = []
/**
* @param {HTMLElement} fileViewElem
* @param {Function} doubleClickCallback
* @param {Function} rightClickCallback
*/
constructor(fileViewElem, doubleClickCallback, rightClickCallback){
//TODO check all params
this.parentElem = fileViewElem
fileViewElem.addEventListener('click', (event) => {
if (event.target.classList[0] == 'FileTileView')
{
this.DeselectAll()
return
}
if (event.detail === 1){
this.DeselectAll()
this.selected.push(event.target)
event.target.classList.add("Selected")
} else if (event.detail === 2) {
doubleClickCallback(event)
}
})
fileViewElem.addEventListener('contextmenu', (event) => {
event.preventDefault();
rightClickCallback(event)
})
}
DeselectAll(){
this.selected.forEach(element => {
element.classList.remove("Selected")
});
this.selected = []
}
/** Get html of folder by path
* @param {string} path
*/
OpenFolder(path){
fetch(`${window.location.origin}/system/wde/widgets/file-tile-view?path=${path}`) //TODO Move to wde func. Or Not?
.then((response) => response.text())
.then((html) => {
//TODO
// console.log(responseStatus)
// if (responseStatus != 200) {
// WebDesktopEnvironment.Alert("Error")
// }
this.parentElem.innerHTML = html
}).catch((error) => {
WebDesktopEnvironment.Alert(error);
})
}
}