diff options
author | Helmut K. C. Tessarek <tessarek@evermeet.cx> | 2019-11-21 00:22:52 +0300 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2019-11-21 00:22:52 +0300 |
commit | feed670bbdcb81b673de85f3327e0c232c915fd9 (patch) | |
tree | 1128b735cc6b4ebb8becd5f74ca9b89b6e8bc37e | |
parent | 65880d35bb745870f27a390e30ff98424cee16af (diff) |
fix switching server and database (#153)
always show overview when switching
- server, only keep var s (old database index might not exist on new server)
- db, only keep vars s and d (whatever we are doing (show/edit key) won't be valid on new db)
fixes #89, fixes #151
-rw-r--r-- | js/index.js | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/js/index.js b/js/index.js index de45790..3557014 100644 --- a/js/index.js +++ b/js/index.js @@ -12,7 +12,7 @@ $(function() { $(this).html('Select all'); } }) - + $('#sidebar').on('click', 'a', function(e) { if (e.currentTarget.className.indexOf('batch_del') !== -1){ e.preventDefault(); @@ -51,24 +51,24 @@ $(function() { if (e.currentTarget.href.indexOf('/?') == -1) { return; } - + e.preventDefault(); - + var href; - + if ((e.currentTarget.href.indexOf('?') == -1) || (e.currentTarget.href.indexOf('?') == (e.currentTarget.href.length - 1))) { href = 'overview.php'; } else { href = e.currentTarget.href.substr(e.currentTarget.href.indexOf('?') + 1); - + if (href.indexOf('&') != -1) { href = href.replace('&', '.php?'); } else { href += '.php'; } } - + if (href.indexOf('flush.php') == 0) { if (confirm('Are you sure you want to delete this key and all it\'s values?')) { $.ajax({ @@ -90,24 +90,17 @@ $(function() { }); $('#server').change(function(e) { - if (location.href.indexOf('?') == -1) { - location.href = location.href+'?s='+e.target.value; - } else if (location.href.indexOf('&s=') == -1) { - location.href = location.href+'&s='+e.target.value; - } else { - location.href = location.href.replace(/s=[0-9]*/, 's='+e.target.value); - } + // always show overview when switching server, only keep var s (old database index might not exist on new server) + const base = location.href.split('?', 1)[0]; + location.href = base + '?overview&s=' + e.target.value; }); $('#database').change(function(e) { - if (location.href.indexOf('?') == -1) { - location.href = location.href+'?d='+e.target.value; - } else if (location.href.indexOf('&d=') == -1) { - location.href = location.href+'&d='+e.target.value; - } else { - location.href = location.href.replace(/d=[0-9]*/, 'd='+e.target.value); - } + // always show overview when switching db, only keep vars s and d (whatever we are doing (show/edit key) won't be valid on new db) + const base = location.href.split('?', 1)[0]; + const s = location.href.match(/s=[0-9]*/); + location.href = base + '?overview&' + s + '&d=' + e.target.value; }); |