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() { async upload() {
if (await this.check_if_exists()) { 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; return;
} }
this.make_html_element(); this.make_html_element();

View File

@ -1,10 +1,15 @@
/** /**
* @typedef {Object} Request * @typedef {Object} Request
* @property {string} label * @property {string} label
* @property {("text"|"checkbox")} type * @property {"text"|"checkbox"} type
* @property {string|undefined} default * @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 { export class ModalPrompt {
constructor() { constructor() {
this.ok = document.createElement("button"); this.ok = document.createElement("button");
@ -98,14 +103,19 @@ export class ModalPrompt {
* *
* @param {string} header * @param {string} header
* @param {string} message * @param {string} message
* @param {boolean} danger
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
*/ */
confirm(header, message = "") { confirm(header, message = "", danger = false) {
this.set_header(header); this.set_header(header);
this.set_body(message); this.set_body(message);
this.footer.innerHTML = ""; this.footer.innerHTML = "";
this.footer.append(this.no, this.yes); 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(); this.show();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let resolve_true = () => { let resolve_true = () => {

View File

@ -104,7 +104,7 @@ export class NavDir extends NavEntry {
}); });
proc.fail(async (e, data) => { proc.fail(async (e, data) => {
if (/^rmdir: failed to remove .*: Directory not empty\n?$/.test(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); this.rm_recursive(resolve, reject);
} }
} else { } else {

View File

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