Nashboard/static/js/mainpage.js

68 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-12-14 12:10:00 +03:00
if (!localStorage.getItem("SessionID")) {
window.location.href = "/login.html";
}
2022-12-14 02:27:39 +03:00
window.addEventListener("load", async () => {
console.log("loading...");
const rootFolder = await getFolder();
const bm = document.getElementById("bookmarks");
if (!rootFolder.success) {
bm.textContent = "Нет закладок";
return;
}
2022-12-14 12:10:00 +03:00
if (!bookmark || !folder) {
2022-12-14 02:27:39 +03:00
return;
}
2022-12-14 12:10:00 +03:00
for (let f of rootFolder.folder.ChildFolders) {
const clone = createFolderElement(f);
bm.appendChild(clone);
}
2022-12-14 02:27:39 +03:00
for (let b of rootFolder.folder.ChildBookmarks) {
2022-12-14 12:10:00 +03:00
const clone = createBookmarkElement(b);
2022-12-14 02:27:39 +03:00
bm.appendChild(clone);
}
2022-12-14 12:10:00 +03:00
feather.replace();
2022-12-14 02:27:39 +03:00
});
2022-12-14 12:10:00 +03:00
function createFolderElement(folder) {
const template = document.querySelector("#folder");
const clone = template.content.firstElementChild.cloneNode(true);
clone.querySelector("#folder_name").textContent = folder.Name;
clone.addEventListener("click", () => {
alert(folder.Name);
});
for (let el of clone.querySelectorAll("[data-feather-t]")) {
el.setAttribute("data-feather", el.getAttribute("data-feather-t"));
}
clone.querySelector(".xmark").addEventListener("click", (e) => {
alert(`${folder.Name} was deleted`);
e.stopPropagation();
});
return clone;
}
function createBookmarkElement(bookmark) {
const template = document.querySelector("#bookmark");
const tagtempl = document.querySelector("#booktag");
const clone = template.content.firstElementChild.cloneNode(true);
clone.querySelector("#bookmark_name").textContent = bookmark.Name;
const link = clone.querySelector("#bookmark_link");
link.setAttribute("href", bookmark.Url);
link.textContent = bookmark.Url;
for (let tag of bookmark.Tags) {
const t = tagtempl.content.cloneNode(true);
const el = t.querySelector("span");
el.addEventListener("onclick", () => alert(tag));
el.textContent = "#" + tag;
clone.querySelector("#bookmark_tags").appendChild(t);
}
for (let el of clone.querySelectorAll("[data-feather-t]")) {
el.setAttribute("data-feather", el.getAttribute("data-feather-t"));
}
clone.querySelector(".xmark").addEventListener("click", (e) => {
alert(`${bookmark.Name} was deleted`);
e.stopPropagation();
});
return clone;
}