|
|
|
function disableList(listEmail){
|
|
|
|
$.post('/api/list/disable',{list:listEmail},showListResult,'json');
|
|
|
|
}
|
|
|
|
|
|
|
|
function dropList(listEmail){
|
|
|
|
console.log('dopList('+listEmail+')');
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableList(listEmail){
|
|
|
|
$.post('/api/list/enable',{list:listEmail},showListResult,'json');
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideList(listEmail){
|
|
|
|
$.post('/api/list/hide',{list:listEmail},showListResult,'json');
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadListAdminList(){
|
|
|
|
$.getJSON('/api/list/list', showListAdminList);
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadListList(){
|
|
|
|
$.getJSON('/api/list/list', showListList);
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadUserList(){
|
|
|
|
$.getJSON('/api/user/list', showUserList);
|
|
|
|
}
|
|
|
|
|
|
|
|
function reload(){
|
|
|
|
window.location.reload(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function showList(listEmail){
|
|
|
|
$.post('/api/list/show',{list:listEmail},showListResult,'json');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function showListAdminList(data){
|
|
|
|
for (let i in data.lists){
|
|
|
|
let list = data.lists[i];
|
|
|
|
let row = $('<tr/>');
|
|
|
|
let addr = list.email.prefix+'@'+list.email.domain;
|
|
|
|
|
|
|
|
$('<td/>').text(list.name).appendTo(row);
|
|
|
|
$('<td/>').text(addr).appendTo(row);
|
|
|
|
$('<td/>').text(list.state).appendTo(row);
|
|
|
|
|
|
|
|
let select = $('<select/>',{name:addr}).change(function () {
|
|
|
|
let action = $(this).children("option:selected").val();
|
|
|
|
let list = $(this).attr('name');
|
|
|
|
if (confirm("This will "+action+" '"+list+"'. Are you sure?"))self[action+'List'](list);
|
|
|
|
});
|
|
|
|
$('<option/>').text('Actions').appendTo(select);
|
|
|
|
['enable','disable','drop','hide','show'].forEach(val => $('<option/>',{value:val}).text(val).appendTo(select));
|
|
|
|
|
|
|
|
select.appendTo($('<td/>')).appendTo(row);
|
|
|
|
|
|
|
|
$('<td/>').text(list.imap_host).appendTo(row);
|
|
|
|
$('<td/>').text(list.imap_port).appendTo(row);
|
|
|
|
$('<td/>').text(list.imap_user).appendTo(row);
|
|
|
|
$('<td/>').text(list.smtp_host).appendTo(row);
|
|
|
|
$('<td/>').text(list.smtp_port).appendTo(row);
|
|
|
|
$('<td/>').text(list.smtp_user).appendTo(row);
|
|
|
|
row.appendTo('#listlist');
|
|
|
|
}
|
|
|
|
if (data.user.name == 'Admin'){
|
|
|
|
$('a[href=register]').show();
|
|
|
|
} else {
|
|
|
|
$('a[href=register]').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showListList(data){
|
|
|
|
for (let i in data.lists){
|
|
|
|
let list = data.lists[i];
|
|
|
|
let row = $('<tr/>');
|
|
|
|
let subBtn = $('<button/>',{onclick:"subscribeTo('"+list.email.domain+"', '"+list.email.prefix+"');"}).text('subscribe');
|
|
|
|
|
|
|
|
$('<td/>').text(list.name).appendTo(row);
|
|
|
|
$('<td/>',{class:'right'}).text(list.email.prefix).appendTo(row);
|
|
|
|
$('<td/>',{class:'right'}).text('@').appendTo(row);
|
|
|
|
$('<td/>').text(list.email.domain).appendTo(row);
|
|
|
|
$('<td/>').text(list.state).appendTo(row);
|
|
|
|
$('<td/>').html(subBtn).appendTo(row);
|
|
|
|
|
|
|
|
row.appendTo('#listlist');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showListResult(result){
|
|
|
|
console.log(result);
|
|
|
|
if ('error' in result){
|
|
|
|
alert(result.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ('success' in result){
|
|
|
|
alert(result.success);
|
|
|
|
reload();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
alert("Api call did not return result");
|
|
|
|
}
|
|
|
|
|
|
|
|
function showUserList(data){
|
|
|
|
for (let i in data.users){
|
|
|
|
let user = data.users[i];
|
|
|
|
let row = $('<tr/>');
|
|
|
|
$('<td/>').text(user.name).appendTo(row);
|
|
|
|
$('<td/>').text(user.email).appendTo(row);
|
|
|
|
$('<td/>').text(user.password).appendTo(row);
|
|
|
|
row.appendTo('#userlist');
|
|
|
|
}
|
|
|
|
if (data.user.name == 'Admin'){
|
|
|
|
$('a[href=register]').show();
|
|
|
|
} else {
|
|
|
|
$('a[href=register]').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function start(){
|
|
|
|
console.log("application started");
|
|
|
|
}
|
|
|
|
|
|
|
|
function subscribeTo(domain,prefix){
|
|
|
|
window.location.href='subscribe/'+prefix+'@'+domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$(start); // document.on ready
|