show everyone in the directory page by default #12
3 changed files with 22 additions and 18 deletions
|
@ -43,7 +43,7 @@ func handleDirectorySearch(w http.ResponseWriter, r *http.Request) {
|
||||||
r.ParseMultipartForm(1024)
|
r.ParseMultipartForm(1024)
|
||||||
input := strings.TrimSpace(strings.Join(r.Form["query"], ""))
|
input := strings.TrimSpace(strings.Join(r.Form["query"], ""))
|
||||||
|
|
||||||
if r.Method != "POST" || input == "" {
|
if r.Method != "POST" {
|
||||||
http.Error(w, "Invalid request", http.StatusBadRequest)
|
http.Error(w, "Invalid request", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,8 @@ func handleDirectorySearch(w http.ResponseWriter, r *http.Request) {
|
||||||
results := []SearchResult{}
|
results := []SearchResult{}
|
||||||
|
|
||||||
for _, values := range sr.Entries {
|
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("displayname"), input) ||
|
||||||
ContainsI(values.GetAttributeValue("mail"), input) {
|
ContainsI(values.GetAttributeValue("mail"), input) {
|
||||||
results = append(results, SearchResult{
|
results = append(results, SearchResult{
|
||||||
|
|
|
@ -2,23 +2,21 @@ var last_id = 0;
|
||||||
|
|
||||||
function searchDirectory() {
|
function searchDirectory() {
|
||||||
var input = document.getElementById("search").value;
|
var input = document.getElementById("search").value;
|
||||||
if(input){
|
last_id++;
|
||||||
last_id++;
|
var request_id = last_id;
|
||||||
var request_id = last_id;
|
|
||||||
|
|
||||||
var data = new FormData();
|
var data = new FormData();
|
||||||
data.append("query", input);
|
data.append("query", input);
|
||||||
|
|
||||||
var xhttp = new XMLHttpRequest();
|
var xhttp = new XMLHttpRequest();
|
||||||
xhttp.onreadystatechange = function() {
|
xhttp.onreadystatechange = function() {
|
||||||
if (request_id != last_id) return;
|
if (request_id != last_id) return;
|
||||||
|
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
var result_div = document.getElementById("search-results");
|
var result_div = document.getElementById("search-results");
|
||||||
result_div.innerHTML = xhttp.responseText;
|
result_div.innerHTML = xhttp.responseText;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
xhttp.open("POST", "/directory/search", true);
|
xhttp.open("POST", "/directory/search", true);
|
||||||
xhttp.send(data);
|
xhttp.send(data);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,5 +19,10 @@
|
||||||
<div id="search-results"></div>
|
<div id="search-results"></div>
|
||||||
|
|
||||||
<script src="/static/javascript/search.js"></script>
|
<script src="/static/javascript/search.js"></script>
|
||||||
|
<script>
|
||||||
|
window.addEventListener("load", function(event) {
|
||||||
|
searchDirectory();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Loading…
Reference in a new issue