summaryrefslogtreecommitdiff
path: root/www/scripts/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/scripts/main.js')
-rw-r--r--www/scripts/main.js112
1 files changed, 76 insertions, 36 deletions
diff --git a/www/scripts/main.js b/www/scripts/main.js
index fe069dd..53027aa 100644
--- a/www/scripts/main.js
+++ b/www/scripts/main.js
@@ -3,27 +3,11 @@ var globalDb = [];
var globalGroups = [];
var globalCurrentGroup = "";
-var globalScrollY = 0;
-
function Error(message)
{
alert(message);
}
-function SaveScroll()
-{
- globalScrollY = window.pageYOffset;
-}
-
-function RestoreScroll()
-{
- if (globalScrollY > 0)
- {
- window.scroll(0, globalScrollY);
- globalScrollY = 0;
- }
-}
-
function SetEnable(id, enabled)
{
var elem = document.getElementById(id);
@@ -411,9 +395,27 @@ function LoadTable()
function RefreshDataAsync()
{
- globalDb = JSON.parse(this.responseText);
- LoadGroups(true);
- LoadTable();
+ try
+ {
+ globalDb = JSON.parse(this.responseText);
+ }
+ catch(e)
+ {
+ Error(e);
+ globalDb = [];
+ return;
+ }
+
+ if (globalDb.error)
+ {
+ Error(globalDb.error);
+ globalDb = [];
+ }
+ else
+ {
+ LoadGroups(true);
+ LoadTable();
+ }
}
function RefreshData()
@@ -429,7 +431,16 @@ function LoadInitialData()
function DoLoadAsync()
{
- globalDb = JSON.parse(this.responseText);
+ try
+ {
+ globalDb = JSON.parse(this.responseText);
+ }
+ catch(e)
+ {
+ Error(e);
+ globalDb = [];
+ return;
+ }
if (globalDb.error)
{
@@ -456,7 +467,15 @@ function DoLoad()
function DoChangePassphraseAsync()
{
- var response = JSON.parse(this.responseText);
+ try
+ {
+ var response = JSON.parse(this.responseText);
+ }
+ catch(e)
+ {
+ Error(e);
+ return;
+ }
if (response.error)
{
@@ -511,7 +530,15 @@ function DoSelectGroup()
function DoAddAsync()
{
- var response = JSON.parse(this.responseText);
+ try
+ {
+ var response = JSON.parse(this.responseText);
+ }
+ catch(e)
+ {
+ Error(e);
+ return;
+ }
if (response.error)
{
@@ -566,7 +593,15 @@ function DoAdd()
function DoEditAsync()
{
- var response = JSON.parse(this.responseText);
+ try
+ {
+ var response = JSON.parse(this.responseText);
+ }
+ catch(e)
+ {
+ Error(e);
+ return;
+ }
if (response.error)
{
@@ -616,7 +651,15 @@ function DoEdit()
function DoDeleteAsync()
{
- var response = JSON.parse(this.responseText);
+ try
+ {
+ var response = JSON.parse(this.responseText);
+ }
+ catch(e)
+ {
+ Error(e);
+ return;
+ }
if (response.error)
{
@@ -649,8 +692,6 @@ function DoCopyPassword()
{
var id = "Password" + this.dataset.pmId;
- SaveScroll();
-
if (!ShowPasswords())
{
SetInputType(id, "text");
@@ -662,15 +703,12 @@ function DoCopyPassword()
{
SetInputType(id, "password");
}
-
- RestoreScroll();
}
function DoShow()
{
if (!ShowPasswords())
{
- SaveScroll();
SetInputType("Password" + this.dataset.pmId, "text");
}
}
@@ -680,13 +718,20 @@ function DoHide()
if (!ShowPasswords())
{
SetInputType("Password" + this.dataset.pmId, "password");
- setTimeout(RestoreScroll, 0);
}
}
function DoReorderAsync()
{
- var response = JSON.parse(this.responseText);
+ try
+ {
+ var response = JSON.parse(this.responseText);
+ }
+ catch(e)
+ {
+ Error(e);
+ return;
+ }
if (response.error)
{
@@ -695,7 +740,6 @@ function DoReorderAsync()
else
{
RefreshData();
- RestoreScroll();
}
}
@@ -704,8 +748,6 @@ function DoUp()
var id = this.dataset.pmId;
var prev = this.dataset.pmPrevId;
- SaveScroll();
-
WebRequest("reorder.php", DoReorderAsync,
[
"from_id", id,
@@ -719,8 +761,6 @@ function DoDown()
var id = this.dataset.pmId;
var next = this.dataset.pmNextId;
- SaveScroll();
-
WebRequest("reorder.php", DoReorderAsync,
[
"from_id", id,