52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
class FileView{
|
|
parentElem = undefined
|
|
selected = []
|
|
/**
|
|
* @param {HTMLElement} fileViewElem
|
|
* @param {Function} doubleClickCallback
|
|
*/
|
|
constructor(fileViewElem, doubleClickCallback){
|
|
//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)
|
|
}
|
|
})
|
|
}
|
|
|
|
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);
|
|
})
|
|
}
|
|
} |