aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarkgallium <darkgallium@deuxfleurs.fr>2021-08-18 12:44:44 +0200
committerdarkgallium <darkgallium@deuxfleurs.fr>2021-08-18 12:44:44 +0200
commit59c29e9c76952933c19f2ae9d9ae0bf7076d7e35 (patch)
tree9edebe95b65254f60a087a24219148b637f87e7b
parenta187ae72cbd5960a0778679fba7535d67796f27e (diff)
downloadguichet-show-everyone-by-default.tar.gz
guichet-show-everyone-by-default.zip
show everyone in the directory page by defaultshow-everyone-by-default
-rw-r--r--directory.go5
-rw-r--r--static/javascript/search.js30
-rw-r--r--templates/directory.html5
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 @@
<div id="search-results"></div>
<script src="/static/javascript/search.js"></script>
+<script>
+window.addEventListener("load", function(event) {
+ searchDirectory();
+});
+</script>
{{end}}