add dialog confirm,
add resize handler Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
dbbb3ab09c
commit
37839d4117
@ -25,8 +25,7 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset class="fieldset-no-border">
|
<fieldset class="fieldset-no-border">
|
||||||
<div class="btn-group" id="form-actions">
|
<div class="btn-group" id="form-actions">
|
||||||
<button id="cancel" type="button">CANCEL</button>
|
<button id="cancel" type="button">Exit</button>
|
||||||
<button id="submit" type="button">SUBMIT</button>
|
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
18
css/dialog.css
Normal file
18
css/dialog.css
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
dialog {
|
||||||
|
background-color: #000000;
|
||||||
|
border: 1px solid white;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog::backdrop {
|
||||||
|
background: rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog .btn-group {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, h2, h3, p {
|
||||||
|
margin: 10px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import {requestPVE, requestAPI, goToPage, getURIData, reload, resources} from "./utils.js";
|
import {requestPVE, requestAPI, goToPage, getURIData, reload, resources} from "./utils.js";
|
||||||
|
import { Dialog } from "./elements.js";
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", init);
|
window.addEventListener("DOMContentLoaded", init);
|
||||||
|
|
||||||
@ -116,24 +117,36 @@ function addDiskLine (fieldset, busPrefix, busName, device, disk) {
|
|||||||
diskMetaData.actionBarOrder.forEach((element) => {
|
diskMetaData.actionBarOrder.forEach((element) => {
|
||||||
let action = document.createElement("img");
|
let action = document.createElement("img");
|
||||||
action.classList.add("clickable");
|
action.classList.add("clickable");
|
||||||
if (element === "delete_detach_attach" && diskMetaData[type][busPrefix].actions.includes("attach")){
|
if (element === "delete_detach_attach" && diskMetaData[type][busPrefix].actions.includes("attach")){ // attach
|
||||||
action.src = "images/actions/attach.svg";
|
action.src = "images/actions/attach.svg";
|
||||||
action.title = "Attach Disk";
|
action.title = "Attach Disk";
|
||||||
}
|
}
|
||||||
else if (element === "delete_detach_attach" && diskMetaData[type][busPrefix].actions.includes("detach")){
|
else if (element === "delete_detach_attach" && diskMetaData[type][busPrefix].actions.includes("detach")){ // detach
|
||||||
action.src = "images/actions/detach.svg";
|
action.src = "images/actions/detach.svg";
|
||||||
action.title = "Detach Disk";
|
action.title = "Detach Disk";
|
||||||
action.addEventListener("click", handleDiskDetach);
|
action.addEventListener("click", handleDiskDetach);
|
||||||
}
|
}
|
||||||
else if (element === "delete_detach_attach"){
|
else if (element === "delete_detach_attach"){
|
||||||
let active = diskMetaData[type][busPrefix].actions.includes("delete") ? "active" : "inactive";
|
let active = diskMetaData[type][busPrefix].actions.includes("delete") ? "active" : "inactive"; // delete
|
||||||
action.src = `images/actions/delete-${active}.svg`;
|
action.src = `images/actions/delete-${active}.svg`;
|
||||||
action.title = `Delete Disk`;
|
action.title = `Delete Disk`;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let active = diskMetaData[type][busPrefix].actions.includes(element) ? "active" : "inactive";
|
let active = diskMetaData[type][busPrefix].actions.includes(element) ? "active" : "inactive"; // resize
|
||||||
action.src = `images/actions/${element}-${active}.svg`;
|
action.src = `images/actions/${element}-${active}.svg`;
|
||||||
action.title = `${element.charAt(0).toUpperCase()}${element.slice(1)} Disk`;
|
action.title = `${element.charAt(0).toUpperCase()}${element.slice(1)} Disk`;
|
||||||
|
if (element === "config") {
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (element === "move") {
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (element === "resize") {
|
||||||
|
action.addEventListener("click", handleDiskResize);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
action.id = `${busPrefix}${device}`
|
action.id = `${busPrefix}${device}`
|
||||||
actionDiv.append(action);
|
actionDiv.append(action);
|
||||||
@ -142,6 +155,14 @@ function addDiskLine (fieldset, busPrefix, busName, device, disk) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleDiskDetach () {
|
async function handleDiskDetach () {
|
||||||
|
let dialog = document.createElement("dialog-form");
|
||||||
|
document.body.append(dialog);
|
||||||
|
dialog.body = `
|
||||||
|
<p>Detach ${this.id}</p>
|
||||||
|
<hr>
|
||||||
|
`;
|
||||||
|
dialog.callback = async (result, form) => {
|
||||||
|
if(result === "confirm") {
|
||||||
let body = {
|
let body = {
|
||||||
node: node,
|
node: node,
|
||||||
type: type,
|
type: type,
|
||||||
@ -156,6 +177,42 @@ async function handleDiskDetach () {
|
|||||||
else{
|
else{
|
||||||
console.error(result);
|
console.error(result);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
document.querySelector("dialog-form").remove();
|
||||||
|
};
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleDiskResize () {
|
||||||
|
let dialog = document.createElement("dialog-form");
|
||||||
|
document.body.append(dialog);
|
||||||
|
dialog.body = `
|
||||||
|
<p>Resize ${this.id}</p>
|
||||||
|
<hr>
|
||||||
|
<label for="size-increment">Size Increment (GiB)</label>
|
||||||
|
<input name="size-increment" type="number" min="0" max="131072" value="0">
|
||||||
|
<hr>
|
||||||
|
`;
|
||||||
|
dialog.callback = async (result, form) => {
|
||||||
|
if(result === "confirm") {
|
||||||
|
let body = {
|
||||||
|
node: node,
|
||||||
|
type: type,
|
||||||
|
vmid: vmid,
|
||||||
|
action: `disk=${this.id}&size=+${form.get("size-increment")}G`
|
||||||
|
}
|
||||||
|
let result = await requestAPI("/disk/resize", "POST", body);
|
||||||
|
if (result.status === 200) {
|
||||||
|
await getConfig();
|
||||||
|
populateDisk();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
console.error(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.querySelector("dialog-form").remove();
|
||||||
|
};
|
||||||
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOrderedUsed(disks){
|
function getOrderedUsed(disks){
|
||||||
|
@ -2,7 +2,7 @@ import {requestPVE, goToPage, instances} from "./utils.js";
|
|||||||
|
|
||||||
const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay));
|
const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay));
|
||||||
|
|
||||||
class Instance extends HTMLElement {
|
export class Instance extends HTMLElement {
|
||||||
constructor () {
|
constructor () {
|
||||||
super();
|
super();
|
||||||
let shadowRoot = this.attachShadow({mode: "open"});
|
let shadowRoot = this.attachShadow({mode: "open"});
|
||||||
@ -131,16 +131,17 @@ class Instance extends HTMLElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Dialog extends HTMLElement {
|
export class Dialog extends HTMLElement {
|
||||||
constructor () {
|
constructor () {
|
||||||
super();
|
super();
|
||||||
let shadowRoot = this.attachShadow({mode: "open"});
|
let shadowRoot = this.attachShadow({mode: "open"});
|
||||||
|
|
||||||
shadowRoot.innerHTML = `
|
shadowRoot.innerHTML = `
|
||||||
<link rel="stylesheet" href="css/style.css" type="text/css">
|
<link rel="stylesheet" href="css/style.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="css/form.css" type="text/css">
|
||||||
<link rel="stylesheet" href="css/dialog.css" type="text/css">
|
<link rel="stylesheet" href="css/dialog.css" type="text/css">
|
||||||
<dialog>
|
<dialog>
|
||||||
<form method="dialog"></form>
|
<form method="dialog" class="imput-grid" style="auto 1fr"></form>
|
||||||
</dialog>
|
</dialog>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -150,7 +151,8 @@ class Dialog extends HTMLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set body (body) {
|
set body (body) {
|
||||||
this.form.innerHTML = body + `
|
this.form.innerHTML = `
|
||||||
|
${body}
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button value="cancel">Cancel</button>
|
<button value="cancel">Cancel</button>
|
||||||
<button value="confirm">Confirm</button>
|
<button value="confirm">Confirm</button>
|
||||||
@ -159,11 +161,10 @@ class Dialog extends HTMLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set callback (callback) {
|
set callback (callback) {
|
||||||
this.dialog.addEventListener("close", () => {
|
this.dialog.addEventListener("close", async () => {
|
||||||
callback(this.dialog.returnValue, new FormData(this.form));
|
await callback(this.dialog.returnValue, new FormData(this.form));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
show () {
|
show () {
|
||||||
this.dialog.showModal();
|
this.dialog.showModal();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user