forked from mkay/Exim4UI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.js
117 lines (116 loc) · 4.49 KB
/
group.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* Generic functions */
function showItem(id) {
document.getElementById(id).style.display = '';
}
function hideItem(id) {
document.getElementById(id).style.display = 'none';
}
function displayStateMessage(message) {
document.getElementById('state').innerHTML = message;
}
function displayRunningMessage(message) {
document.getElementById('running').innerHTML = message;
}
function getContent(id) {
return document.getElementById(id).innerHTML;
}
function setContent(id, content) {
document.getElementById(id).innerHTML = content;
}
function emptyContent(id) {
document.getElementById(id).innerHTML = '';
}
function getAttribute(id, attName, attValue) {
document.getElementById(id).getAttribute(attName);
}
function setAttribute(id, attName, attValue) {
document.getElementById(id).setAttribute(attName, attValue);
}
/* Mailing list related functions */
function confirmDeleteMl(mlName, confirmMsg, itemToDelete, itemDeletedMsg, runningDeleteMsg) {
if (confirm(confirmMsg + ' ' + mlName)) {
displayRunningMessage(runningDeleteMsg + mlName);
deleteMailingList(mlName, {
'preloader':'running',
'onFinish': function(response) {
hideItem(itemToDelete);
displayStateMessage(itemDeletedMsg +': '+ mlName);
}});
} else {
displayStateMessage('');
}
}
function confirmSwitchMlStatus(mlName, mlStatusImg) {
var img = document.getElementById(mlStatusImg);
var enable = img.src.search(/enabled.png$/) == -1;
if (confirm('__Are sure you want to ' + (enable ? '__enable' : '__disable') + ' ' +
'__mailing list ' + mlName)) {
displayRunningMessage((enable ? '__Enabling' : '__Disabling') + ' ' + mlName);
changeMailingListStatus(mlName, enable, {
'preloader':'running',
'onFinish': function(response) {
img.src = enable ? 'images/enabled.png' : 'images/disabled.png';
displayStateMessage(mlName + ' ' + (enable ? '__enabled' : '__disabled'));
}});
} else {
displayStateMessage('');
}
}
function openEditMlForm(mlName) {
displayRunningMessage('__Fetching mailing list content');
hideItem('mlAndGroupLists');
setContent('mlActionType', 'update');
getMailingListEmails(mlName, {'preloader':'running',
'onUpdate': function(response) {
showItem('mledit');
// JSON text to object
ml = eval('(' + response + ')');
document.mleditform.mlcontent.value = ml.content;
document.getElementById('mlReplyTo_' + ml.replyTo).checked = 'true';
displayStateMessage('__Editing ' + mlName);
}});
setContent('mlNameTitle', mlName);
setAttribute('mlName', 'value', mlName);
}
function discardMlChanges() {
displayStateMessage('');
hideItem('mledit');
document.getElementById('mlcontent').value = '';
showItem('mlAndGroupLists');
return false;
}
function openAddMl() {
var localPart = prompt('__Enter mailing list local part', '');
if (localPart == null || localPart == '') {
displayStateMessage('__Mailing list creation canceled');
} else {
hideItem('mlAndGroupLists');
displayStateMessage('__Creating mailing list ' + localPart);
setContent('mlNameTitle', localPart);
setContent('mlActionType', 'create');
setAttribute('mlName', 'value', localPart);
showItem('mledit');
document.getElementById('mlcontent').value = '';
}
}
function saveMlChanges(form) {
displayStateMessage('');
return PLX.Submit(form, {
'preloader':'running',
'onFinish': function(response) {
if ('ok' == response) {
hideItem('mledit');
displayStateMessage(getContent('mlNameTitle') + ' ' + '__saved');
showItem('mlAndGroupLists');
if (getContent('mlActionType') == 'create') {
window.location.href=window.location.href;
} else {
// todo: we should refresh mailing list description
// or reload the page
}
} else {
displayStateMessage('__Update failed, edit your input');
alert(response);
}
}});
}