aboutsummaryrefslogtreecommitdiff
path: root/static/javascript/search.js
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-08-16 16:27:20 +0200
committerAlex Auvolat <alex@adnab.me>2021-08-16 16:27:20 +0200
commit01bf4aa52279630910ce33d065efcda77e6df7bb (patch)
tree78dd9c82e09388aae5fd9f4847c0b854f9846de5 /static/javascript/search.js
parente94bd728ec7f709883fb232b2eb123543ba5660e (diff)
downloadguichet-01bf4aa52279630910ce33d065efcda77e6df7bb.tar.gz
guichet-01bf4aa52279630910ce33d065efcda77e6df7bb.zip
Fix directory searching
Diffstat (limited to 'static/javascript/search.js')
-rw-r--r--static/javascript/search.js53
1 files changed, 13 insertions, 40 deletions
diff --git a/static/javascript/search.js b/static/javascript/search.js
index ea98e34..2a75889 100644
--- a/static/javascript/search.js
+++ b/static/javascript/search.js
@@ -1,51 +1,24 @@
-var perso_id = 0;
var last_id = 0;
function searchDirectory() {
var input = document.getElementById("search").value;
if(input){
- var xhttp = new XMLHttpRequest();
- xhttp.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 201) {
- // Typical action to be performed when the document is ready:
- //Response from Request Ajax
- var jsonResponse = JSON.parse(xhttp.responseText);
+ last_id++;
+ var request_id = last_id;
- if (last_id < jsonResponse.id) {
- last_id = jsonResponse.id
- //We get the old table element, we create an new table element then we increment this new table.
- //After the new add, we replace the old table by the new one.
- var old_table = document.getElementById("users");
- var table = document.createElement('tbody');
- table.setAttribute("id","users");
-
- for (let i =0; i < Object.keys(jsonResponse.search).length; i++) {
- var row = table.insertRow(0);
- var urlName = row.insertCell(0);
- var identifiant = row.insertCell(1);
- var displayname = row.insertCell(2);
- var email = row.insertCell(3);
- var description = row.insertCell(4);
- description.setAttribute("style", "word-break: break-all;");
+ var data = new FormData();
+ data.append("query", input);
- if (jsonResponse.search[i].dn.localeCompare("")!=0) {
- urlName.innerText = `<object data="/image/${jsonResponse.search[i].dn}/little" class=".img-thumbnail"><image src="/image/unknown_profile/little" class=".img-thumbnail"></object>`
- }else {
- urlName.innerText=""
- }
- identifiant.innerText = `<a href="/admin/ldap/${jsonResponse.search[i].dn}">${jsonResponse.search[i].id}</a>`
- displayname.innerText = jsonResponse.search[i].displayname
- email.innerText = jsonResponse.search[i].email
- description.innerText = jsonResponse.search[i].description
+ var xhttp = new XMLHttpRequest();
+ xhttp.onreadystatechange = function() {
+ if (request_id != last_id) return;
- }
- old_table.parentNode.replaceChild(table, old_table)
+ if (this.readyState == 4 && this.status == 200) {
+ var result_div = document.getElementById("search-results");
+ result_div.innerHTML = xhttp.responseText;
}
- }
};
- perso_id += 1
- xhttp.overrideMimeType("application/json");
- xhttp.open("POST", "/search/".concat(input), true);
- xhttp.send(JSON.stringify({"id": perso_id}));
+ xhttp.open("POST", "/directory/search", true);
+ xhttp.send(data);
}
-} \ No newline at end of file
+}