2023-03-22 21:53:06 +00:00
|
|
|
class FileView{
|
2023-04-29 13:58:39 +00:00
|
|
|
parentElem = undefined
|
2023-05-02 00:48:12 +00:00
|
|
|
selected = []
|
2023-03-22 21:53:06 +00:00
|
|
|
/**
|
|
|
|
* @param {HTMLElement} fileViewElem
|
2023-05-02 00:48:12 +00:00
|
|
|
* @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 19:49:42 +00:00
|
|
|
constructor(fileViewElem, doubleClickCallback, rightClickCallback, fileUploadCallback){
|
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) => {
|
2023-05-02 10:50:56 +00:00
|
|
|
if (event.target.classList[0] == 'FileTileView')
|
|
|
|
{
|
|
|
|
this.DeselectAll()
|
|
|
|
return
|
|
|
|
}
|
2023-05-02 00:48:12 +00:00
|
|
|
if (event.detail === 1){
|
2023-05-02 10:50:56 +00:00
|
|
|
this.DeselectAll()
|
2023-05-04 14:58:38 +00:00
|
|
|
this.Select([event.target])
|
2023-05-02 00:48:12 +00:00
|
|
|
} 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();
|
2023-05-04 14:58:38 +00:00
|
|
|
if (event.target.classList.contains("Tile")){
|
|
|
|
this.DeselectAll()
|
|
|
|
this.Select([event.target])
|
|
|
|
}
|
|
|
|
this.Select([event.target])
|
2023-05-04 00:38:24 +00:00
|
|
|
rightClickCallback(event)
|
|
|
|
})
|
2023-05-04 19:49:42 +00:00
|
|
|
|
|
|
|
if (fileUploadCallback !== undefined) {
|
|
|
|
fileViewElem.addEventListener('dragenter', function(event) {
|
|
|
|
// console.log("start")
|
|
|
|
})
|
|
|
|
|
|
|
|
fileViewElem.addEventListener('dragover', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
// console.log("over")
|
|
|
|
})
|
|
|
|
|
|
|
|
fileViewElem.addEventListener("drop", (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
// console.log(event.dataTransfer.items[0])
|
|
|
|
fileUploadCallback(event.dataTransfer.items)
|
|
|
|
})
|
|
|
|
}
|
2023-03-22 21:53:06 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 14:58:38 +00:00
|
|
|
/**
|
|
|
|
* @param {[]Element} elements
|
|
|
|
*/
|
|
|
|
Select(elements){
|
|
|
|
elements.forEach(element => {
|
|
|
|
this.selected.push(element)
|
|
|
|
element.classList.add("Selected")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-02 10:50:56 +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);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|