f7110c1dd9b2 — Peter Sanchez 2 months ago
Adding emus picker from ols
3 files changed, 64 insertions(+), 0 deletions(-)

M views/honkform.html
M views/style.css
M web.go
M views/honkform.html +29 -0
@@ 44,4 44,33 @@ 
 <button>it's gonna be honked</button>
 <button name="preview" value="preview">preview</button>
 <button type=button name="cancel" value="cancel" onclick="cancelhonking()">cancel</button>
+</p><p>
+<svg class="emuload" onclick="loademus();" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-mood-neutral" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
+<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
+<circle cx="12" cy="12" r="9"></circle>
+<line x1="9" y1="10" x2="9.01" y2="10"></line>
+<line x1="15" y1="10" x2="15.01" y2="10"></line>
+</svg></p>
+<div id="emupicker">
+</div>
 </form>
+<script>
+function addemu(data){
+	const box = document.getElementById("honknoise");
+	box.value += data;
+}
+function loademus() {
+	div = document.getElementById("emupicker")
+	request = new XMLHttpRequest();
+	request.open('GET', '/emus')
+	request.onload = function(){
+		div.innerHTML = request.responseText
+	}
+	if (div.style.display === "none") {
+		div.style.display = "block";
+	} else {
+		div.style.display = "none";
+	}
+	request.send()
+}
+</script>

          
M views/style.css +5 -0
@@ 253,6 253,11 @@ input[type=file] {
 .honk	details.actions summary {
 		color: var(--fg-subtle);
 }
+
+#emupicker{height:300px;overflow-y:scroll;padding:3px;background:var(--bg-dark);border:solid 5px var(--fg-subtle);text-align:center;display:none;}
+#emupicker img{margin:0;}
+.emuload{background:var(--bg-page);padding:0.5em;}
+
 .subtle .noise {
 		color: var(--fg-subtle);
 		font-size: 0.8em;

          
M web.go +30 -0
@@ 50,6 50,8 @@ var honkSep = "h"
 
 var develMode = false
 
+var emunames []string
+
 func getuserstyle(u *login.UserInfo) template.CSS {
 	if u == nil {
 		return ""

          
@@ 147,6 149,15 @@ func homepage(w http.ResponseWriter, r *
 	honkpage(w, u, honks, templinfo)
 }
 
+func showemus(w http.ResponseWriter, r *http.Request) {
+	templinfo := getInfo(r)
+	templinfo["Emus"] = emunames
+	err := readviews.Execute(w, "emus.html", templinfo)
+	if err != nil {
+		elog.Print(err)
+	}
+}
+
 func showfunzone(w http.ResponseWriter, r *http.Request) {
 	var emunames, memenames []string
 	emuext := make(map[string]string)

          
@@ 2419,6 2430,22 @@ func bgmonitor() {
 	}
 }
 
+func emuinit() {
+	dir, err := os.Open(dataDir + "/emus")
+	if err == nil {
+		emunames, _ = dir.Readdirnames(0)
+		dir.Close()
+	}
+	for i, e := range emunames {
+		if len(e) > 4 {
+			emunames[i] = e[:len(e)-4]
+		}
+	}
+	sort.Slice(emunames, func(i, j int) bool {
+		return emunames[i] < emunames[j]
+	})
+}
+
 func serve() {
 	db := opendatabase()
 	login.Init(login.InitArgs{Db: db, Logger: ilog, Insecure: develMode})

          
@@ 2433,6 2460,7 @@ func serve() {
 	go tracker()
 	go bgmonitor()
 	loadLingo()
+	emuinit()
 
 	readviews = templates.Load(develMode,
 		viewDir+"/views/honkpage.html",

          
@@ 2451,6 2479,7 @@ func serve() {
 		viewDir+"/views/msg.html",
 		viewDir+"/views/header.html",
 		viewDir+"/views/onts.html",
+		viewDir+"/views/emus.html",
 		viewDir+"/views/honkpage.js",
 	)
 	if !develMode {

          
@@ 2550,6 2579,7 @@ func serve() {
 	loggedin.HandleFunc("/t", showconvoy)
 	loggedin.HandleFunc("/q", showsearch)
 	loggedin.HandleFunc("/hydra", webhydra)
+	loggedin.HandleFunc("/emus", showemus)
 	loggedin.Handle("/submithonker", login.CSRFWrap("submithonker", http.HandlerFunc(submithonker)))
 
 	err = http.Serve(listener, mux)