diff --git a/crates/frontend/js-components/lib/import-addressbook-form.ts b/crates/frontend/js-components/lib/import-addressbook-form.ts new file mode 100644 index 0000000..a7f34a3 --- /dev/null +++ b/crates/frontend/js-components/lib/import-addressbook-form.ts @@ -0,0 +1,92 @@ +import { html, LitElement } from "lit"; +import { customElement, property } from "lit/decorators.js"; +import { Ref, createRef, ref } from 'lit/directives/ref.js'; + +@customElement("import-addressbook-form") +export class ImportAddressbookForm extends LitElement { + constructor() { + super() + } + + protected override createRenderRoot() { + return this + } + + @property() + user: string = '' + @property() + principal: string + @property() + addressbook_id: string = self.crypto.randomUUID() + + dialog: Ref = createRef() + form: Ref = createRef() + file: File; + + + override render() { + return html` + + +

Import addressbook

+
+ +
+ +
+ + + +
+
+ ` + } + + async submit(e: SubmitEvent) { + e.preventDefault() + this.principal ||= this.user + if (!this.principal) { + alert("Empty principal") + return + } + if (!this.addressbook_id) { + alert("Empty id") + return + } + let response = await fetch(`/carddav/principal/${this.principal}/${this.addressbook_id}`, { + method: 'IMPORT', + headers: { + 'Content-Type': 'text/vcard' + }, + body: this.file, + }) + + if (response.status >= 400) { + alert(`Error ${response.status}: ${await response.text()}`) + return null + } + + window.location.reload() + return null + } +} + +declare global { + interface HTMLElementTagNameMap { + 'import-addressbook-form': ImportAddressbookForm + } +} diff --git a/crates/frontend/js-components/lib/import-calendar-form.ts b/crates/frontend/js-components/lib/import-calendar-form.ts index b9623bf..9beec6c 100644 --- a/crates/frontend/js-components/lib/import-calendar-form.ts +++ b/crates/frontend/js-components/lib/import-calendar-form.ts @@ -1,7 +1,6 @@ import { html, LitElement } from "lit"; import { customElement, property } from "lit/decorators.js"; import { Ref, createRef, ref } from 'lit/directives/ref.js'; -import { escapeXml } from "."; @customElement("import-calendar-form") export class ImportCalendarForm extends LitElement { @@ -19,8 +18,6 @@ export class ImportCalendarForm extends LitElement { principal: string @property() cal_id: string = self.crypto.randomUUID() - @property() - timezone_id: string = '' dialog: Ref = createRef() form: Ref = createRef() diff --git a/crates/frontend/js-components/vite.config.ts b/crates/frontend/js-components/vite.config.ts index 0c038bf..e535efb 100644 --- a/crates/frontend/js-components/vite.config.ts +++ b/crates/frontend/js-components/vite.config.ts @@ -19,6 +19,7 @@ export default defineConfig({ "lib/import-calendar-form.ts", "lib/create-addressbook-form.ts", "lib/edit-addressbook-form.ts", + "lib/import-addressbook-form.ts", "lib/delete-button.ts", ], output: { diff --git a/crates/frontend/public/assets/js/import-addressbook-form.mjs b/crates/frontend/public/assets/js/import-addressbook-form.mjs new file mode 100644 index 0000000..7ce5e44 --- /dev/null +++ b/crates/frontend/public/assets/js/import-addressbook-form.mjs @@ -0,0 +1,100 @@ +import { i, x } from "./lit-z6_uA4GX.mjs"; +import { n as n$1, t } from "./property-D0NJdseG.mjs"; +import { e, n } from "./ref-CPp9J0V5.mjs"; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __decorateClass = (decorators, target, key, kind) => { + var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target; + for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--) + if (decorator = decorators[i2]) + result = (kind ? decorator(target, key, result) : decorator(result)) || result; + if (kind && result) __defProp(target, key, result); + return result; +}; +let ImportAddressbookForm = class extends i { + constructor() { + super(); + this.user = ""; + this.addressbook_id = self.crypto.randomUUID(); + this.dialog = e(); + this.form = e(); + } + createRenderRoot() { + return this; + } + render() { + return x` + + +

Import addressbook

+
+ +
+ +
+ + + +
+
+ `; + } + async submit(e2) { + e2.preventDefault(); + this.principal || (this.principal = this.user); + if (!this.principal) { + alert("Empty principal"); + return; + } + if (!this.addressbook_id) { + alert("Empty id"); + return; + } + let response = await fetch(`/carddav/principal/${this.principal}/${this.addressbook_id}`, { + method: "IMPORT", + headers: { + "Content-Type": "text/vcard" + }, + body: this.file + }); + if (response.status >= 400) { + alert(`Error ${response.status}: ${await response.text()}`); + return null; + } + window.location.reload(); + return null; + } +}; +__decorateClass([ + n$1() +], ImportAddressbookForm.prototype, "user", 2); +__decorateClass([ + n$1() +], ImportAddressbookForm.prototype, "principal", 2); +__decorateClass([ + n$1() +], ImportAddressbookForm.prototype, "addressbook_id", 2); +ImportAddressbookForm = __decorateClass([ + t("import-addressbook-form") +], ImportAddressbookForm); +export { + ImportAddressbookForm +}; diff --git a/crates/frontend/public/assets/js/import-calendar-form.mjs b/crates/frontend/public/assets/js/import-calendar-form.mjs index 75d6fd7..82e20aa 100644 --- a/crates/frontend/public/assets/js/import-calendar-form.mjs +++ b/crates/frontend/public/assets/js/import-calendar-form.mjs @@ -16,7 +16,6 @@ let ImportCalendarForm = class extends i { super(); this.user = ""; this.cal_id = self.crypto.randomUUID(); - this.timezone_id = ""; this.dialog = e(); this.form = e(); } @@ -93,9 +92,6 @@ __decorateClass([ __decorateClass([ n$1() ], ImportCalendarForm.prototype, "cal_id", 2); -__decorateClass([ - n$1() -], ImportCalendarForm.prototype, "timezone_id", 2); ImportCalendarForm = __decorateClass([ t("import-calendar-form") ], ImportCalendarForm); diff --git a/crates/frontend/public/templates/components/sections/addressbooks_section.html b/crates/frontend/public/templates/components/sections/addressbooks_section.html index bf0b9a8..e699b0b 100644 --- a/crates/frontend/public/templates/components/sections/addressbooks_section.html +++ b/crates/frontend/public/templates/components/sections/addressbooks_section.html @@ -65,4 +65,5 @@ {% endif %} + diff --git a/crates/frontend/public/templates/pages/user.html b/crates/frontend/public/templates/pages/user.html index 70aa77a..e4c2f88 100644 --- a/crates/frontend/public/templates/pages/user.html +++ b/crates/frontend/public/templates/pages/user.html @@ -10,6 +10,7 @@ window.rusticalUser = JSON.parse(document.querySelector('#data-rustical-user').i + {% endblock %} {% block header_center %}