diff options
author | MrArmonius <mrarmonius@gmail.com> | 2021-07-26 16:54:51 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-08-16 12:54:08 +0200 |
commit | cf4918e901da8f2c388eebd33a500bf737943685 (patch) | |
tree | 63492edb25cc0a5a01a317744efce85a6015a4a2 /static/javascript/search.js | |
parent | 819d7bf02f1c7b119468c1353b78a3d3bb7015fe (diff) | |
download | guichet-cf4918e901da8f2c388eebd33a500bf737943685.tar.gz guichet-cf4918e901da8f2c388eebd33a500bf737943685.zip |
Add MessageID for asynchronous request
ID is stored in the session with the type `uint32`
Correction javascript
For the `for loop`, we need don't forget than know we have in format
`JSON` the response: `search:{..}, id:0`
For the id, don't forget to change the global value of `JS`.
Diffstat (limited to 'static/javascript/search.js')
-rw-r--r-- | static/javascript/search.js | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/static/javascript/search.js b/static/javascript/search.js index b82b232..7675c0e 100644 --- a/static/javascript/search.js +++ b/static/javascript/search.js @@ -1,3 +1,5 @@ +var perso_id = 0; + function searchDirectory() { var input = document.getElementById("search").value; if(input){ @@ -8,23 +10,26 @@ function searchDirectory() { //Response from Request Ajax var jsonResponse = JSON.parse(xhttp.responseText); - //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"); + if (perso_id < jsonResponse.id) { + perso_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).length; i++) { - var row = table.insertRow(0); - var identifiant = row.insertCell(0); - var name = row.insertCell(1); - var email = row.insertCell(2); - identifiant.innerHTML = `<a href="/admin/ldap/${jsonResponse[i].dn}">${jsonResponse[i].identifiant}</a>` - name.innerHTML = jsonResponse[i].name - email.innerHTML = jsonResponse[i].email + for (let i =0; i < Object.keys(jsonResponse.search).length; i++) { + var row = table.insertRow(0); + var identifiant = row.insertCell(0); + var name = row.insertCell(1); + var email = row.insertCell(2); + identifiant.innerHTML = `<a href="/admin/ldap/${jsonResponse.search[i].dn}">${jsonResponse.search[i].identifiant}</a>` + name.innerHTML = jsonResponse.search[i].name + email.innerHTML = jsonResponse.search[i].email + } + old_table.parentNode.replaceChild(table, old_table) } - old_table.parentNode.replaceChild(table, old_table) } }; xhttp.overrideMimeType("application/json"); |