Verified Commit a8c07f52 authored by Jakob Moser's avatar Jakob Moser
Browse files

Only save if there is something to save

parent fd60da16
Loading
Loading
Loading
Loading
Loading
+1 −1
Changes for portal/static/js/components/pieces/Agenda.mjs: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ export const Agenda = {
                              },
                          },
                          m("i.fa-solid.fa-floppy-disk"),
                          "Speichern",
                          agenda.changes.length > 0 ? "Speichern" : "Ohne Änderungen speichern",
                      ),
                  ]
                : m(
+16 −3
Changes for portal/static/js/model/Agenda.mjs: 16 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -12,7 +12,13 @@ export class Agenda {
        return getKey() ? { Authorization: `Bearer ${getKey().secret}` } : {}
    }

    async fetch() {
    get changes() {
        return this.items.filter(it => it.taiga && it.taiga.status !== 42)
    }

    async fetch(force) {
        if(this.items && !force) return

        try {
            this.items = await m.request({
                method: "GET",
@@ -30,13 +36,20 @@ export class Agenda {
    }

    async save() {
        // TODO Somehow handle error?
        try {
            if(this.changes.length === 0) return

            this.items = await m.request({
                method: "PATCH",
                url: this.url,
                headers: this.#headers,
            body: this.items,
                body: this.changes
            })
        } catch (e) {
            // TODO Handle error better
            alert("Beim Speichern ist ein Fehler aufgetreten.")
            throw e
        }
    }
}