personal-website/resources/sys/wde/file-view.js

58 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-03-22 21:53:06 +00:00
class FileView{
2023-04-29 13:58:39 +00:00
parentElem = undefined
selected = []
2023-03-22 21:53:06 +00:00
/**
* @param {HTMLElement} fileViewElem
* @param {Function} doubleClickCallback
2023-05-04 00:38:24 +00:00
* @param {Function} rightClickCallback
2023-03-22 21:53:06 +00:00
*/
2023-05-04 00:38:24 +00:00
constructor(fileViewElem, doubleClickCallback, rightClickCallback){
2023-04-12 17:04:25 +00:00
//TODO check all params
2023-04-29 13:58:39 +00:00
this.parentElem = fileViewElem
2023-03-22 21:53:06 +00:00
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)
}
2023-03-22 21:53:06 +00:00
})
2023-05-04 00:38:24 +00:00
fileViewElem.addEventListener('contextmenu', (event) => {
event.preventDefault();
rightClickCallback(event)
})
2023-03-22 21:53:06 +00:00
}
DeselectAll(){
this.selected.forEach(element => {
element.classList.remove("Selected")
});
this.selected = []
}
2023-03-22 21:53:06 +00:00
/** Get html of folder by path
* @param {string} path
*/
2023-04-29 13:58:39 +00:00
OpenFolder(path){
2023-03-22 21:53:06 +00:00
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) => {
2023-04-29 13:58:39 +00:00
//TODO
// console.log(responseStatus)
// if (responseStatus != 200) {
// WebDesktopEnvironment.Alert("Error")
// }
this.parentElem.innerHTML = html
2023-03-22 21:53:06 +00:00
}).catch((error) => {
WebDesktopEnvironment.Alert(error);
})
}
}