summaryrefslogtreecommitdiff
path: root/www/scripts
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2018-06-27 14:17:13 +0000
committerIan C <ianc@noddybox.co.uk>2018-06-27 14:17:13 +0000
commite19daf5e4efe081a721ba627df5cf5499930d497 (patch)
tree591e02023f139e8f9b9e012aee3f2823a707937c /www/scripts
parentc4c55c23c564160a7150062ffb73041f21de70e9 (diff)
Initial attempts at adding the commands.
Diffstat (limited to 'www/scripts')
-rw-r--r--www/scripts/main.js203
1 files changed, 194 insertions, 9 deletions
diff --git a/www/scripts/main.js b/www/scripts/main.js
index 9c77f56..f10139f 100644
--- a/www/scripts/main.js
+++ b/www/scripts/main.js
@@ -3,6 +3,19 @@ var globalDb = [{"id":"3","description":"TestDescription2","group":"TestGroup","
var globalGroups = []
var globalCurrentGroup = ""
+function Error(message)
+{
+ alert(message);
+}
+
+function Copy(id)
+{
+ var elem = document.getElementById(id);
+
+ elem.select();
+ document.execCommand("copy");
+}
+
function AESEncrypt(source, phrase)
{
var encryptedAES = CryptoJS.AES.encrypt(source, phrase);
@@ -43,7 +56,7 @@ function WebRequest(url, func, args)
}
else
{
- url += "#";
+ url += "&";
}
url += args[f] + "=";
@@ -70,6 +83,13 @@ function ArrayContains(haystack, needle)
return false;
}
+function IsEmpty(id)
+{
+ var elem = document.getElementById(id);
+
+ return elem.value == "";
+}
+
function LoadGroups(keep_selection)
{
globalGroups = [];
@@ -121,7 +141,7 @@ function LoadGroups(keep_selection)
elem.value = globalCurrentGroup;
}
-function AddTableInputCell(id, text, name, node)
+function AddTableInputCell(id, text, name, maxlen, classname, node)
{
var td = document.createElement("td");
var input = document.createElement("input");
@@ -129,6 +149,9 @@ function AddTableInputCell(id, text, name, node)
input.value = text;
input.id = name + id;
input.type = "text";
+ input.maxLength = maxlen;
+
+ td.className = classname;
td.appendChild(input);
node.appendChild(td);
@@ -147,10 +170,17 @@ function AddSmallLink(node, text, func, id)
node.appendChild(anchor);
}
-function AddNBSP(node)
+function AddText(node, text)
+{
+ var t = document.createTextNode(text);
+ node.appendChild(t);
+}
+
+function AddElement(node, elementname)
{
- var nbsp = document.createTextNode("\u00a0");
- node.appendChild(nbsp);
+ var elem = document.createElement(elementname);
+
+ node.appendChild(elem);
}
function AddRow(table, id, desc, username, password, rowcount)
@@ -166,12 +196,14 @@ function AddRow(table, id, desc, username, password, rowcount)
tr.className = "style2";
}
- AddTableInputCell(id, desc, "Description", tr);
- AddTableInputCell(id, username, "Username", tr);
- AddTableInputCell(id, password, "Password", tr);
+ AddTableInputCell(id, desc, "Description", 1024, "description", tr);
+ AddTableInputCell(id, username, "Username", 256, "username", tr);
+ AddTableInputCell(id, password, "Password", 256, "password", tr);
var td = document.createElement("td");
+ td.className = "commands";
+
if (id == -1)
{
AddSmallLink(td, "Add", DoAdd, id);
@@ -179,8 +211,14 @@ function AddRow(table, id, desc, username, password, rowcount)
else
{
AddSmallLink(td, "Edit", DoEdit, id);
- AddNBSP(td);
+ AddText(td, "\u00a0");
+ AddText(td, "\u00a0");
AddSmallLink(td, "Delete", DoDelete, id);
+ AddElement(td, "br");
+ AddSmallLink(td, "Copy Username", DoCopyUsername, id);
+ AddText(td, "\u00a0");
+ AddText(td, "\u00a0");
+ AddSmallLink(td, "Copy Password", DoCopyPassword, id);
}
tr.appendChild(td);
@@ -212,6 +250,18 @@ function LoadTable()
AddRow(table, -1, "", "", "", rowcount++);
}
+function RefreshDataAsync()
+{
+ globalDb = JSON.parse(this.responseText);
+ LoadGroups(true);
+ LoadTable();
+}
+
+function RefreshData()
+{
+ WebRequest("get.php", RefreshDataAsync, []);
+}
+
function LoadInitialData()
{
LoadGroups(false);
@@ -226,6 +276,12 @@ function DoLoadAsync()
function DoLoad()
{
+ if (IsEmpty("PassPhrase"))
+ {
+ Error("Passphrase empty");
+ return;
+ }
+
// WebRequest("get.php", DoLoadAsync, []);
LoadInitialData();
}
@@ -235,19 +291,148 @@ function DoSelectGroup()
var elem = document.getElementById("Group");
globalCurrentGroup = elem.value;
+ document.getElementById("NewGroup").value = "";
LoadTable();
}
+function DoAddAsync()
+{
+ var response = JSON.parse(this.responseText);
+
+ if (response.error)
+ {
+ Error(response.error);
+ }
+ else
+ {
+ RefreshData();
+ }
+}
+
function DoAdd()
{
+ if (IsEmpty("Group") && IsEmpty("NewGroup"))
+ {
+ Error("No groups defined -- please enter a group name");
+ return;
+ }
+
+ var id = this.dataset.pmId;
+ var description = document.getElementById("Description" + id).value;
+ var username = document.getElementById("Username" + id).value;
+ var password = document.getElementById("Password" + id).value;
+ var group;
+
+ if (description == "" || username == "" | password == "")
+ {
+ Error("Please enter the description, username and password");
+ return;
+ }
+
+ if (!IsEmpty("NewGroup"))
+ {
+ group = document.getElementById("NewGroup").value;
+ document.getElementById("NewGroup").value = "";
+ }
+ else
+ {
+ group = document.getElementById("Group").value;
+ }
+
+ WebRequest("add.php", DoAddAsync,
+ [
+ "description", description,
+ "group", group,
+ "username", username,
+ "password", Encrypt(password)
+ ]
+ );
+}
+
+function DoEditAsync()
+{
+ var response = JSON.parse(this.responseText);
+
+ if (response.error)
+ {
+ Error(response.error);
+ }
+ else
+ {
+ RefreshData();
+ }
}
function DoEdit()
{
+ var id = this.dataset.pmId;
+ var description = document.getElementById("Description" + id).value;
+ var username = document.getElementById("Username" + id).value;
+ var password = document.getElementById("Password" + id).value;
+ var group;
+
+ if (description == "" || username == "" | password == "")
+ {
+ Error("Please enter the description, username and password");
+ return;
+ }
+
+ if (!IsEmpty("NewGroup"))
+ {
+ group = document.getElementById("NewGroup").value;
+ document.getElementById("NewGroup").value = "";
+ }
+ else
+ {
+ group = document.getElementById("Group").value;
+ }
+
+ WebRequest("edit.php", DoEditAsync,
+ [
+ "id", id,
+ "description", description,
+ "group", group,
+ "username", username,
+ "password", Encrypt(password)
+ ]
+ );
+}
+
+function DoDeleteAsync()
+{
+ var response = JSON.parse(this.responseText);
+
+ if (response.error)
+ {
+ Error(response.error);
+ }
+ else
+ {
+ RefreshData();
+ }
}
function DoDelete()
{
+ var id = this.dataset.pmId;
+
+ WebRequest("delete.php", DoDeleteAsync,
+ [
+ "id", id
+ ]
+ );
+}
+
+function DoCopyUsername()
+{
+ var id = "Username" + this.dataset.pmId;
+ Copy(id);
+}
+
+function DoCopyPassword()
+{
+ var id = "Password" + this.dataset.pmId;
+ Copy(id);
}
// vim: sw=4 ts=4