mirror of
https://github.com/45Drives/cockpit-navigator.git
synced 2025-07-26 23:24:30 +02:00
update ModalPrompt module
This commit is contained in:
parent
d01a9ef665
commit
074f52c0be
@ -1,20 +1,19 @@
|
||||
/*
|
||||
Cockpit Navigator - A File System Browser for Cockpit.
|
||||
ModalPrompt - A Custom Prompt Module for Cockpit Plugins.
|
||||
Copyright (C) 2021 Josh Boudreau <jboudreau@45drives.com>
|
||||
Copyright (C) 2021 Sam Silver <ssilver@45drives.com>
|
||||
Copyright (C) 2021 Dawson Della Valle <ddellavalle@45drives.com>
|
||||
|
||||
This file is part of Cockpit Navigator.
|
||||
Cockpit Navigator is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the Lesser GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
Cockpit Navigator is distributed in the hope that it will be useful,
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Cockpit Navigator. If not, see <https://www.gnu.org/licenses/>.
|
||||
Lesser GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the Lesser GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -168,8 +167,20 @@ export class ModalPrompt {
|
||||
this.footer.innerHTML = "";
|
||||
this.footer.append(this.cancel, this.ok);
|
||||
let inputs = [];
|
||||
let simple_prompt = false;
|
||||
|
||||
|
||||
if (typeof requests === "string") {
|
||||
let label = requests;
|
||||
simple_prompt = true;
|
||||
requests = {
|
||||
"key": {
|
||||
"label": label,
|
||||
"type": "text"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof requests === "object") {
|
||||
let req_holder = document.createElement("div");
|
||||
req_holder.style.display = "flex";
|
||||
req_holder.style.flexFlow = "column nowrap";
|
||||
@ -208,7 +219,6 @@ export class ModalPrompt {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.show();
|
||||
inputs[0].focus();
|
||||
@ -222,7 +232,11 @@ export class ModalPrompt {
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ok.onclick = () => {
|
||||
let response = {};
|
||||
let response
|
||||
if (simple_prompt) {
|
||||
response = inputs[0].value;
|
||||
} else {
|
||||
response = {};
|
||||
for (let input of inputs) {
|
||||
switch (input.type) {
|
||||
case "checkbox":
|
||||
@ -234,6 +248,7 @@ export class ModalPrompt {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
resolve(response);
|
||||
this.hide();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user