From 4b6e37397d3a9a80db0c20484b712175c7b9c9c7 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 24 Nov 2025 15:55:20 +0100 Subject: add password-dialog --- static/widgets/password-dialog/index.js | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 static/widgets/password-dialog/index.js (limited to 'static/widgets/password-dialog/index.js') diff --git a/static/widgets/password-dialog/index.js b/static/widgets/password-dialog/index.js new file mode 100644 index 0000000..334e02d --- /dev/null +++ b/static/widgets/password-dialog/index.js @@ -0,0 +1,60 @@ +import * as sfw from 'sfw'; +const { Div, Input } = sfw.element.native; + +import * as api from '../../api/index.js'; + +import icons from '../../icons/index.js'; + +const css = await sfw.css(import.meta.url, './index.css'); + +export default class PasswordDialog extends sfw.element.Container { + #current + #new + #confirm + #error + + constructor() { + super({ css }); + + this.callclose = () => this.close(); + + document.body.addEventListener('click', this.callclose); + this.onclick = (e) => e.stopPropagation(); + + this.body.append(Div.new({ + id: 'container', + children: [ + Div.new({ id: 'title', innerText: 'Change Password' }), + Div.new({ id: 'close', children: [ icons.close ], onclick: () => this.close() }), + this.#current = Input.new({ placeholder: 'Current Password', type: 'password' }), + this.#new = Input.new({ placeholder: 'New Password', type: 'password' }), + this.#confirm = Input.new({ placeholder: 'Confirm Password', type: 'password' }), + this.#error = Div.new({ id: 'error', className: 'hidden' }), + Div.new({ + id: 'button', + innerText: 'Update', + onclick: async () => { + if (this.#new.value !== this.#confirm.value) { + this.#error.innerText = 'Passwords do not match'; + this.#error.className = ''; + return; + } + + if (!await api.profile.update_password(this.#current.value, this.#new.value)) { + this.#error.innerText = 'invalid password'; + this.#error.className = ''; + return; + } + + this.close(); + }, + }), + ], + })); + } + + close() { + this.parentNode.removeChild(this); + document.body.removeEventListener('click', this.callclose); + } +} -- cgit v1.2.3-70-g09d2