From 59c29e9c76952933c19f2ae9d9ae0bf7076d7e35 Mon Sep 17 00:00:00 2001 From: darkgallium Date: Wed, 18 Aug 2021 12:44:44 +0200 Subject: show everyone in the directory page by default --- directory.go | 5 +++-- static/javascript/search.js | 30 ++++++++++++++---------------- templates/directory.html | 5 +++++ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/directory.go b/directory.go index 06afdf2..ab5dea3 100644 --- a/directory.go +++ b/directory.go @@ -43,7 +43,7 @@ func handleDirectorySearch(w http.ResponseWriter, r *http.Request) { r.ParseMultipartForm(1024) input := strings.TrimSpace(strings.Join(r.Form["query"], "")) - if r.Method != "POST" || input == "" { + if r.Method != "POST" { http.Error(w, "Invalid request", http.StatusBadRequest) return } @@ -79,7 +79,8 @@ func handleDirectorySearch(w http.ResponseWriter, r *http.Request) { results := []SearchResult{} for _, values := range sr.Entries { - if ContainsI(values.GetAttributeValue(config.UserNameAttr), input) || + if input == "" || + ContainsI(values.GetAttributeValue(config.UserNameAttr), input) || ContainsI(values.GetAttributeValue("displayname"), input) || ContainsI(values.GetAttributeValue("mail"), input) { results = append(results, SearchResult{ diff --git a/static/javascript/search.js b/static/javascript/search.js index 2a75889..be3bd86 100644 --- a/static/javascript/search.js +++ b/static/javascript/search.js @@ -2,23 +2,21 @@ var last_id = 0; function searchDirectory() { var input = document.getElementById("search").value; - if(input){ - last_id++; - var request_id = last_id; + last_id++; + var request_id = last_id; - var data = new FormData(); - data.append("query", input); + var data = new FormData(); + data.append("query", input); - var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function() { - if (request_id != last_id) return; + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (request_id != last_id) return; - if (this.readyState == 4 && this.status == 200) { - var result_div = document.getElementById("search-results"); - result_div.innerHTML = xhttp.responseText; - } - }; - xhttp.open("POST", "/directory/search", true); - xhttp.send(data); - } + if (this.readyState == 4 && this.status == 200) { + var result_div = document.getElementById("search-results"); + result_div.innerHTML = xhttp.responseText; + } + }; + xhttp.open("POST", "/directory/search", true); + xhttp.send(data); } diff --git a/templates/directory.html b/templates/directory.html index d995fb2..a1c058a 100644 --- a/templates/directory.html +++ b/templates/directory.html @@ -19,5 +19,10 @@
+ {{end}} -- cgit v1.2.3