add order

This commit is contained in:
Xavier Henner 2019-08-28 07:58:34 +02:00
parent 53ec762bbb
commit c288f25dfe
2 changed files with 47 additions and 18 deletions

File diff suppressed because one or more lines are too long

View File

@ -153,8 +153,6 @@ select.interface {
return; return;
} }
last_change = data["last_change"]; last_change = data["last_change"];
$('#result>tbody').remove();
$('#result').append('<tbody></ybody>');
$.each(data, function(index, infos) { $.each(data, function(index, infos) {
if (!infos) { if (!infos) {
return; return;
@ -172,46 +170,77 @@ select.interface {
} }
}); });
} else if (index == "sessions") { } else if (index == "sessions") {
$.each(infos, function(pid, infos) { var sessions = [];
$.each(infos, function(pid, s) {
s.pid = pid;
sessions.push(s);
});
sessions.sort(function SortSearch(a, b){
if(a['provider'] > b['provider']) {
return 1;
}
if(a['provider'] < b['provider']) {
return -1;
}
if(a['identifier'] > b['identifier']) {
return 1;
}
if(a['identifier'] < b['identifier']) {
return -1;
}
if(a['active-vpn'] > b['active-vpn']) {
return 1;
}
if(a['active-vpn'] < b['active-vpn']) {
return -1;
}
return 0;
});
$('#result>tbody').remove();
$('#result').append('<tbody></ybody>');
$.each(sessions, function(key, session) {
pid = session.pid;
line = '<tr>'; line = '<tr>';
line +='<td'; line +='<td';
if(infos['status']=="Need Password") { if(session['status']=="Need Password") {
line += ' rowspan="2"'; line += ' rowspan="2"';
} }
line +='>'+infos['identifier']+'</td>'; line +='>'+session['identifier']+'</td>';
line +='<td>'+infos['provider']+'</td>'; line +='<td>'+session['provider']+'</td>';
if (possible=remotes[infos['provider']]) { if (possible=remotes[session['provider']]) {
line += '<td><select id="server_'+pid+'" onchange="server_change('+pid+')">' line += '<td><select id="server_'+pid+'" onchange="server_change('+pid+')">'
if (infos['active-vpn']=="") { if (session['active-vpn']=="") {
line += '<option value="">----------------</option>' line += '<option value="">----------------</option>'
} }
$.each(possible, function(name, remote) { $.each(possible, function(name, remote) {
line += '<option value="'+remote+'"'; line += '<option value="'+remote+'"';
if(remote == infos['active-vpn']) { if(remote == session['active-vpn']) {
line += ' selected '; line += ' selected ';
} }
line += '>'+name+'</option>'; line += '>'+name+'</option>';
}); });
line+='</select></td>' line+='</select></td>'
} else { } else {
line +='<td>'+infos['active-vpn']+'</td>'; line +='<td>'+session['active-vpn']+'</td>';
} }
line +='<td>'+infos['status']+'</td>'; line +='<td>'+session['status']+'</td>';
line += '<td>'; line += '<td>';
line += '<a href="javascript:vpn_restart('+pid+')"><img width="24" height="24" src="refresh.png"/></a>'; line += '<a href="javascript:vpn_restart('+pid+')"><img width="24" height="24" src="vpn/refresh.png"/></a>';
line += '<a href="javascript:vpn_kill('+pid+')"><img width="24" height="24" src="disconnect.png"/></a></td>'; line += '<a href="javascript:vpn_kill('+pid+')"><img width="24" height="24" src="vpn/disconnect.png"/></a></td>';
line += '</td>\n'; line += '</td>\n';
line += '</tr>\n'; line += '</tr>\n';
if(infos['status'].startsWith("Need")) { if(session['status'].startsWith("Need")) {
line +='<tr><td colspan="4">'; line +='<tr><td colspan="4">';
line +='<form id="auth_'+pid+'" action="#" onsubmit="auth('+pid+') ; return false" >'; line +='<form id="auth_'+pid+'" action="#" onsubmit="auth('+pid+') ; return false" >';
if (infos['status'].includes("Password")) { if (session['status'].includes("Password")) {
line +='<input class="user" placeholder="Enter login" size="15">'; line +='<input class="user" placeholder="Enter login" size="15">';
line +='<input type="password" placeholder="Password" size="15" class="pass">'; line +='<input type="password" placeholder="Password" size="15" class="pass">';
} }
if (infos['status'].includes("OTP")) { if (session['status'].includes("OTP")) {
line +='<input class="otp" placeholder="'+infos["message"]+'" size="15">'; line +='<input class="otp" placeholder="'+session["message"]+'" size="15">';
} }
line +='<input type="submit" value="G0">'; line +='<input type="submit" value="G0">';
line +='</form>'; line +='</form>';