diff --git a/crates/frontend/js-components/lib/delete-button.ts b/crates/frontend/js-components/lib/delete-button.ts new file mode 100644 index 0000000..2a55496 --- /dev/null +++ b/crates/frontend/js-components/lib/delete-button.ts @@ -0,0 +1,44 @@ +import { html, LitElement } from "lit"; +import { customElement, property } from "lit/decorators.js"; +import { createClient } from "webdav"; + +@customElement("delete-button") +export class DeleteButton extends LitElement { + constructor() { + super() + } + + @property({ type: Boolean }) + trash: boolean = false + @property() + href: string + + protected createRenderRoot() { + return this + } + + protected render() { + let text = this.trash ? 'Move to trash' : 'Delete' + return html`` + } + + async _onClick(event: Event) { + event.preventDefault() + if (!this.trash && !confirm('Do you want to delete this collection permanently?')) { + return + } + + let response = await fetch(this.href, { + method: 'DELETE', + headers: { + 'X-No-Trashbin': this.trash ? '0' : '1' + } + }) + if (response.status < 200 || response.status >= 300) { + alert('An error occured, look into the console') + console.error(response) + return + } + window.location.reload() + } +} diff --git a/crates/frontend/js-components/vite.config.ts b/crates/frontend/js-components/vite.config.ts index 2e3220b..47c8eb0 100644 --- a/crates/frontend/js-components/vite.config.ts +++ b/crates/frontend/js-components/vite.config.ts @@ -15,6 +15,7 @@ export default defineConfig({ input: [ "lib/create-calendar-form.ts", "lib/create-addressbook-form.ts", + "lib/delete-button.ts", ], output: { dir: "../public/assets/js/", diff --git a/crates/frontend/public/assets/js/create-addressbook-form.mjs b/crates/frontend/public/assets/js/create-addressbook-form.mjs index e9abc69..9e70d46 100644 --- a/crates/frontend/public/assets/js/create-addressbook-form.mjs +++ b/crates/frontend/public/assets/js/create-addressbook-form.mjs @@ -1,10 +1,11 @@ import { i as c, x as u } from "./lit-CWlWuEHk.mjs"; -import { e as d, n as m, a as o, t as h } from "./ref-DuYNkSJ_.mjs"; +import { n as o, t as h } from "./property-DYFkTqgI.mjs"; +import { e as d, n as m } from "./ref-nf9JiOyl.mjs"; import { a as b } from "./webdav-Bz4I5vNH.mjs"; -var y = Object.defineProperty, f = Object.getOwnPropertyDescriptor, a = (t, s, l, r) => { - for (var e = r > 1 ? void 0 : r ? f(s, l) : s, n = t.length - 1, p; n >= 0; n--) - (p = t[n]) && (e = (r ? p(s, l, e) : p(e)) || e); - return r && e && y(s, l, e), e; +var y = Object.defineProperty, f = Object.getOwnPropertyDescriptor, r = (t, a, n, s) => { + for (var e = s > 1 ? void 0 : s ? f(a, n) : a, l = t.length - 1, p; l >= 0; l--) + (p = t[l]) && (e = (s ? p(a, n, e) : p(e)) || e); + return s && e && y(a, n, e), e; }; let i = class extends c { constructor() { @@ -65,19 +66,19 @@ let i = class extends c { }), window.location.reload(), null; } }; -a([ +r([ o() ], i.prototype, "user", 2); -a([ +r([ o() ], i.prototype, "id", 2); -a([ +r([ o() ], i.prototype, "displayname", 2); -a([ +r([ o() ], i.prototype, "description", 2); -i = a([ +i = r([ h("create-addressbook-form") ], i); export { diff --git a/crates/frontend/public/assets/js/create-calendar-form.mjs b/crates/frontend/public/assets/js/create-calendar-form.mjs index e804565..ca9d6e0 100644 --- a/crates/frontend/public/assets/js/create-calendar-form.mjs +++ b/crates/frontend/public/assets/js/create-calendar-form.mjs @@ -1,14 +1,15 @@ import { i as u, x as c } from "./lit-CWlWuEHk.mjs"; -import { e as d, n as m, a as o, t as h } from "./ref-DuYNkSJ_.mjs"; +import { n as o, t as h } from "./property-DYFkTqgI.mjs"; +import { e as m, n as d } from "./ref-nf9JiOyl.mjs"; import { a as b } from "./webdav-Bz4I5vNH.mjs"; -var y = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, a = (t, e, l, s) => { - for (var i = s > 1 ? void 0 : s ? $(e, l) : e, n = t.length - 1, p; n >= 0; n--) - (p = t[n]) && (i = (s ? p(e, l, i) : p(i)) || i); - return s && i && y(e, l, i), i; +var y = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, a = (t, e, n, s) => { + for (var i = s > 1 ? void 0 : s ? $(e, n) : e, l = t.length - 1, p; l >= 0; l--) + (p = t[l]) && (i = (s ? p(e, n, i) : p(i)) || i); + return s && i && y(e, n, i), i; }; let r = class extends u { constructor() { - super(), this.client = b("/caldav"), this.user = "", this.id = "", this.displayname = "", this.description = "", this.color = "", this.subscriptionUrl = "", this.components = /* @__PURE__ */ new Set(), this.dialog = d(), this.form = d(); + super(), this.client = b("/caldav"), this.user = "", this.id = "", this.displayname = "", this.description = "", this.color = "", this.subscriptionUrl = "", this.components = /* @__PURE__ */ new Set(), this.dialog = m(), this.form = m(); } createRenderRoot() { return this; @@ -16,9 +17,9 @@ let r = class extends u { render() { return c` - +

Create calendar

-
+