This repository has been archived by the owner on Nov 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathaliases.js
203 lines (162 loc) · 6.75 KB
/
aliases.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
+-----------------------------------------------------------------------+
| PostfixAdmin Aliases Plugin for RoundCube |
| Version: 1.3.6 |
| Author: Gianluca Giacometti <php@gianlucagiacometti.it> |
| Copyright (C) 2012 Gianluca Giacometti |
| License: GNU General Public License |
+-----------------------------------------------------------------------+
code structure based on:
+-----------------------------------------------------------------------+
| SieveRules Module for RoundCube |
| by Philip Weir |
| Licensed under the GNU GPL |
+-----------------------------------------------------------------------+
*/
rcube_webmail.prototype.aliases_select = function(list) {
if (this.aliases_timer)
clearTimeout(rcmail.aliases_timer);
var id;
if (id = list.get_single_selection())
rcmail.aliases_timer = window.setTimeout(function(id) { rcmail.aliases_load(id, 'plugin.aliases.edit'); }, 200, id);
}
rcube_webmail.prototype.aliases_keypress = function(list) {
if (list.key_pressed == list.DELETE_KEY)
rcmail.command('plugin.aliases.delete');
else if (list.key_pressed == list.BACKSPACE_KEY)
rcmail.command('plugin.aliases.delete');
}
rcube_webmail.prototype.aliases_mouse_up = function(e) {
if (rcmail.aliases_list) {
if (!rcube_mouse_is_over(e, rcmail.aliases_list.list))
rcmail.aliases_list.blur();
}
};
rcube_webmail.prototype.aliases_load = function(id, action) {
if (action == 'plugin.aliases.edit' && (!id || id == rcmail.env.iid))
return false;
var add_url = '';
var target = window;
if (rcmail.env.contentframe && window.frames && window.frames[rcmail.env.contentframe]) {
add_url = '&_framed=1';
target = window.frames[rcmail.env.contentframe];
rcube_find_object(rcmail.env.contentframe).style.visibility = 'inherit';
}
if (action && (id || action == 'plugin.aliases.add')) {
rcmail.set_busy(true);
target.location.href = rcmail.env.comm_path+'&_action='+action+'&_iid='+id+add_url;
}
return true;
}
rcube_webmail.prototype.aliases_ready = function(id) {
if (id.substring(0, 2) != 'ex')
rcmail.enable_command('plugin.aliases.delete', true);
rcmail.aliases_list.highlight_row(id);
rcmail.env.iid = id;
return true;
}
rcube_webmail.prototype.aliases_get_index = function(list, value, fallback) {
fallback = fallback || 0;
for (var i = 0; i < list.length; i++) {
if (list[i].value == value)
return i;
}
return fallback;
}
rcube_webmail.prototype.aliases_load_setup = function() {
var add_url = '';
var target = window;
if (rcmail.env.contentframe && window.frames && window.frames[rcmail.env.contentframe]) {
add_url = '&_framed=1';
target = window.frames[rcmail.env.contentframe];
rcube_find_object(rcmail.env.contentframe).style.visibility = 'inherit';
}
target.location.href = rcmail.env.comm_path+'&_action=plugin.aliases.setup' + add_url;
}
$(document).ready(function() {
if (window.rcmail) {
rcmail.addEventListener('init', function(evt) {
if ((rcmail.env.action == 'plugin.aliases') && !rcmail.env.aliaseserror) {
if (rcmail.gui_objects.aliases_list) {
rcmail.aliases_list = new rcube_list_widget(rcmail.gui_objects.aliases_list, {multiselect:false, draggable:true, keyboard:true});
// override blur function to prevent current alias being deselected
rcmail.aliases_list.blur = function() {}
rcmail.aliases_list.addEventListener('select', function(o) { rcmail.aliases_select(o); });
rcmail.aliases_list.addEventListener('keypress', function(o) { rcmail.aliases_keypress(o); });
document.onmouseup = function(e) { return rcmail.aliases_mouse_up(e); };
rcmail.aliases_list.init();
rcmail.aliases_list.focus();
if (rcmail.env.iid && rcmail.env.iid < rcmail.aliases_list.rowcount && !rcmail.env.eid)
rcmail.aliases_list.select_row(rcmail.env.iid, false, false);
}
if (rcmail.env.action == 'plugin.aliases') {
rcmail.register_command('plugin.aliases.add', function(id) {
rcmail.aliases_list.clear_selection();
rcmail.env.iid = null;
rcmail.enable_command('plugin.aliases.delete', false);
var add_url = '';
var target = window;
if (rcmail.env.contentframe && window.frames && window.frames[rcmail.env.contentframe]) {
add_url = '&_framed=1';
target = window.frames[rcmail.env.contentframe];
rcube_find_object(rcmail.env.contentframe).style.visibility = 'inherit';
}
target.location.href = rcmail.env.comm_path+'&_action=plugin.aliases.add' + add_url;
}, true);
}
rcmail.register_command('plugin.aliases.delete', function(id) {
if (confirm(rcmail.get_label('aliasesaliasdeleteconfirm','aliases'))) {
var add_url = '';
var target = window;
if (rcmail.env.contentframe && window.frames && window.frames[rcmail.env.contentframe]) {
add_url = '&_framed=1';
target = window.frames[rcmail.env.contentframe];
rcube_find_object(rcmail.env.contentframe).style.visibility = 'inherit';
}
target.location.href = rcmail.env.comm_path+'&_action=plugin.aliases.delete&_iid=' + rcmail.env.iid + add_url;
rcmail.enable_command('plugin.aliases.delete', false);
}
}, false);
}
if (rcmail.env.action == 'plugin.aliases.add' || rcmail.env.action == 'plugin.aliases.edit') {
rcmail.register_command('plugin.aliases.save', function() {
var rows, rowcount;
if (rcmail.env.framed) {
rows = parent.rcmail.aliases_list.rows;
rowcount = parent.rcmail.aliases_list.rowcount;
}
else {
rows = rcmail.aliases_list.rows;
rowcount = rcmail.aliases_list.rowcount;
}
var input_name = rcube_find_object('_name');
if (input_name && input_name.value == '') {
alert(rcmail.get_label('aliasesnovalidalias','aliases'));
input_name.focus();
return false;
}
for (var i = 0; i < rowcount; i++) {
if (rows[i] && input_name.value == rows[i].obj.cells[0].innerHTML && i != rcmail.env.iid) {
alert(rcmail.get_label('aliasesaliasexists','aliases'));
input_name.focus();
return false;
}
}
rcmail.addEventListener('plugin.aliases.checkaliasdomain', check_duplicates);
rcmail.http_post('plugin.aliases.check', { _newalias: input_name.value });
function check_duplicates(response)
{
if (response != "") {
alert(rcmail.get_label('aliasesaliasexistsindomain','aliases'));
input_name.focus();
return false;
}
else {
rcmail.gui_objects.editform.submit();
}
}
}, true);
}
});
}
});