You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
243 lines
8.2 KiB
243 lines
8.2 KiB
function addMod(userEmail,listEmail){ |
|
$.post('/api/list/add_mod',{list:listEmail,email:userEmail},reload,'json'); |
|
} |
|
|
|
function addPermission(userEmail,permission){ |
|
if (confirm("Really give permission to "+userEmail+"?")){ |
|
$.post('/api/user/addpermission',{email:userEmail,permissions:permission},reload,'json'); |
|
} |
|
} |
|
|
|
function disableList(listEmail){ |
|
$.post('/api/list/disable',{list:listEmail},showListResult,'json'); |
|
} |
|
|
|
function dropList(listEmail){ |
|
$.post('/api/list/drop',{list:listEmail},showListResult,'json'); |
|
} |
|
|
|
function dropMember(userEmail,listEmail){ |
|
$.post('/api/list/drop_member',{list:listEmail,email:userEmail},reload,'json'); |
|
} |
|
|
|
function dropMod(userEmail,listEmail){ |
|
$.post('/api/list/drop_mod',{list:listEmail,email:userEmail},reload,'json'); |
|
} |
|
|
|
|
|
function dropPermission(userEmail,permission){ |
|
if (confirm("Really withdraw permission from "+userEmail+"?")){ |
|
$.post('/api/user/droppermission',{email:userEmail,permissions:permission},reload,'json'); |
|
} |
|
} |
|
|
|
|
|
function enableList(listEmail){ |
|
$.post('/api/list/enable',{list:listEmail},showListResult,'json'); |
|
} |
|
|
|
function hideList(listEmail){ |
|
$.post('/api/list/hide',{list:listEmail},showListResult,'json'); |
|
} |
|
|
|
function loadArchive(listEmail){ |
|
$.get('/api/list/archive?list='+listEmail,showListArchive,'json'); |
|
} |
|
|
|
function loadListDetail(listEmail){ |
|
$.post('/api/list/detail',{list:listEmail},showListDetail,'json'); |
|
} |
|
|
|
function loadListOfModeratedLists(){ |
|
$.getJSON('/api/list/moderated', showListOfModeratedLists); |
|
} |
|
|
|
function loadListOfSubscribableLists(){ |
|
$.getJSON('/api/list/subscribable', showListList); |
|
} |
|
|
|
function loadMembers(listEmail){ |
|
$.post('/api/list/members',{list:listEmail},showMembers,'json'); |
|
} |
|
|
|
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 showListArchive(data){ |
|
for (let time in data.archive){ |
|
let post = data.archive[time]; |
|
let row = $('<tr/>'); |
|
var url = 'post?id='+post.id; |
|
$('<td/>').html('<a href="'+url+'">'+new Date(post.date)+'</a>').appendTo(row); |
|
$('<td/>').html('<a href="'+url+'">'+post.from_name+'</a>').appendTo(row); |
|
$('<td/>').html('<a href="'+url+'">'+post.subject+'</a>').appendTo(row); |
|
row.appendTo($('#archive')); |
|
console.log(post); |
|
} |
|
} |
|
|
|
function showListDetail(data){ |
|
var options = ['forward_from','forward_attached','hide_receivers','reply_to_list','open_for_guests','open_for_subscribers','archive','edit_mods']; |
|
options.forEach(function(option,index,array){ |
|
console.log(option,'→',data[option]); |
|
if (data[option]) $('input[name="'+option+'"]').prop('checked',true); |
|
}); |
|
} |
|
|
|
function showListOfModeratedLists(data){ |
|
for (let i in data.lists){ |
|
let list = data.lists[i]; |
|
let row = $('<tr/>'); |
|
let addr = list.email.prefix+'@'+list.email.domain; |
|
let inspect = 'inspect?list='+addr; |
|
let td = $('<td/>'); |
|
$('<a/>',{href:inspect}).text(list.name).appendTo(td); |
|
td.appendTo(row); |
|
td = $('<td/>'); |
|
$('<a/>',{href:inspect}).text(addr).appendTo(td) |
|
td.appendTo(row); |
|
let states = []; |
|
for (let state in list.state){ |
|
if (list.state[state] > 0) states.push(state); |
|
} |
|
$('<td/>').text(states.toString()).appendTo(row); |
|
if (list.last_error){ |
|
$('<td/>').html('<span class="error">'+list.last_error+'</span>').appendTo(row); |
|
} else $('<td/>').text('-').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','test'].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.inbox).appendTo(row); |
|
$('<td/>').text(list.smtp_host).appendTo(row); |
|
$('<td/>').text(list.smtp_port).appendTo(row); |
|
row.appendTo('#listlist'); |
|
} |
|
if (data.user.permissions.includes('create lists')){ |
|
$('a[href=add_list]').show(); |
|
} else { |
|
$('a[href=add_list]').hide(); |
|
} |
|
} |
|
|
|
function showListList(data){ |
|
for (let i in data.lists){ |
|
let list = data.lists[i]; |
|
let row = $('<tr/>'); |
|
let email = list.email.prefix + '@' + list.email.domain; |
|
$('<td/>').html('<a href="archive?list='+email+'">'+list.name+'</a>').appendTo(row); |
|
$('<td/>').text(email).appendTo(row); |
|
let states = []; |
|
for (let state in list.state){ |
|
if (list.state[state] > 0) states.push(state); |
|
} |
|
$('<td/>').text(states.toString()).appendTo(row); |
|
let td = $('<td/>',{class:'actions'}); |
|
$('<button/>',{onclick:"subscribeTo('"+email+"');"}).text('subscribe').appendTo(td); |
|
$('<button/>',{onclick:"unsubscribeFrom('"+email+"');"}).text('unsubcribe').appendTo(td); |
|
td.appendTo(row); |
|
|
|
row.appendTo('#listlist'); |
|
} |
|
} |
|
|
|
function showListResult(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 showMembers(data){ |
|
var list_mail = data.list.email.prefix+'@'+data.list.email.domain; |
|
for (let i in data.members){ |
|
let member = data.members[i]; |
|
let row = $('<tr/>'); |
|
$('<td/>').text(member.name).appendTo(row); |
|
$('<td/>').text(member.email).appendTo(row); |
|
$('<td/>').text(member.state).appendTo(row); |
|
let col = $('<td/>'); |
|
console.log("data",data); |
|
if (member.state.includes("moderator")) { |
|
if (!member.state.includes("owner")) $('<button/>',{onclick:'dropMod("'+member.email+'","'+list_mail+'")'}).text("- moderator").appendTo(col); |
|
} else $('<button/>',{onclick:'addMod("'+member.email+'","'+list_mail+'")'}).text("+ moderator").appendTo(col); |
|
if (!member.state.includes("owner")) $('<button/>',{onclick:'dropMember("'+member.email+'","'+list_mail+'")'}).text("remove").appendTo(col); |
|
col.appendTo(row); |
|
|
|
row.appendTo('#memberlist'); |
|
} |
|
} |
|
|
|
function showUserList(data){ |
|
let isAdmin = data.user.permissions.includes('admin'); |
|
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); |
|
$('<td/>').text(user.permissions).appendTo(row); |
|
let permissions = $('<span/>'); |
|
if (isAdmin){ |
|
if (user.permissions.includes('admin')){ |
|
$('<button/>').text("- admin").click(() => dropPermission(user.email,1)).appendTo(permissions); |
|
} else { |
|
$('<button/>').text("+ admin").click(() => addPermission(user.email,1)).appendTo(permissions); |
|
} |
|
if (user.permissions.includes('create lists')){ |
|
$('<button/>').text("- create lists").click(() => dropPermission(user.email,2)).appendTo(permissions); |
|
} else { |
|
$('<button/>').text("+ create lists").click(() => addPermission(user.email,2)).appendTo(permissions); |
|
} |
|
} |
|
permissions.appendTo(row); |
|
row.appendTo('#userlist'); |
|
} |
|
if (isAdmin){ |
|
$('a[href=register]').show(); |
|
} else { |
|
$('a[href=register]').hide(); |
|
} |
|
} |
|
|
|
function start(){ |
|
console.log("application started"); |
|
} |
|
|
|
function subscribeTo(listEmail){ |
|
window.location.href='subscribe?list='+listEmail; |
|
} |
|
|
|
function testList(listEmail){ |
|
$.post('/api/list/test',{list:listEmail},showListResult,'json'); |
|
} |
|
|
|
function unsubscribeFrom(listEmail){ |
|
window.location.href='unsubscribe?list='+listEmail; |
|
} |
|
|
|
|
|
$(start); // document.on ready |