From e21efa3aaf7aeddc55b8768d9a6ad87fc4c04d0b Mon Sep 17 00:00:00 2001
From: coderick14
Date: Thu, 8 Jun 2017 15:14:16 +0530
Subject: Add autocomplete feature
---
templates/admin/changeMID.html | 52 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
(limited to 'templates/admin/changeMID.html')
diff --git a/templates/admin/changeMID.html b/templates/admin/changeMID.html
index 5aff464..721a6b8 100644
--- a/templates/admin/changeMID.html
+++ b/templates/admin/changeMID.html
@@ -10,7 +10,8 @@
Username:
-
+
+
@@ -63,6 +64,55 @@
}
+ // for live search of usernames
+ if (sessionStorage.getItem("fetchedUsers") == null) {
+ var BASE_URL = window.location.origin;
+ var request = $.ajax({
+ url: BASE_URL + '/admin/getusers',
+ method: 'POST'
+ });
+
+ request.done(function(data){
+ if (data.status_code == 200) {
+ sessionStorage.setItem("fetchedUsers", true);
+ populateUsers(data.message);
+ appendUsers();
+ }
+ else {
+ console.log("Sorry. Unable to implement live search");
+ }
+ });
+ }
+
+ function populateUsers(data) {
+ for (username of data) {
+ sessionStorage.setItem("sbhsuser"+username, username);
+ }
+ }
+
+ function appendUsers() {
+ if (sessionStorage.getItem("fetchedUsers")) {
+ var i, matchedUsers = [];
+ query = "sbhsuser";
+ for (i in sessionStorage) {
+ if (sessionStorage.hasOwnProperty(i)) {
+ if (i.match(query)) {
+ value = sessionStorage.getItem(i);
+ matchedUsers.push(value);
+ }
+ }
+ }
+ options = "";
+ for (matchedUser of matchedUsers) {
+ options += "";
+ }
+ if (options.length != 0) {
+ document.getElementById("users").innerHTML = options;
+ }
+ }
+ }
+
+ appendUsers();
{% endblock %}
\ No newline at end of file
--
cgit