From 757d5d2a16f9b147e2fdc36ab54b7f6e4b35ac0b Mon Sep 17 00:00:00 2001 From: venizelou andreas Date: Mon, 23 Sep 2024 22:57:58 +0300 Subject: [PATCH] API, front-end --- Protest/Front/api.js | 105 +++++++++++++++++++++++++++++++++++++++- Protest/Front/backup.js | 4 +- 2 files changed, 105 insertions(+), 4 deletions(-) diff --git a/Protest/Front/api.js b/Protest/Front/api.js index 3c27fc90..e16b5663 100644 --- a/Protest/Front/api.js +++ b/Protest/Front/api.js @@ -17,7 +17,7 @@ class Api extends List { this.createButton = this.AddToolbarButton("Create API link", "mono/add.svg?light"); this.deleteButton = this.AddToolbarButton("Delete", "mono/delete.svg?light"); - this.createButton.onclick = ()=> this.Create(); + this.createButton.onclick = ()=> this.CreateDialog(); this.deleteButton.onclick = ()=> this.Delete(); this.UpdateAuthorization(); @@ -30,11 +30,112 @@ class Api extends List { super.UpdateAuthorization(); } - Create() { + CreateDialog() { + const dialog = this.DialogBox("420px"); + if (dialog === null) return; + const {okButton, innerBox} = dialog; + + okButton.value = "Create"; + + innerBox.parentElement.style.maxWidth = "640px"; + + innerBox.style.padding = "16px 32px"; + innerBox.style.display = "grid"; + innerBox.style.gridTemplateColumns = "auto 150px 275px auto"; + innerBox.style.gridTemplateRows = "repeat(6, 38px) 72px"; + innerBox.style.alignItems = "center"; + + let counter = 0; + const AddParameter = (name, tag, type, properties) => { + counter++; + + const label = document.createElement("div"); + label.style.gridArea = `${counter} / 2`; + label.textContent = `${name}:`; + + const input = document.createElement(tag); + input.style.gridArea = `${counter} / 3`; + if (type) { + input.type = type; + } + + for (let param in properties) { + input[param] = properties[param]; + } + + innerBox.append(label, input); + + return input; + }; + + const nameInput = AddParameter("Name", "input", "text"); + + setTimeout(()=>nameInput.focus(), 200); + + okButton.onclick = async ()=> { + let requiredFieldMissing = false; + let requiredFields = [nameInput]; + + for (let i=0; i { + try { + const response = await fetch(`api/delete?name=${encodeURIComponent(this.args.select)}`); + if (response.status !== 200) LOADER.HttpErrorHandler(response.status); + + const json = await response.json(); + if (json.error) throw(json.error); + + this.selected = null; + this.args.select = null; + this.link = json; + this.ListCerts(); + } + catch (ex) { + this.ConfirmBox(ex, true, "mono/error.svg") + } + }); } } \ No newline at end of file diff --git a/Protest/Front/backup.js b/Protest/Front/backup.js index 64ae104f..c9a7ab5f 100644 --- a/Protest/Front/backup.js +++ b/Protest/Front/backup.js @@ -19,7 +19,7 @@ class Backup extends List { this.AddToolbarSeparator(); this.downloadButton = this.AddToolbarButton("Download", "mono/download.svg?light"); - this.createButton.onclick = ()=> this.Create(); + this.createButton.onclick = ()=> this.CreateDialog(); this.deleteButton.onclick = ()=> this.Delete(); this.downloadButton.onclick = ()=> this.Download(); @@ -70,7 +70,7 @@ class Backup extends List { } } - Create() { + CreateDialog() { const dialog = this.DialogBox("108px"); if (dialog === null) return;