Files
linkding/bookmarks/frontend/behaviors/bookmark-details.js
Sascha Ißbrücker 9c48085829 Add bookmark details view (#665)
* Experiment with bookmark details

* Add basic tests

* Refactor details into modal

* Implement edit and delete button

* Remove slide down animation

* Add fallback details view

* Add status actions

* Improve dark theme

* Improve return URLs

* Make bookmark details sharable

* Fix E2E tests
2024-03-29 12:37:20 +01:00

39 lines
958 B
JavaScript

import { registerBehavior } from "./index";
class BookmarkDetails {
constructor(element) {
this.form = element.querySelector(".status form");
if (!this.form) {
// Form may not exist if user does not own the bookmark
return;
}
this.form.addEventListener("submit", (event) => {
event.preventDefault();
this.submitForm();
});
const inputs = this.form.querySelectorAll("input");
inputs.forEach((input) => {
input.addEventListener("change", () => {
this.submitForm();
});
});
}
async submitForm() {
const url = this.form.action;
const formData = new FormData(this.form);
await fetch(url, {
method: "POST",
body: formData,
redirect: "manual", // ignore redirect
});
// Refresh bookmark page if it exists
document.dispatchEvent(new CustomEvent("bookmark-page-refresh"));
}
}
registerBehavior("ld-bookmark-details", BookmarkDetails);