From f7d6c8db1fd7fa82c7da96d0f06da4e49fbd9a05 Mon Sep 17 00:00:00 2001 From: amy Date: Thu, 16 Feb 2023 14:04:44 -0600 Subject: a certified mess --- src/window-utils.js | 159 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 151 insertions(+), 8 deletions(-) (limited to 'src/window-utils.js') diff --git a/src/window-utils.js b/src/window-utils.js index 7cdbd7c..2755878 100644 --- a/src/window-utils.js +++ b/src/window-utils.js @@ -1,9 +1,152 @@ let util = { - alert(inp){ - - window_create(document.getElementsByClassName("window").length, - (inp.title == undefined ? "Alert" : inp.title), - " "+ (inp.content == undefined ? "Alert" : inp.content), - {width:220,height:110,resize:false}) - } -} \ No newline at end of file + async alert(inp) { + let promise = new Promise(async (res, rej) => { + bu = []; + if (inp.buttons == undefined) { + bu = ["ok", "no"]; + } else { + bu = inp.buttons; + } + let buttons = ""; + let i = document.getElementsByClassName("window").length; + for (let b of bu) { + buttons += + ""; + } + + await window_create( + i, + inp.title == undefined ? "Alert" : inp.title, + ` + + + +
${ + inp.content == undefined ? "Alert" : inp.content + }${buttons}
`, + { width: 220, height: 110, resize: false } + ); + for (let b of bu) { + document.getElementById(i + "-content-button-" + b).onclick = () => { + res(b); + }; + } + }); + return promise; + }, + async fd(inp) { + let promise = new Promise(async (res, rej) => { + let i = document.getElementsByClassName("window").length; + let sel = []; + await window_create(i, "fs", ""); + function load() { + let ll = new jssh(fs, "/", i, "null", "null", window_create); + let tfs = ll.set_wd(ll.clean_path(inp.path)); + let files = ""; + for (let f of tfs) { + if (f.dir) { + files += + "
" + + f.name + + "
"; + } else { + files += + "
" + + f.name + + "
"; + } + } + files += + "
file/directory name:
" + + sel.join(",") + + (sel.length == 0 ? "select a file!" : "") + + "
" + + "" + + "
"; + document.getElementById(i + "-content-content").innerHTML = files; + for (let f of tfs) { + let tt = document.getElementById(i + "-id-name-" + f.name); + let dou = false; + tt.onclick = (ev) => { + if (dou) { + console.log(f, inp); + if (f.dir) { + inp.path += f.name; + } else { + if (f.name.includes(".exe")) + ll.ex_file(inp.path + "/" + f.name); + else { + if (inp.open_file == true || inp.open_file == undefined) { + let iii = ll.ex_file("/apps/notepad.exe"); + document.getElementById( + iii + "-content-content" + ).firstChild.value = ll.get_file( + inp.path + "/" + f.name + ).content; + } else { + return inp.path + "/" + f.name; + } + //console.log(); + } + } + load(); + dou = false; + } else { + dou = true; + + tt.style.backgroundColor = "blue"; + setTimeout(() => { + if (dou) { + if (ev.ctrlKey) { + if (sel.includes(f.name)) { + sel.splice(sel.indexOf(f.name), 1); + } else sel.push(f.name); + } else sel = [f.name]; + //sel = [f.name]; + document.getElementById(i + "-fd-bottom-sel").innerHTML = + sel.join(",") + (sel.length == 0 ? "select a file!" : ""); + for (let aa of tfs) { + let ttt = document.getElementById( + i + "-id-name-" + aa.name + ); + if (sel.includes(aa.name)) { + ttt.style.backgroundColor = "blue"; + } else { + ttt.style.backgroundColor = ""; + } + } + //load(); + dou = false; + } + }, 200); + } + }; + } + } + load(); + }); + return promise; + }, +}; -- cgit v1.2.3