var globalDb = [{"id":"3","description":"TestDescription2","group":"TestGroup","username":"TestUser2","password":"TestPass2"},{"id":"4","description":"TestDescription3","group":"TestGroup","username":"TestUser3","password":"TestPass3"}]; var globalGroups = [] var globalCurrentGroup = "" function AESEncrypt(source, phrase) { var encryptedAES = CryptoJS.AES.encrypt(source, phrase); return encryptedAES.toString(); } function AESDecrypt(source, phrase) { var decryptedBytes = CryptoJS.AES.decrypt(source, phrase); return decryptedBytes.toString(CryptoJS.enc.Latin1); } function Decrypt(val) { var phrase = document.getElementById("PassPhrase").value; return AESDecrypt(val, phrase); } function Encrypt(val) { var phrase = document.getElementById("PassPhrase").value; return AESEncrypt(val, phrase); } function WebRequest(url, func, args) { var f; for(f = 0; f < args.length; f += 2) { if (f == 0) { url += "?"; } else { url += "#"; } url += args[f] + "="; url += encodeURIComponent(args[f+1]); } var req = new XMLHttpRequest(); req.addEventListener("load", func); req.open("GET", url); req.send(); } function ArrayContains(haystack, needle) { for(var f = 0; f < haystack.length; f++) { if (haystack[f] === needle) { return true; } } return false; } function LoadGroups(keep_selection) { globalGroups = []; for(var f = 0; f < globalDb.length; f++) { var group = globalDb[f].group; if (!ArrayContains(globalGroups, group)) { globalGroups.push(group); } } if (!keep_selection) { globalCurrentGroup = ""; } if (!ArrayContains(globalGroups, globalCurrentGroup)) { if (globalGroups.length > 0) { globalCurrentGroup = globalGroups[0]; } else { globalCurrentGroup = ""; } } var elem = document.getElementById("Group"); while(elem.length > 0) { elem.remove(0); } for(var f = 0; f < globalGroups.length; f++) { var option = document.createElement("option"); option.text = globalGroups[f]; option.value = globalGroups[f]; elem.add(option); } alert(globalCurrentGroup); elem.value = globalCurrentGroup; } function AddTableInputCell(id, text, name, tr) { var td = document.createElement("td"); var input = document.createElement("input"); input.value = text; input.id = name + id; input.type = "text"; td.appendChild(input); tr.appendChild(td); } function AddRow(table, id, desc, username, password, rowcount) { var tr = document.createElement("tr"); if ((rowcount % 2) == 1) { tr.style = "style1"; } else { tr.style = "style2"; } AddTableInputCell(id, desc, "Description", tr); AddTableInputCell(id, username, "Username", tr); AddTableInputCell(id, password, "Password", tr); var td = document.createElement("td"); if (id == -1) { td.innerText = "Stuff for new entry"; } else { td.innerText = "Stuff for existing entry"; } tr.appendChild(td); table.appendChild(tr); } function LoadTable() { var table = document.getElementById("DataTable"); table.innerHTML = ""; var rowcount = 0; for(var f = 0; f < globalDb.length; f++) { if (globalDb[f].group == globalCurrentGroup) { AddRow(table, globalDb[f].id, globalDb[f].description, globalDb[f].username, Decrypt(globalDb[f].password), rowcount++); } } AddRow(table, -1, "", "", "", rowcount++); } function LoadInitialData() { LoadGroups(false); LoadTable(); } function DoLoadAsync() { globalDb = JSON.parse(this.responseText); LoadInitialData(); } function DoLoad() { // WebRequest("get.php", DoLoadAsync, []); LoadInitialData(); } function DoSelectGroup() { var elem = document.getElementById("Group"); globalCurrentGroup = elem.value; LoadTable(); } // vim: sw=4 ts=4