Skip to content

Commit feed670

Browse files
tessuserikdubbelboer
authored andcommitted
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
1 parent 65880d3 commit feed670

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

js/index.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $(function() {
1212
$(this).html('Select all');
1313
}
1414
})
15-
15+
1616
$('#sidebar').on('click', 'a', function(e) {
1717
if (e.currentTarget.className.indexOf('batch_del') !== -1){
1818
e.preventDefault();
@@ -51,24 +51,24 @@ $(function() {
5151
if (e.currentTarget.href.indexOf('/?') == -1) {
5252
return;
5353
}
54-
54+
5555
e.preventDefault();
56-
56+
5757
var href;
58-
58+
5959
if ((e.currentTarget.href.indexOf('?') == -1) ||
6060
(e.currentTarget.href.indexOf('?') == (e.currentTarget.href.length - 1))) {
6161
href = 'overview.php';
6262
} else {
6363
href = e.currentTarget.href.substr(e.currentTarget.href.indexOf('?') + 1);
64-
64+
6565
if (href.indexOf('&') != -1) {
6666
href = href.replace('&', '.php?');
6767
} else {
6868
href += '.php';
6969
}
7070
}
71-
71+
7272
if (href.indexOf('flush.php') == 0) {
7373
if (confirm('Are you sure you want to delete this key and all it\'s values?')) {
7474
$.ajax({
@@ -90,24 +90,17 @@ $(function() {
9090
});
9191

9292
$('#server').change(function(e) {
93-
if (location.href.indexOf('?') == -1) {
94-
location.href = location.href+'?s='+e.target.value;
95-
} else if (location.href.indexOf('&s=') == -1) {
96-
location.href = location.href+'&s='+e.target.value;
97-
} else {
98-
location.href = location.href.replace(/s=[0-9]*/, 's='+e.target.value);
99-
}
93+
// always show overview when switching server, only keep var s (old database index might not exist on new server)
94+
const base = location.href.split('?', 1)[0];
95+
location.href = base + '?overview&s=' + e.target.value;
10096
});
10197

10298

10399
$('#database').change(function(e) {
104-
if (location.href.indexOf('?') == -1) {
105-
location.href = location.href+'?d='+e.target.value;
106-
} else if (location.href.indexOf('&d=') == -1) {
107-
location.href = location.href+'&d='+e.target.value;
108-
} else {
109-
location.href = location.href.replace(/d=[0-9]*/, 'd='+e.target.value);
110-
}
100+
// 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)
101+
const base = location.href.split('?', 1)[0];
102+
const s = location.href.match(/s=[0-9]*/);
103+
location.href = base + '?overview&' + s + '&d=' + e.target.value;
111104
});
112105

113106

0 commit comments

Comments
 (0)