Easy-Session-Manager/src/scripts/events.js

111 lines
4.3 KiB
JavaScript
Raw Normal View History

2020-02-01 02:43:21 +00:00
getSavedSessionIDs();
2018-11-11 09:04:55 +00:00
document.addEventListener("click", (e) => {
if (e.button == 0) { // Left click
2020-02-29 21:30:44 +00:00
const target = e.target;
2020-03-02 02:59:26 +00:00
const action = target.getAttribute("name");
// Set selection first before doing any actions...
if (target.tagName == "LI" && target.className.includes("sessionLI")) {
2018-11-11 09:04:55 +00:00
if (selectedItem) {
if (selectedItem == target && selectedItem.className == "sessionLI selected") {
selectedItem.setAttribute("class", "sessionLI");
selectedItem = null;
2018-11-11 09:04:55 +00:00
} else {
selectedItem.setAttribute("class", "sessionLI");
selectedItem = target;
selectedItem.setAttribute("class", "sessionLI selected");
2018-11-11 09:04:55 +00:00
}
} else {
selectedItem = target;
selectedItem.setAttribute("class", "sessionLI selected");
2018-11-11 09:04:55 +00:00
}
}
const selectedItemName = (selectedItem !== null) ? selectedItem.getAttribute("name") : "";
2020-02-29 21:30:44 +00:00
// Modals
if (/(saveModalLauncher|editModalLauncher|deleteModalLauncher|downloadModalLauncher)/.test(action)) {
if (action == "saveModalLauncher") {
preSaveSession(selectedItem, selectedItemName);
showModal("saveModal");
return ;
}
if (selectedItem) {
2020-02-29 21:30:44 +00:00
if (action == "editModalLauncher") {
preEditSession(selectedItem, selectedItemName);
showModal("editModal");
} else if (action == "deleteModalLauncher") {
document.getElementsByName("toDeleteName")[0].innerText = selectedItemName;
showModal("deleteModal");
} else if (action == "downloadModalLauncher") {
preDownloadSession(selectedItemName);
showModal("downloadModal");
}
} else {
messageWindow("warning", "Select a session first...");
}
return ;
}
if (/(closeSave|closeEdit|closeDownload|closeDelete|closeConfirm|closeLoad)/.test(action)) {
if (action.includes("closeSave")) {
hideModal("saveModal");
} else if (action.includes("closeEdit")) {
hideModal("editModal");
} else if (action.includes("closeDownload")) {
hideModal("downloadModal");
} else if (action.includes("closeDelete")) {
hideModal("deleteModal");
} else if (action.includes("closeConfirm")) {
hideModal("confModal");
} else if (action.includes("closeLoad")) {
hideModal("loadModal");
}
}
else if (action.includes("deselectAll")) {
let container = document.getElementById("editSelectionContainer");
deselectAll(container);
}
2020-02-29 21:30:44 +00:00
// Actions
if (/(download|delete|edit|load)/.test(action)) {
if (selectedItem) {
if (action == "download") {
downloadSession(selectedItemName);
2020-02-29 21:30:44 +00:00
} else if (action == "delete") {
2020-02-01 06:59:29 +00:00
deleteFromStorage(selectedItem, selectedItemName);
2020-02-29 21:30:44 +00:00
hideModal("deleteModal");
} else if (action == "edit") {
editSession(selectedItem, selectedItemName);
2020-02-29 21:30:44 +00:00
} else if (action == "load") {
startLoadSession();
}
}
} else if (action == "save") {
saveSession(selectedItem, selectedItemName);
2020-02-29 21:30:44 +00:00
} else if (action == "confirm") {
confirmSessionOverwrite();
} else if (action == "import") {
importSession();
} else if (action == "donate") {
doUrlAction("https://www.paypal.me/ITDominator",);
}
2018-11-11 09:04:55 +00:00
}
});
2020-02-29 21:30:44 +00:00
2018-11-11 09:04:55 +00:00
document.addEventListener("dblclick", (e) => {
if (e.button == 0) { // Left click
if (e.target.tagName == "LI" && e.target.className.includes("sessionLI")) {
selectedItem = e.target;
2020-02-01 06:59:29 +00:00
const id = selectedItem.getAttribute("name");
selectedItem.setAttribute("class", "sessionLI selected");
2020-02-01 02:43:21 +00:00
preLoadSession(id);
2018-11-11 09:04:55 +00:00
}
}
});