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

39 lines
1.2 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
2023-03-22 21:53:06 +00:00
/**
* @param {HTMLElement} fileViewElem
2023-04-12 17:04:25 +00:00
* @param {Function} clickCallback
2023-03-22 21:53:06 +00:00
*/
2023-04-29 13:58:39 +00:00
constructor(fileViewElem, clickCallback){
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
2023-04-29 13:58:39 +00:00
// this.OpenFolder(path)
2023-03-22 21:53:06 +00:00
// let scrollDiv = fileViewElem.children[1]
// console.log(scrollDiv)
// let scrollBar = new WdeScrollBar(fileViewElem.children[1].children[0], fileViewElem.children[0])
fileViewElem.addEventListener('click', (event) => {
2023-04-12 17:04:25 +00:00
clickCallback(event)
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);
})
}
}