diff --git a/config.json b/config.json index 4a86116..fffc80c 100644 --- a/config.json +++ b/config.json @@ -2,7 +2,7 @@ "name": "Access", "short_description": "NFC door access — authorize Bolt Card taps and unlock via Home Assistant", "tile": "/access/static/image/access.png", - "version": "0.0.2", + "version": "0.0.3", "min_lnbits_version": "1.3.0", "contributors": [ { diff --git a/static/js/index.js b/static/js/index.js index 62083e8..24e5d8f 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -75,14 +75,31 @@ window.app = Vue.createApp({ ) this.logs = data }, - async createDoor() { + editDoor(door) { + // Prefill the dialog for an update. Drop controller_token so it's left + // untouched server-side (api_door_update keeps it when not resent). + const { controller_token, ...data } = door + this.doorDialog = { show: true, data } + }, + async saveDoor() { + // POST to create, PUT to update an existing door (data.id present). + const d = this.doorDialog.data try { - await LNbits.api.request( - 'POST', - '/access/api/v1/doors', - this.adminkey, - this.doorDialog.data - ) + if (d.id) { + await LNbits.api.request( + 'PUT', + `/access/api/v1/doors/${d.id}`, + this.adminkey, + d + ) + } else { + await LNbits.api.request( + 'POST', + '/access/api/v1/doors', + this.adminkey, + d + ) + } this.doorDialog = { show: false, data: { unlock_timeout_ms: 2500 } } await this.loadDoors() } catch (e) { diff --git a/templates/access/index.html b/templates/access/index.html index fc77efb..bcc7f3d 100644 --- a/templates/access/index.html +++ b/templates/access/index.html @@ -34,6 +34,14 @@ > + Edit door -
New door
+
+ {% raw %}{{ doorDialog.data.id ? 'Edit door' : 'New door' }}{% endraw %} +
Cancel - Create + {% raw %}{{ doorDialog.data.id ? 'Save' : 'Create' }}{% endraw %}