blob: cbf0193588d26ca007f58711129436e5b539d4df [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001$(document).ready(function() {
2 acl_data = JSON.parse(acl);
3 FooTable.domainFilter = FooTable.Filtering.extend({
4 construct: function(instance){
5 this._super(instance);
6 this.def = 'All Domains';
7 this.$domain = null;
8 },
9 $create: function(){
10 this._super();
11 var self = this;
12 var domains = [];
13
14 $.each(self.ft.rows.all, function(i, row){
15 if((row.val().domain != null) && ($.inArray(row.val().domain, domains) === -1)) domains.push(row.val().domain);
16 });
17
18 $form_grp = $('<div/>', {'class': 'form-group'})
19 .append($('<label/>', {'class': 'sr-only', text: 'Domain'}))
20 .prependTo(self.$form);
21 self.$domain = $('<select/>', { 'class': 'aform-control' })
22 .on('change', {self: self}, self._onDomainDropdownChanged)
23 .append($('<option/>', {text: self.def}))
24 .appendTo($form_grp);
25
26 $.each(domains, function(i, domain){
27 self.$domain.append($('<option/>').text(domain));
28 });
29 },
30 _onDomainDropdownChanged: function(e){
31 var self = e.data.self,
32 selected = $(this).val();
33 if (selected !== self.def){
34 self.addFilter('domain', selected, ['domain']);
35 } else {
36 self.removeFilter('domain');
37 }
38 self.filter();
39 },
40 draw: function(){
41 this._super();
42 var domain = this.find('domain');
43 if (domain instanceof FooTable.Filter){
44 this.$domain.val(domain.query.val());
45 } else {
46 this.$domain.val(this.def);
47 }
48 $(this.$domain).closest("select").selectpicker();
49 }
50 });
51 // Set paging
52 $('[data-page-size]').on('click', function(e){
53 e.preventDefault();
54 var new_size = $(this).data('page-size');
55 var parent_ul = $(this).closest('ul');
56 var table_id = $(parent_ul).data('table-id');
57 FooTable.get('#' + table_id).pageSize(new_size);
58 //$(this).parent().addClass('active').siblings().removeClass('active')
59 heading = $(this).parents('.panel').find('.panel-heading')
60 var n_results = $(heading).children('.table-lines').text().split(' / ')[1];
61 $(heading).children('.table-lines').text(function(){
62 if (new_size > n_results) {
63 new_size = n_results;
64 }
65 return new_size + ' / ' + n_results;
66 })
67 });
68 // Clone mailbox mass actions
69 $("div").find("[data-actions-header='true'").each(function() {
70 $(this).html($(this).nextAll('.mass-actions-mailbox:first').html());
71 });
72 // Auto-fill domain quota when adding new domain
73 auto_fill_quota = function(domain) {
74 $.get("/api/v1/get/domain/" + domain, function(data){
75 var result = $.parseJSON(JSON.stringify(data));
76 def_new_mailbox_quota = ( result.def_new_mailbox_quota / 1048576);
77 max_new_mailbox_quota = ( result.max_new_mailbox_quota / 1048576);
78 if (max_new_mailbox_quota != '0') {
79 $('.addInputQuotaExhausted').hide();
80 $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
81 $('#addInputQuota').attr({"disabled": false, "value": "", "type": "number", "max": max_new_mailbox_quota});
82 $('#addInputQuota').val(def_new_mailbox_quota);
83 }
84 else {
85 $('.addInputQuotaExhausted').show();
86 $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
87 $('#addInputQuota').attr({"disabled": true, "value": "", "type": "text", "value": "n/a"});
88 $('#addInputQuota').val(max_new_mailbox_quota);
89 }
90 });
91 }
92 $('#addSelectDomain').on('change', function() {
93 auto_fill_quota($('#addSelectDomain').val());
94 });
95 auto_fill_quota($('#addSelectDomain').val());
96 $(".goto_checkbox").click(function( event ) {
97 $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false);
98 if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
99 $('#textarea_alias_goto').prop('disabled', true);
100 }
101 else {
102 $("#textarea_alias_goto").removeAttr('disabled');
103 }
104 });
105 $('#addAliasModal').on('show.bs.modal', function(e) {
106 if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
107 $('#textarea_alias_goto').prop('disabled', true);
108 }
109 else {
110 $("#textarea_alias_goto").removeAttr('disabled');
111 }
112 });
113 // Log modal
114 $('#syncjobLogModal').on('show.bs.modal', function(e) {
115 var syncjob_id = $(e.relatedTarget).data('syncjob-id');
116 $.ajax({
117 url: '/inc/ajax/syncjob_logs.php',
118 data: { id: syncjob_id },
119 dataType: 'text',
120 success: function(data){
121 $(e.currentTarget).find('#logText').text(data);
122 },
123 error: function(xhr, status, error) {
124 $(e.currentTarget).find('#logText').text(xhr.responseText);
125 }
126 });
127 });
128 // Add Mailbox Modal
129 var addMailboxModalShown = false;
130 $('#addMailboxModal').on('show.bs.modal', function(e) {
131 if (addMailboxModalShown) {
132 return;
133 }
134 addMailboxModalShown = true;
135 var $domainSelect = $("#mailbox_table select");
136 if ($domainSelect[0].selectedIndex > 0) { // not "All Domains"
137 $("#addSelectDomain").val($domainSelect.val()).change().selectpicker("render");
138 }
139 });
140 // Log modal
141 $('#dnsInfoModal').on('show.bs.modal', function(e) {
142 var domain = $(e.relatedTarget).data('domain');
143 $('.dns-modal-body').html('<center><span style="font-size:18pt;margin:50px" class="glyphicon glyphicon-refresh glyphicon-spin"></span></center>');
144 $.ajax({
145 url: '/inc/ajax/dns_diagnostics.php',
146 data: { domain: domain },
147 dataType: 'text',
148 success: function(data){
149 $('.dns-modal-body').html(data);
150 },
151 error: function(xhr, status, error) {
152 $('.dns-modal-body').html(xhr.responseText);
153 }
154 });
155 });
156 // Sieve data modal
157 $('#sieveDataModal').on('show.bs.modal', function(e) {
158 var sieveScript = $(e.relatedTarget).data('sieve-script');
159 $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
160 });
161 // Disable submit button on script change
162 $('.textarea-code').on('keyup', function() {
163 // Disable all "save" buttons, could be a "related button only" function, todo
164 $('.add_sieve_script').attr({"disabled": true});
165 });
166 // Validate script data
167 $(".validate_sieve").click(function( event ) {
168 event.preventDefault();
169 var validation_button = $(this);
170 // Get script_data textarea content from form the button was clicked in
171 var script = $('textarea[name="script_data"]', $(this).parents('form:first')).val();
172 $.ajax({
173 dataType: 'json',
174 url: "/inc/ajax/sieve_validation.php",
175 type: "get",
176 data: { script: script },
177 complete: function(data) {
178 var response = (data.responseText);
179 response_obj = JSON.parse(response);
180 if (response_obj.type == "success") {
181 $(validation_button).next().attr({"disabled": false});
182 }
183 mailcow_alert_box(response_obj.msg, response_obj.type);
184 },
185 });
186 });
187 // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
188 // $("#active-script").closest('td').css('background-color','#b0f0a0');
189 // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
190 // });
191 $('#addResourceModal').on('shown.bs.modal', function() {
192 $("#multiple_bookings").val($("#multiple_bookings_select").val());
193 if ($("#multiple_bookings").val() == "custom") {
194 $("#multiple_bookings_custom_div").show();
195 $("#multiple_bookings").val($("#multiple_bookings_custom").val());
196 }
197 })
198 $("#multiple_bookings_select").change(function() {
199 $("#multiple_bookings").val($("#multiple_bookings_select").val());
200 if ($("#multiple_bookings").val() == "custom") {
201 $("#multiple_bookings_custom_div").show();
202 }
203 else {
204 $("#multiple_bookings_custom_div").hide();
205 }
206 });
207 $("#multiple_bookings_custom").bind ("change keypress keyup blur", function () {
208 $("#multiple_bookings").val($("#multiple_bookings_custom").val());
209 });
210
211
212});
213jQuery(function($){
214 // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
215 var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};
216 function escapeHtml(n){return String(n).replace(/[&<>"'`=\/]/g,function(n){return entityMap[n]})}
217 // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
218 function humanFileSize(i){if(Math.abs(i)<1024)return i+" B";var B=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],e=-1;do{i/=1024,++e}while(Math.abs(i)>=1024&&e<B.length-1);return i.toFixed(1)+" "+B[e]}
219 function unix_time_format(i){return""==i?'&#10005;':new Date(i?1e3*i:0).toLocaleDateString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})}
220 $(".refresh_table").on('click', function(e) {
221 e.preventDefault();
222 var table_name = $(this).data('table');
223 $('#' + table_name).find("tr.footable-empty").remove();
224 draw_table = $(this).data('draw');
225 eval(draw_table + '()');
226 });
227 function table_mailbox_ready(ft, name) {
228 if(is_dual) {
229 $('.login_as').data("toggle", "tooltip")
230 .attr("disabled", true)
231 .removeAttr("href")
232 .attr("title", "Dual login cannot be used twice")
233 .tooltip();
234 }
235 $('.refresh_table').prop("disabled", false);
236 heading = ft.$el.parents('.panel').find('.panel-heading')
237 var ft_paging = ft.use(FooTable.Paging)
238 $(heading).children('.table-lines').text(function(){
239 var total_rows = ft_paging.totalRows;
240 var size = ft_paging.size;
241 if (size > total_rows) {
242 size = total_rows;
243 }
244 return size + ' / ' + total_rows;
245 })
246 }
247 function draw_domain_table() {
248 ft_domain_table = FooTable.init('#domain_table', {
249 "columns": [
250 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
251 {"sorted": true,"name":"domain_name","title":lang.domain,"style":{"width":"250px"}},
252 {"name":"aliases","title":lang.aliases,"breakpoints":"xs sm"},
253 {"name":"mailboxes","title":lang.mailboxes},
254 {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
255 res = value.split("/");
256 return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
257 },
258 "sortValue": function(value){
259 res = value.split("/");
260 return Number(res[0]);
261 }},
262 {"name":"stats","sortable": false,"style":{"whiteSpace":"nowrap"},"title":lang.stats,"formatter": function(value){
263 res = value.split("/");
264 return '<span class="glyphicon glyphicon-file" aria-hidden="true"></span> ' + res[0] + ' / ' + humanFileSize(res[1]);
265 }},
266 {"name":"def_quota_for_mbox","title":lang.mailbox_defquota,"breakpoints":"xs sm md","style":{"width":"125px"}},
267 {"name":"max_quota_for_mbox","title":lang.mailbox_quota,"breakpoints":"xs sm","style":{"width":"125px"}},
268 {"name":"rl","title":"RL","breakpoints":"xs sm md lg","style":{"maxWidth":"100px","width":"100px"}},
269 {"name":"backupmx","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.backup_mx,"breakpoints":"xs sm md lg","formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
270 {"name":"domain_admins","title":lang.domain_admins,"style":{"word-break":"break-all","min-width":"200px"},"breakpoints":"xs sm md lg","filterable":(role == "admin"),"visible":(role == "admin")},
271 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
272 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"240px","width":"240px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
273 ],
274 "rows": $.ajax({
275 dataType: 'json',
276 url: '/api/v1/get/domain/all',
277 jsonp: false,
278 error: function (data) {
279 console.log('Cannot draw domain table');
280 },
281 success: function (data) {
282 $.each(data, function (i, item) {
283 item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
284 item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
285 item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain + "/" + item.bytes_total;
286 item.stats = item.msgs_total + "/" + item.bytes_total;
287 if (!item.rl) {
288 item.rl = '∞';
289 } else {
290 item.rl = $.map(item.rl, function(e){
291 return e;
292 }).join('/1');
293 }
294 item.def_quota_for_mbox = humanFileSize(item.def_quota_for_mbox);
295 item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
296 item.chkbox = '<input type="checkbox" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
297 item.action = '<div class="btn-group">';
298 if (role == "admin") {
299 item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
300 '<a href="#" data-action="delete_selected" data-id="single-domain" data-api-url="delete/domain" data-item="' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>';
301 }
302 else {
303 item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>';
304 }
305 item.action += '<a href="#dnsInfoModal" class="btn btn-xs btn-info" data-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><span class="glyphicon glyphicon-question-sign"></span> DNS</a></div>';
306 if (item.backupmx == 1) {
307 if (item.relay_unknown_only == 1) {
308 item.domain_name = '<div class="label label-info">Relay Non-Local</div> ' + item.domain_name;
309 } else if (item.relay_all_recipients == 1) {
310 item.domain_name = '<div class="label label-info">Relay All</div> ' + item.domain_name;
311 } else {
312 item.domain_name = '<div class="label label-info">Relay</div> ' + item.domain_name;
313 }
314 }
315 });
316 }
317 }),
318 "empty": lang.empty,
319 "paging": {
320 "enabled": true,
321 "limit": 5,
322 "size": pagination_size
323 },
324 "state": {
325 "enabled": true
326 },
327 "filtering": {
328 "enabled": true,
329 "delay": 1200,
330 "position": "left",
331 "connectors": false,
332 "placeholder": lang.filter_table
333 },
334 "sorting": {
335 "enabled": true
336 },
337 "on": {
338 "destroy.ft.table": function(e, ft){
339 $('.refresh_table').attr('disabled', 'true');
340 },
341 "ready.ft.table": function(e, ft){
342 table_mailbox_ready(ft, 'domain_table');
343 },
344 "after.ft.filtering": function(e, ft){
345 table_mailbox_ready(ft, 'domain_table');
346 }
347 },
348 "toggleSelector": "table tbody span.footable-toggle"
349 });
350 }
351 function draw_mailbox_table() {
352 ft_mailbox_table = FooTable.init('#mailbox_table', {
353 "columns": [
354 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
355 {"sorted": true,"name":"username","style":{"word-break":"break-all","min-width":"120px"},"title":lang.username},
356 {"name":"name","title":lang.fname,"style":{"word-break":"break-all","min-width":"120px"},"breakpoints":"xs sm md lg"},
357 {"name":"domain","title":lang.domain,"breakpoints":"xs sm md lg"},
358 {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
359 res = value.split("/");
360 var of_q = (res[1] == 0 ? "∞" : humanFileSize(res[1]));
361 return humanFileSize(res[0]) + " / " + of_q;
362 },
363 "sortValue": function(value){
364 res = value.split("/");
365 return Number(res[0]);
366 },
367 },
368 {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"all"},
369 {"name":"tls_enforce_in","filterable": false,"title":lang.tls_enforce_in,"breakpoints":"all"},
370 {"name":"tls_enforce_out","filterable": false,"title":lang.tls_enforce_out,"breakpoints":"all"},
371 {"name":"smtp_access","filterable": false,"title":"SMTP","breakpoints":"all"},
372 {"name":"imap_access","filterable": false,"title":"IMAP","breakpoints":"all"},
373 {"name":"pop3_access","filterable": false,"title":"POP3","breakpoints":"all"},
374 {"name":"last_mail_login","breakpoints":"xs sm","title":lang.last_mail_login,"style":{"width":"170px"},
375 "sortValue": function(value){
376 res = value.split("/");
377 return Math.max(res[0], res[1]);
378 },
379 "formatter": function(value){
380 res = value.split("/");
381 return '<div class="label label-last-login">IMAP @ ' + unix_time_format(Number(res[0])) + '</div><br>' +
382 '<div class="label label-last-login">POP3 @ ' + unix_time_format(Number(res[1])) + '</div><br>' +
383 '<div class="label label-last-login">SMTP @ ' + unix_time_format(Number(res[2])) + '</div>';
384 }},
385 {"name":"quarantine_notification","filterable": false,"title":lang.quarantine_notification,"breakpoints":"all"},
386 {"name":"quarantine_category","filterable": false,"title":lang.quarantine_category,"breakpoints":"all"},
387 {"name":"in_use","filterable": false,"type":"html","title":lang.in_use,"sortValue": function(value){
388 return Number($(value).find(".progress-bar-mailbox").attr('aria-valuenow'));
389 },
390 },
391 {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
392 {"name":"rl","title":"RL","breakpoints":"all","style":{"width":"125px"}},
393 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':(0==value?'&#10005;':2==value&&'&#8212;');}},
394 {"name":"action","filterable": false,"sortable": false,"style":{"min-width":"290px","text-align":"right"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
395 ],
396 "empty": lang.empty,
397 "rows": $.ajax({
398 dataType: 'json',
399 url: '/api/v1/get/mailbox/all',
400 jsonp: false,
401 error: function () {
402 console.log('Cannot draw mailbox table');
403 },
404 success: function (data) {
405 $.each(data, function (i, item) {
406 item.quota = item.quota_used + "/" + item.quota;
407 item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
408 item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login;
409 if (!item.rl) {
410 item.rl = '∞';
411 } else {
412 item.rl = $.map(item.rl, function(e){
413 return e;
414 }).join('/1');
415 if (item.rl_scope === 'domain') {
416 item.rl = '↪ ' + item.rl + ' (via ' + item.domain + ')';
417 }
418 }
419 item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
420 item.tls_enforce_in = '<span class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success' : 'danger') + ' glyphicon glyphicon-lock"></span>';
421 item.tls_enforce_out = '<span class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success' : 'danger') + ' glyphicon glyphicon-lock"></span>';
422 item.pop3_access = '<span class="text-' + (item.attributes.pop3_access == 1 ? 'success' : 'danger') + ' glyphicon glyphicon-' + (item.attributes.pop3_access == 1 ? 'ok' : 'remove') + '"></span>';
423 item.imap_access = '<span class="text-' + (item.attributes.imap_access == 1 ? 'success' : 'danger') + ' glyphicon glyphicon-' + (item.attributes.imap_access == 1 ? 'ok' : 'remove') + '"></span>';
424 item.smtp_access = '<span class="text-' + (item.attributes.smtp_access == 1 ? 'success' : 'danger') + ' glyphicon glyphicon-' + (item.attributes.smtp_access == 1 ? 'ok' : 'remove') + '"></span>';
425 if (item.attributes.quarantine_notification === 'never') {
426 item.quarantine_notification = lang.never;
427 } else if (item.attributes.quarantine_notification === 'hourly') {
428 item.quarantine_notification = lang.hourly;
429 } else if (item.attributes.quarantine_notification === 'daily') {
430 item.quarantine_notification = lang.daily;
431 } else if (item.attributes.quarantine_notification === 'weekly') {
432 item.quarantine_notification = lang.weekly;
433 }
434 if (item.attributes.quarantine_category === 'reject') {
435 item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
436 } else if (item.attributes.quarantine_category === 'add_header') {
437 item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
438 } else if (item.attributes.quarantine_category === 'all') {
439 item.quarantine_category = lang.q_all;
440 }
441 if (acl_data.login_as === 1) {
442 item.action = '<div class="btn-group">' +
443 '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
444 '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
445 '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="login_as btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>';
446 if (ALLOW_ADMIN_EMAIL_LOGIN) {
447 item.action += '<a href="/sogo-auth.php?login=' + encodeURIComponent(item.username) + '" class="login_as btn btn-xs btn-primary" target="_blank"><span class="glyphicon glyphicon-envelope"></span> SOGo</a>';
448 }
449 item.action += '</div>';
450 }
451 else {
452 item.action = '<div class="btn-group">' +
453 '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
454 '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
455 '</div>';
456 }
457 item.in_use = '<div class="progress">' +
458 '<div class="progress-bar-mailbox progress-bar progress-bar-' + item.percent_class + '" role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
459 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
460 item.username = escapeHtml(item.username);
461 });
462 }
463 }),
464 "paging": {
465 "enabled": true,
466 "limit": 5,
467 "size": pagination_size
468 },
469 "state": {
470 "enabled": true
471 },
472 "filtering": {
473 "enabled": true,
474 "delay": 1200,
475 "position": "left",
476 "connectors": false,
477 //"container": "#tab-mailboxes.panel",
478 "placeholder": lang.filter_table
479 },
480 "components": {
481 "filtering": FooTable.domainFilter
482 },
483 "sorting": {
484 "enabled": true
485 },
486 "on": {
487 "destroy.ft.table": function(e, ft){
488 $('.refresh_table').attr('disabled', 'true');
489 },
490 "ready.ft.table": function(e, ft){
491 table_mailbox_ready(ft, 'mailbox_table');
492 },
493 "after.ft.filtering": function(e, ft){
494 table_mailbox_ready(ft, 'mailbox_table');
495 }
496 },
497 "toggleSelector": "table tbody span.footable-toggle"
498 });
499 }
500 function draw_resource_table() {
501 ft_resource_table = FooTable.init('#resource_table', {
502 "columns": [
503 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
504 {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
505 {"name":"name","title":lang.alias},
506 {"name":"kind","title":lang.kind},
507 {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
508 {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"150px","width":"140px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
509 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
510 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
511 ],
512 "empty": lang.empty,
513 "rows": $.ajax({
514 dataType: 'json',
515 url: '/api/v1/get/resource/all',
516 jsonp: false,
517 error: function () {
518 console.log('Cannot draw resource table');
519 },
520 success: function (data) {
521 $.each(data, function (i, item) {
522 if (item.multiple_bookings == '0') {
523 item.multiple_bookings = '<span id="active-script" class="label label-success">' + lang.booking_0_short + '</span>';
524 } else if (item.multiple_bookings == '-1') {
525 item.multiple_bookings = '<span id="active-script" class="label label-warning">' + lang.booking_lt0_short + '</span>';
526 } else {
527 item.multiple_bookings = '<span id="active-script" class="label label-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
528 }
529 item.action = '<div class="btn-group">' +
530 '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
531 '<a href="#" data-action="delete_selected" data-id="single-resource" data-api-url="delete/resource" data-item="' + item.name + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
532 '</div>';
533 item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
534 item.name = escapeHtml(item.name);
535 });
536 }
537 }),
538 "paging": {
539 "enabled": true,
540 "limit": 5,
541 "size": pagination_size
542 },
543 "state": {
544 "enabled": true
545 },
546 "filtering": {
547 "enabled": true,
548 "delay": 1200,
549 "position": "left",
550 "connectors": false,
551 "placeholder": lang.filter_table
552 },
553 "components": {
554 "filtering": FooTable.domainFilter
555 },
556 "sorting": {
557 "enabled": true
558 },
559 "on": {
560 "destroy.ft.table": function(e, ft){
561 $('.refresh_table').attr('disabled', 'true');
562 },
563 "ready.ft.table": function(e, ft){
564 table_mailbox_ready(ft, 'resource_table');
565 },
566 "after.ft.filtering": function(e, ft){
567 table_mailbox_ready(ft, 'resource_table');
568 }
569 },
570 "toggleSelector": "table tbody span.footable-toggle"
571 });
572 }
573 function draw_bcc_table() {
574 ft_bcc_table = FooTable.init('#bcc_table', {
575 "columns": [
576 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
577 {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
578 {"name":"type","title":lang.bcc_type},
579 {"name":"local_dest","title":lang.bcc_local_dest},
580 {"name":"bcc_dest","title":lang.bcc_destinations},
581 {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
582 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
583 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
584 ],
585 "empty": lang.empty,
586 "rows": $.ajax({
587 dataType: 'json',
588 url: '/api/v1/get/bcc/all',
589 jsonp: false,
590 error: function () {
591 console.log('Cannot draw bcc table');
592 },
593 success: function (data) {
594 $.each(data, function (i, item) {
595 item.action = '<div class="btn-group">' +
596 '<a href="/edit/bcc/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
597 '<a href="#" data-action="delete_selected" data-id="single-bcc" data-api-url="delete/bcc" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
598 '</div>';
599 item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
600 item.local_dest = escapeHtml(item.local_dest);
601 item.bcc_dest = escapeHtml(item.bcc_dest);
602 if (item.type == 'sender') {
603 item.type = '<span id="active-script" class="label label-success">Sender</span>';
604 } else {
605 item.type = '<span id="inactive-script" class="label label-warning">Recipient</span>';
606 }
607 });
608 }
609 }),
610 "paging": {
611 "enabled": true,
612 "limit": 5,
613 "size": pagination_size
614 },
615 "state": {
616 "enabled": true
617 },
618 "filtering": {
619 "enabled": true,
620 "delay": 1200,
621 "position": "left",
622 "connectors": false,
623 "placeholder": lang.filter_table
624 },
625 "sorting": {
626 "enabled": true
627 },
628 "on": {
629 "destroy.ft.table": function(e, ft){
630 $('.refresh_table').attr('disabled', 'true');
631 },
632 "ready.ft.table": function(e, ft){
633 table_mailbox_ready(ft, 'bcc_table');
634 },
635 "after.ft.filtering": function(e, ft){
636 table_mailbox_ready(ft, 'bcc_table');
637 }
638 },
639 "toggleSelector": "table tbody span.footable-toggle"
640 });
641 }
642 function draw_recipient_map_table() {
643 ft_recipient_map_table = FooTable.init('#recipient_map_table', {
644 "columns": [
645 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
646 {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
647 {"name":"recipient_map_old","title":lang.recipient_map_old},
648 {"name":"recipient_map_new","title":lang.recipient_map_new},
649 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
650 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
651 ],
652 "empty": lang.empty,
653 "rows": $.ajax({
654 dataType: 'json',
655 url: '/api/v1/get/recipient_map/all',
656 jsonp: false,
657 error: function () {
658 console.log('Cannot draw recipient map table');
659 },
660 success: function (data) {
661 if (role == "admin") {
662 $.each(data, function (i, item) {
663 item.recipient_map_old = escapeHtml(item.recipient_map_old);
664 item.recipient_map_new = escapeHtml(item.recipient_map_new);
665 item.action = '<div class="btn-group">' +
666 '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
667 '<a href="#" data-action="delete_selected" data-id="single-recipient_map" data-api-url="delete/recipient_map" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
668 '</div>';
669 item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
670 });
671 }
672 }
673 }),
674 "paging": {
675 "enabled": true,
676 "limit": 5,
677 "size": pagination_size
678 },
679 "state": {
680 "enabled": true
681 },
682 "filtering": {
683 "enabled": true,
684 "delay": 1200,
685 "position": "left",
686 "connectors": false,
687 "placeholder": lang.filter_table
688 },
689 "sorting": {
690 "enabled": true
691 },
692 "on": {
693 "destroy.ft.table": function(e, ft){
694 $('.refresh_table').attr('disabled', 'true');
695 },
696 "ready.ft.table": function(e, ft){
697 table_mailbox_ready(ft, 'recipient_map_table');
698 },
699 "after.ft.filtering": function(e, ft){
700 table_mailbox_ready(ft, 'recipient_map_table');
701 }
702 },
703 "toggleSelector": "table tbody span.footable-toggle"
704 });
705 }
706 function draw_tls_policy_table() {
707 ft_tls_policy_table = FooTable.init('#tls_policy_table', {
708 "columns": [
709 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
710 {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
711 {"name":"dest","title":lang.tls_map_dest},
712 {"name":"policy","title":lang.tls_map_policy},
713 {"name":"parameters","title":lang.tls_map_parameters},
714 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
715 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
716 ],
717 "empty": lang.empty,
718 "rows": $.ajax({
719 dataType: 'json',
720 url: '/api/v1/get/tls-policy-map/all',
721 jsonp: false,
722 error: function () {
723 console.log('Cannot draw tls policy map table');
724 },
725 success: function (data) {
726 if (role == "admin") {
727 $.each(data, function (i, item) {
728 item.dest = escapeHtml(item.dest);
729 item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
730 if (item.parameters == '') {
731 item.parameters = '<code>-</code>';
732 } else {
733 item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
734 }
735 item.action = '<div class="btn-group">' +
736 '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
737 '<a href="#" data-action="delete_selected" data-id="single-tls-policy-map" data-api-url="delete/tls-policy-map" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
738 '</div>';
739 item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
740 });
741 }
742 }
743 }),
744 "paging": {
745 "enabled": true,
746 "limit": 5,
747 "size": pagination_size
748 },
749 "state": {
750 "enabled": true
751 },
752 "filtering": {
753 "enabled": true,
754 "delay": 1200,
755 "position": "left",
756 "connectors": false,
757 "placeholder": lang.filter_table
758 },
759 "sorting": {
760 "enabled": true
761 },
762 "on": {
763 "destroy.ft.table": function(e, ft){
764 $('.refresh_table').attr('disabled', 'true');
765 },
766 "ready.ft.table": function(e, ft){
767 table_mailbox_ready(ft, 'tls_policy_table');
768 },
769 "after.ft.filtering": function(e, ft){
770 table_mailbox_ready(ft, 'tls_policy_table');
771 }
772 },
773 "toggleSelector": "table tbody span.footable-toggle"
774 });
775 }
776 function draw_alias_table() {
777 ft_alias_table = FooTable.init('#alias_table', {
778 "columns": [
779 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
780 {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
781 {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
782 {"name":"goto","title":lang.target_address},
783 {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
784 {"name":"public_comment","title":lang.public_comment,"breakpoints":"all"},
785 {"name":"private_comment","title":lang.private_comment,"breakpoints":"all"},
786 {"name":"sogo_visible","title":lang.sogo_visible,"breakpoints":"all"},
787 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
788 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
789 ],
790 "empty": lang.empty,
791 "rows": $.ajax({
792 dataType: 'json',
793 url: '/api/v1/get/alias/all',
794 jsonp: false,
795 error: function () {
796 console.log('Cannot draw alias table');
797 },
798 success: function (data) {
799 $.each(data, function (i, item) {
800 item.action = '<div class="btn-group">' +
801 '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
802 '<a href="#" data-action="delete_selected" data-id="single-alias" data-api-url="delete/alias" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
803 '</div>';
804 item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
805 item.goto = escapeHtml(item.goto.replace(/,/g, " "));
806 if (item.public_comment !== null) {
807 item.public_comment = escapeHtml(item.public_comment);
808 }
809 else {
810 item.public_comment = '-';
811 }
812 if (item.private_comment !== null) {
813 item.private_comment = escapeHtml(item.private_comment);
814 }
815 else {
816 item.private_comment = '-';
817 }
818 if (item.is_catch_all == 1) {
819 item.address = '<div class="label label-default">Catch-All</div> ' + escapeHtml(item.address);
820 }
821 else {
822 item.address = escapeHtml(item.address);
823 }
824 if (item.goto == "null@localhost") {
825 item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
826 }
827 else if (item.goto == "spam@localhost") {
828 item.goto = '<span class="label label-danger">Learn as spam</span>';
829 }
830 else if (item.goto == "ham@localhost") {
831 item.goto = '<span class="label label-success">Learn as ham</span>';
832 }
833 if (item.in_primary_domain !== "") {
834 item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
835 }
836 });
837 }
838 }),
839 "paging": {
840 "enabled": true,
841 "limit": 5,
842 "size": pagination_size
843 },
844 "state": {
845 "enabled": true
846 },
847 "filtering": {
848 "enabled": true,
849 "delay": 1200,
850 "position": "left",
851 "connectors": false,
852 "placeholder": lang.filter_table
853 },
854 "components": {
855 "filtering": FooTable.domainFilter
856 },
857 "sorting": {
858 "enabled": true
859 },
860 "on": {
861 "destroy.ft.table": function(e, ft){
862 $('.refresh_table').attr('disabled', 'true');
863 },
864 "ready.ft.table": function(e, ft){
865 table_mailbox_ready(ft, 'alias_table');
866 },
867 "after.ft.filtering": function(e, ft){
868 table_mailbox_ready(ft, 'alias_table');
869 }
870 },
871 "toggleSelector": "table tbody span.footable-toggle"
872 });
873 }
874
875 function draw_aliasdomain_table() {
876 ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
877 "columns": [
878 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
879 {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
880 {"name":"target_domain","title":lang.target_domain,"type":"html"},
881 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
882 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
883 ],
884 "empty": lang.empty,
885 "rows": $.ajax({
886 dataType: 'json',
887 url: '/api/v1/get/alias-domain/all',
888 jsonp: false,
889 error: function () {
890 console.log('Cannot draw alias domain table');
891 },
892 success: function (data) {
893 $.each(data, function (i, item) {
894 item.action = '<div class="btn-group">' +
895 '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
896 '<a href="#" data-action="delete_selected" data-id="single-alias-domain" data-api-url="delete/alias-domain" data-item="' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
897 '<a href="#dnsInfoModal" class="btn btn-xs btn-info" data-toggle="modal" data-domain="' + encodeURIComponent(item.alias_domain) + '"><span class="glyphicon glyphicon-question-sign"></span> DNS</a></div>' +
898 '</div>';
899 item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
900 if(item.parent_is_backupmx == '1') {
901 item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a> <div class="label label-warning">' + lang.alias_domain_backupmx + '</div></span>';
902 } else {
903 item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
904 }
905 });
906 }
907 }),
908 "paging": {
909 "enabled": true,
910 "limit": 5,
911 "size": pagination_size
912 },
913 "state": {
914 "enabled": true
915 },
916 "filtering": {
917 "enabled": true,
918 "delay": 1200,
919 "position": "left",
920 "connectors": false,
921 "placeholder": lang.filter_table
922 },
923 "sorting": {
924 "enabled": true
925 },
926 "on": {
927 "destroy.ft.table": function(e, ft){
928 $('.refresh_table').attr('disabled', 'true');
929 },
930 "ready.ft.table": function(e, ft){
931 table_mailbox_ready(ft, 'aliasdomain_table');
932 },
933 "after.ft.filtering": function(e, ft){
934 table_mailbox_ready(ft, 'aliasdomain_table');
935 }
936 },
937 "toggleSelector": "table tbody span.footable-toggle"
938 });
939 }
940
941 function draw_sync_job_table() {
942 ft_syncjob_table = FooTable.init('#sync_job_table', {
943 "columns": [
944 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
945 {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
946 {"name":"user2","title":lang.owner},
947 {"name":"server_w_port","title":"Server","breakpoints":"xs sm md","style":{"word-break":"break-all"}},
948 {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
949 {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
950 {"name":"last_run","title":lang.last_run,"breakpoints":"xs sm md"},
951 {"name":"log","title":"Log"},
952 {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
953 {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
954 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
955 ],
956 "empty": lang.empty,
957 "rows": $.ajax({
958 dataType: 'json',
959 url: '/api/v1/get/syncjobs/all/no_log',
960 jsonp: false,
961 error: function () {
962 console.log('Cannot draw sync job table');
963 },
964 success: function (data) {
965 $.each(data, function (i, item) {
966 item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">Open logs</a>'
967 item.user2 = escapeHtml(item.user2);
968 if (!item.exclude > 0) {
969 item.exclude = '-';
970 } else {
971 item.exclude = '<code>' + item.exclude + '</code>';
972 }
973 item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
974 item.action = '<div class="btn-group">' +
975 '<a href="/edit/syncjob/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
976 '<a href="#" data-action="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
977 '</div>';
978 item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
979 if (item.is_running == 1) {
980 item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
981 } else {
982 item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
983 }
984 if (!item.last_run > 0) {
985 item.last_run = lang.waiting;
986 }
987 });
988 }
989 }),
990 "paging": {
991 "enabled": true,
992 "limit": 5,
993 "size": pagination_size
994 },
995 "state": {
996 "enabled": true
997 },
998 "filtering": {
999 "enabled": true,
1000 "delay": 1200,
1001 "position": "left",
1002 "connectors": false,
1003 "placeholder": lang.filter_table
1004 },
1005 "sorting": {
1006 "enabled": true
1007 },
1008 "on": {
1009 "destroy.ft.table": function(e, ft){
1010 $('.refresh_table').attr('disabled', 'true');
1011 },
1012 "ready.ft.table": function(e, ft){
1013 table_mailbox_ready(ft, 'sync_job_table');
1014 },
1015 "after.ft.filtering": function(e, ft){
1016 table_mailbox_ready(ft, 'sync_job_table');
1017 }
1018 },
1019 "toggleSelector": "table tbody span.footable-toggle"
1020 });
1021 }
1022
1023 function draw_filter_table() {
1024 ft_filter_table = FooTable.init('#filter_table', {
1025 "columns": [
1026 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
1027 {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
1028 {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
1029 {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
1030 {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
1031 {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
1032 {"name":"script_data","title":"Script","breakpoints":"all"},
1033 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
1034 ],
1035 "empty": lang.empty,
1036 "rows": $.ajax({
1037 dataType: 'json',
1038 url: '/api/v1/get/filters/all',
1039 jsonp: false,
1040 error: function () {
1041 console.log('Cannot draw filter table');
1042 },
1043 success: function (data) {
1044 $.each(data, function (i, item) {
1045 if (item.active == 1) {
1046 item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
1047 } else {
1048 item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
1049 }
1050 item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
1051 item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
1052 item.action = '<div class="btn-group">' +
1053 '<a href="/edit/filter/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
1054 '<a href="#" data-action="delete_selected" data-id="single-filter" data-api-url="delete/filter" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
1055 '</div>';
1056 item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
1057 });
1058 }
1059 }),
1060 "paging": {
1061 "enabled": true,
1062 "limit": 5,
1063 "size": pagination_size
1064 },
1065 "state": {
1066 "enabled": true
1067 },
1068 "filtering": {
1069 "enabled": true,
1070 "delay": 1200,
1071 "position": "left",
1072 "connectors": false,
1073 "placeholder": lang.filter_table
1074 },
1075 "sorting": {
1076 "enabled": true
1077 },
1078 "on": {
1079 "destroy.ft.table": function(e, ft){
1080 $('.refresh_table').attr('disabled', 'true');
1081 },
1082 "ready.ft.table": function(e, ft){
1083 table_mailbox_ready(ft, 'filter_table');
1084 },
1085 "after.ft.filtering": function(e, ft){
1086 table_mailbox_ready(ft, 'filter_table');
1087 }
1088 },
1089 "toggleSelector": "table tbody span.footable-toggle"
1090 });
1091 };
1092
1093 $('body').on('click', 'span.footable-toggle', function () {
1094 event.stopPropagation();
1095 })
1096
1097 draw_domain_table();
1098 draw_mailbox_table();
1099 draw_resource_table();
1100 draw_alias_table();
1101 draw_aliasdomain_table();
1102 draw_sync_job_table();
1103 draw_filter_table();
1104 draw_bcc_table();
1105 draw_recipient_map_table();
1106 draw_tls_policy_table();
1107
1108});