add danger bool to confirm and sort groups/users

This commit is contained in:
joshuaboud 2021-07-15 13:00:45 -03:00
parent c4f800f948
commit c3b3f77935
No known key found for this signature in database
GPG Key ID: 17EFB59E2A8BF50E
4 changed files with 27 additions and 9 deletions

View File

@ -92,7 +92,7 @@ export class FileUpload {
async upload() {
if (await this.check_if_exists()) {
if (!await this.nav_window_ref.modal_prompt.confirm(this.filename + ": File exists. Replace?"))
if (!await this.nav_window_ref.modal_prompt.confirm(this.filename + ": File exists. Replace?", "", true))
return;
}
this.make_html_element();

View File

@ -1,10 +1,15 @@
/**
* @typedef {Object} Request
* @property {string} label
* @property {("text"|"checkbox")} type
* @property {"text"|"checkbox"} type
* @property {string|undefined} default
*/
let primary_btn = "pf-m-primary";
let secondary_btn = "pf-m-secondary";
let danger_btn = "pf-m-danger";
let all_btn = [primary_btn, secondary_btn, danger_btn];
export class ModalPrompt {
constructor() {
this.ok = document.createElement("button");
@ -98,14 +103,19 @@ export class ModalPrompt {
*
* @param {string} header
* @param {string} message
* @param {boolean} danger
* @returns {Promise<boolean>}
*/
confirm(header, message = "") {
confirm(header, message = "", danger = false) {
this.set_header(header);
this.set_body(message);
this.footer.innerHTML = "";
this.footer.append(this.no, this.yes);
// this.footer.appendChild(this.yes);
this.yes.classList.remove(... all_btn);
if (danger)
this.yes.classList.add(danger_btn);
else
this.yes.classList.add(primary_btn);
this.show();
return new Promise((resolve, reject) => {
let resolve_true = () => {

View File

@ -104,7 +104,7 @@ export class NavDir extends NavEntry {
});
proc.fail(async (e, data) => {
if (/^rmdir: failed to remove .*: Directory not empty\n?$/.test(data)) {
if (await this.nav_window_ref.modal_prompt.confirm("WARNING: '" + this.path_str() + "' is not empty.", "Delete recursively? This can NOT be undone.")) {
if (await this.nav_window_ref.modal_prompt.confirm("WARNING: '" + this.path_str() + "' is not empty.", "Delete recursively? This can NOT be undone.", true)) {
this.rm_recursive(resolve, reject);
}
} else {

View File

@ -4,7 +4,7 @@ import {NavContextMenu} from "./NavContextMenu.js";
import {NavDragDrop} from "./NavDragDrop.js";
import {SortFunctions} from "./SortFunctions.js";
import {ModalPrompt} from "./ModalPrompt.js";
import {format_bytes} from "../functions.js";
import {format_bytes, format_permissions} from "../functions.js";
export class NavWindow {
constructor() {
@ -268,7 +268,8 @@ export class NavWindow {
"Warning: editing " +
dangerous_selected_str +
" can be dangerous.",
"Are you sure?"
"Are you sure?",
true
)) {
return;
}
@ -277,7 +278,8 @@ export class NavWindow {
"Warning: editing permissions for " +
this.selected_entries.size +
" files.",
"Are you sure?"
"Are you sure?",
true
)) {
return;
}
@ -378,7 +380,7 @@ export class NavWindow {
} else {
prompt = "Deleting `" + this.selected_entry().path_str() + "`.";
}
if (!await this.modal_prompt.confirm(prompt, "This cannot be undone. Are you sure?")) {
if (!await this.modal_prompt.confirm(prompt, "This cannot be undone. Are you sure?", true)) {
return;
}
for (let target of this.selected_entries) {
@ -712,6 +714,9 @@ export class NavWindow {
return;
}
var passwd_entries = passwd.split("\n");
passwd_entries.sort((first, second) => {
return first.split(":")[0].localeCompare(second.split(":")[0]);
});
for (let entry of passwd_entries) {
var cols = entry.split(":");
var username = cols[0];
@ -745,6 +750,9 @@ export class NavWindow {
return;
}
var group_entries = group.split("\n");
group_entries.sort((first, second) => {
return first.split(":")[0].localeCompare(second.split(":")[0]);
});
for (let entry of group_entries) {
var cols = entry.split(":");
var groupname = cols[0];