Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | $(document).ready(function() { |
| 2 | acl_data = JSON.parse(acl); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 3 | // Set paging |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 4 | // Clone mailbox mass actions |
| 5 | $("div").find("[data-actions-header='true'").each(function() { |
| 6 | $(this).html($(this).nextAll('.mass-actions-mailbox:first').html()); |
| 7 | }); |
| 8 | // Auto-fill domain quota when adding new domain |
| 9 | auto_fill_quota = function(domain) { |
| 10 | $.get("/api/v1/get/domain/" + domain, function(data){ |
| 11 | var result = $.parseJSON(JSON.stringify(data)); |
| 12 | def_new_mailbox_quota = ( result.def_new_mailbox_quota / 1048576); |
| 13 | max_new_mailbox_quota = ( result.max_new_mailbox_quota / 1048576); |
| 14 | if (max_new_mailbox_quota != '0') { |
| 15 | $('.addInputQuotaExhausted').hide(); |
| 16 | $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB'); |
| 17 | $('#addInputQuota').attr({"disabled": false, "value": "", "type": "number", "max": max_new_mailbox_quota}); |
| 18 | $('#addInputQuota').val(def_new_mailbox_quota); |
| 19 | } |
| 20 | else { |
| 21 | $('.addInputQuotaExhausted').show(); |
| 22 | $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB'); |
| 23 | $('#addInputQuota').attr({"disabled": true, "value": "", "type": "text", "value": "n/a"}); |
| 24 | $('#addInputQuota').val(max_new_mailbox_quota); |
| 25 | } |
| 26 | }); |
| 27 | } |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 28 | $('#addSelectDomain').on('change', function() { |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 29 | auto_fill_quota($('#addSelectDomain').val()); |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 30 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 31 | auto_fill_quota($('#addSelectDomain').val()); |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 32 | |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 33 | $(".goto_checkbox").click(function( event ) { |
| 34 | $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false); |
| 35 | if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) { |
| 36 | $('#textarea_alias_goto').prop('disabled', true); |
| 37 | } |
| 38 | else { |
| 39 | $("#textarea_alias_goto").removeAttr('disabled'); |
| 40 | } |
| 41 | }); |
| 42 | $('#addAliasModal').on('show.bs.modal', function(e) { |
| 43 | if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) { |
| 44 | $('#textarea_alias_goto').prop('disabled', true); |
| 45 | } |
| 46 | else { |
| 47 | $("#textarea_alias_goto").removeAttr('disabled'); |
| 48 | } |
| 49 | }); |
| 50 | // Log modal |
| 51 | $('#syncjobLogModal').on('show.bs.modal', function(e) { |
| 52 | var syncjob_id = $(e.relatedTarget).data('syncjob-id'); |
| 53 | $.ajax({ |
| 54 | url: '/inc/ajax/syncjob_logs.php', |
| 55 | data: { id: syncjob_id }, |
| 56 | dataType: 'text', |
| 57 | success: function(data){ |
| 58 | $(e.currentTarget).find('#logText').text(data); |
| 59 | }, |
| 60 | error: function(xhr, status, error) { |
| 61 | $(e.currentTarget).find('#logText').text(xhr.responseText); |
| 62 | } |
| 63 | }); |
| 64 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 65 | // Log modal |
| 66 | $('#dnsInfoModal').on('show.bs.modal', function(e) { |
| 67 | var domain = $(e.relatedTarget).data('domain'); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 68 | $('.dns-modal-body').html('<div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div>'); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 69 | $.ajax({ |
| 70 | url: '/inc/ajax/dns_diagnostics.php', |
| 71 | data: { domain: domain }, |
| 72 | dataType: 'text', |
| 73 | success: function(data){ |
| 74 | $('.dns-modal-body').html(data); |
| 75 | }, |
| 76 | error: function(xhr, status, error) { |
| 77 | $('.dns-modal-body').html(xhr.responseText); |
| 78 | } |
| 79 | }); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 80 | }); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 81 | // @Open Domain add modal |
| 82 | $('#addDomainModal').on('show.bs.modal', function(e) { |
| 83 | $.ajax({ |
| 84 | url: '/api/v1/get/domain/template/all', |
| 85 | data: {}, |
| 86 | dataType: 'json', |
| 87 | success: async function(data){ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 88 | $('#domain_templates').find('option').remove(); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 89 | $('#domain_templates').selectpicker('destroy'); |
| 90 | $('#domain_templates').selectpicker(); |
| 91 | for (var i = 0; i < data.length; i++){ |
| 92 | if (data[i].template === "Default"){ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 93 | $('#domain_templates').prepend($('<option>', { |
| 94 | 'value': data[i].id, |
| 95 | 'text': data[i].template, |
| 96 | 'data-attributes': JSON.stringify(data[i].attributes), |
| 97 | 'selected': true |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 98 | })); |
| 99 | setDomainTemplateData(data[i].attributes); |
| 100 | } else { |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 101 | $('#domain_templates').append($('<option>', { |
| 102 | 'value': data[i].id, |
| 103 | 'text': data[i].template, |
| 104 | 'data-attributes': JSON.stringify(data[i].attributes), |
| 105 | 'selected': false |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 106 | })); |
| 107 | } |
| 108 | }; |
| 109 | $('#domain_templates').selectpicker("refresh"); |
| 110 | |
| 111 | // @selecting template |
| 112 | $('#domain_templates').on('change', function(){ |
| 113 | var selected = $('#domain_templates option:selected'); |
| 114 | var attr = selected.data('attributes'); |
| 115 | setDomainTemplateData(attr); |
| 116 | }); |
| 117 | }, |
| 118 | error: function(xhr, status, error) { |
| 119 | console.log(error); |
| 120 | } |
| 121 | }); |
| 122 | }); |
| 123 | // @Open Mailbox add modal |
| 124 | $('#addMailboxModal').on('show.bs.modal', function(e) { |
| 125 | $.ajax({ |
| 126 | url: '/api/v1/get/mailbox/template/all', |
| 127 | data: {}, |
| 128 | dataType: 'json', |
| 129 | success: async function(data){ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 130 | $('#mailbox_templates').find('option').remove(); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 131 | $('#mailbox_templates').selectpicker('destroy'); |
| 132 | $('#mailbox_templates').selectpicker(); |
| 133 | for (var i = 0; i < data.length; i++){ |
| 134 | if (data[i].template === "Default"){ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 135 | $('#mailbox_templates').prepend($('<option>', { |
| 136 | 'value': data[i].id, |
| 137 | 'text': data[i].template, |
| 138 | 'data-attributes': JSON.stringify(data[i].attributes), |
| 139 | 'selected': true |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 140 | })); |
| 141 | setMailboxTemplateData(data[i].attributes); |
| 142 | } else { |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 143 | $('#mailbox_templates').append($('<option>', { |
| 144 | value: data[i].id, |
| 145 | text : data[i].template, |
| 146 | 'data-attributes': JSON.stringify(data[i].attributes), |
| 147 | 'selected': false |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 148 | })); |
| 149 | } |
| 150 | }; |
| 151 | $('#mailbox_templates').selectpicker("refresh"); |
| 152 | |
| 153 | // @selecting template |
| 154 | $('#mailbox_templates').on('change', function(){ |
| 155 | var selected = $('#mailbox_templates option:selected'); |
| 156 | var attr = selected.data('attributes'); |
| 157 | setMailboxTemplateData(attr); |
| 158 | }); |
| 159 | }, |
| 160 | error: function(xhr, status, error) { |
| 161 | console.log(error); |
| 162 | } |
| 163 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 164 | }); |
| 165 | // Sieve data modal |
| 166 | $('#sieveDataModal').on('show.bs.modal', function(e) { |
| 167 | var sieveScript = $(e.relatedTarget).data('sieve-script'); |
| 168 | $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>'); |
| 169 | }); |
| 170 | // Disable submit button on script change |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 171 | $('.textarea-code').on('keyup', function() { |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 172 | // Disable all "save" buttons, could be a "related button only" function, todo |
| 173 | $('.add_sieve_script').attr({"disabled": true}); |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 174 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 175 | // Validate script data |
| 176 | $(".validate_sieve").click(function( event ) { |
| 177 | event.preventDefault(); |
| 178 | var validation_button = $(this); |
| 179 | // Get script_data textarea content from form the button was clicked in |
| 180 | var script = $('textarea[name="script_data"]', $(this).parents('form:first')).val(); |
| 181 | $.ajax({ |
| 182 | dataType: 'json', |
| 183 | url: "/inc/ajax/sieve_validation.php", |
| 184 | type: "get", |
| 185 | data: { script: script }, |
| 186 | complete: function(data) { |
| 187 | var response = (data.responseText); |
| 188 | response_obj = JSON.parse(response); |
| 189 | if (response_obj.type == "success") { |
| 190 | $(validation_button).next().attr({"disabled": false}); |
| 191 | } |
| 192 | mailcow_alert_box(response_obj.msg, response_obj.type); |
| 193 | }, |
| 194 | }); |
| 195 | }); |
| 196 | // $(document).on('DOMNodeInserted', '#prefilter_table', function () { |
| 197 | // $("#active-script").closest('td').css('background-color','#b0f0a0'); |
| 198 | // $("#inactive-script").closest('td').css('background-color','#b0f0a0'); |
| 199 | // }); |
| 200 | $('#addResourceModal').on('shown.bs.modal', function() { |
| 201 | $("#multiple_bookings").val($("#multiple_bookings_select").val()); |
| 202 | if ($("#multiple_bookings").val() == "custom") { |
| 203 | $("#multiple_bookings_custom_div").show(); |
| 204 | $("#multiple_bookings").val($("#multiple_bookings_custom").val()); |
| 205 | } |
| 206 | }) |
| 207 | $("#multiple_bookings_select").change(function() { |
| 208 | $("#multiple_bookings").val($("#multiple_bookings_select").val()); |
| 209 | if ($("#multiple_bookings").val() == "custom") { |
| 210 | $("#multiple_bookings_custom_div").show(); |
| 211 | } |
| 212 | else { |
| 213 | $("#multiple_bookings_custom_div").hide(); |
| 214 | } |
| 215 | }); |
| 216 | $("#multiple_bookings_custom").bind ("change keypress keyup blur", function () { |
| 217 | $("#multiple_bookings").val($("#multiple_bookings_custom").val()); |
| 218 | }); |
| 219 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 220 | function setDomainTemplateData(template){ |
| 221 | $("#addDomain_max_aliases").val(template.max_num_aliases_for_domain); |
| 222 | $("#addDomain_max_mailboxes").val(template.max_num_mboxes_for_domain); |
| 223 | $("#addDomain_mailbox_quota_def").val(template.def_quota_for_mbox / 1048576); |
| 224 | $("#addDomain_mailbox_quota_m").val(template.max_quota_for_mbox / 1048576); |
| 225 | $("#addDomain_domain_quota_m").val(template.max_quota_for_domain / 1048576); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 226 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 227 | if (template.gal == 1){ |
| 228 | $('#addDomain_gal').prop('checked', true); |
| 229 | } else { |
| 230 | $('#addDomain_gal').prop('checked', false); |
| 231 | } |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 232 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 233 | if (template.active == 1){ |
| 234 | $('#addDomain_active').prop('checked', true); |
| 235 | } else { |
| 236 | $('#addDomain_active').prop('checked', false); |
| 237 | } |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 238 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 239 | $("#addDomain_rl_value").val(template.rl_value); |
| 240 | $('#addDomain_rl_frame').selectpicker('val', template.rl_frame); |
| 241 | $("#dkim_selector").val(template.dkim_selector); |
| 242 | if (!template.key_size) |
| 243 | template.key_size = 2048; |
| 244 | $('#key_size').selectpicker('val', template.key_size.toString()); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 245 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 246 | if (template.backupmx == 1){ |
| 247 | $('#addDomain_relay_domain').prop('checked', true); |
| 248 | } else { |
| 249 | $('#addDomain_relay_domain').prop('checked', false); |
| 250 | } |
| 251 | if (template.relay_all_recipients == 1){ |
| 252 | $('#addDomain_relay_all').prop('checked', true); |
| 253 | } else { |
| 254 | $('#addDomain_relay_all').prop('checked', false); |
| 255 | } |
| 256 | if (template.relay_unknown_only == 1){ |
| 257 | $('#addDomain_relay_unknown_only').prop('checked', true); |
| 258 | } else { |
| 259 | $('#addDomain_relay_unknown_only').prop('checked', false); |
| 260 | } |
| 261 | |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 262 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 263 | // load tags |
| 264 | $('#addDomain_tags').val(""); |
| 265 | $($('#addDomain_tags').parent().find(".tag-values")[0]).val(""); |
| 266 | $('#addDomain_tags').parent().find(".tag-badge").remove(); |
| 267 | for (var i = 0; i < template.tags.length; i++) |
| 268 | addTag($('#addDomain_tags'), template.tags[i]); |
| 269 | } |
| 270 | function setMailboxTemplateData(template){ |
| 271 | $("#addInputQuota").val(template.quota / 1048576); |
| 272 | |
| 273 | if (template.quarantine_notification === "never"){ |
| 274 | $('#quarantine_notification_never').prop('checked', true); |
| 275 | $('#quarantine_notification_hourly').prop('checked', false); |
| 276 | $('#quarantine_notification_daily').prop('checked', false); |
| 277 | $('#quarantine_notification_weekly').prop('checked', false); |
| 278 | } else if(template.quarantine_notification === "hourly"){ |
| 279 | $('#quarantine_notification_never').prop('checked', false); |
| 280 | $('#quarantine_notification_hourly').prop('checked', true); |
| 281 | $('#quarantine_notification_daily').prop('checked', false); |
| 282 | $('#quarantine_notification_weekly').prop('checked', false); |
| 283 | } else if(template.quarantine_notification === "daily"){ |
| 284 | $('#quarantine_notification_never').prop('checked', false); |
| 285 | $('#quarantine_notification_hourly').prop('checked', false); |
| 286 | $('#quarantine_notification_daily').prop('checked', true); |
| 287 | $('#quarantine_notification_weekly').prop('checked', false); |
| 288 | } else if(template.quarantine_notification === "weekly"){ |
| 289 | $('#quarantine_notification_never').prop('checked', false); |
| 290 | $('#quarantine_notification_hourly').prop('checked', false); |
| 291 | $('#quarantine_notification_daily').prop('checked', false); |
| 292 | $('#quarantine_notification_weekly').prop('checked', true); |
| 293 | } else { |
| 294 | $('#quarantine_notification_never').prop('checked', false); |
| 295 | $('#quarantine_notification_hourly').prop('checked', false); |
| 296 | $('#quarantine_notification_daily').prop('checked', false); |
| 297 | $('#quarantine_notification_weekly').prop('checked', false); |
| 298 | } |
| 299 | |
| 300 | if (template.quarantine_category === "reject"){ |
| 301 | $('#quarantine_category_reject').prop('checked', true); |
| 302 | $('#quarantine_category_add_header').prop('checked', false); |
| 303 | $('#quarantine_category_all').prop('checked', false); |
| 304 | } else if(template.quarantine_category === "add_header"){ |
| 305 | $('#quarantine_category_reject').prop('checked', false); |
| 306 | $('#quarantine_category_add_header').prop('checked', true); |
| 307 | $('#quarantine_category_all').prop('checked', false); |
| 308 | } else if(template.quarantine_category === "all"){ |
| 309 | $('#quarantine_category_reject').prop('checked', false); |
| 310 | $('#quarantine_category_add_header').prop('checked', false); |
| 311 | $('#quarantine_category_all').prop('checked', true); |
| 312 | } |
| 313 | |
| 314 | if (template.tls_enforce_in == 1){ |
| 315 | $('#tls_enforce_in').prop('checked', true); |
| 316 | } else { |
| 317 | $('#tls_enforce_in').prop('checked', false); |
| 318 | } |
| 319 | if (template.tls_enforce_out == 1){ |
| 320 | $('#tls_enforce_out').prop('checked', true); |
| 321 | } else { |
| 322 | $('#tls_enforce_out').prop('checked', false); |
| 323 | } |
| 324 | |
| 325 | var protocol_access = []; |
| 326 | if (template.imap_access == 1){ |
| 327 | protocol_access.push("imap"); |
| 328 | } |
| 329 | if (template.pop3_access == 1){ |
| 330 | protocol_access.push("pop3"); |
| 331 | } |
| 332 | if (template.smtp_access == 1){ |
| 333 | protocol_access.push("smtp"); |
| 334 | } |
| 335 | if (template.sieve_access == 1){ |
| 336 | protocol_access.push("sieve"); |
| 337 | } |
| 338 | $('#protocol_access').selectpicker('val', protocol_access); |
| 339 | |
| 340 | var acl = []; |
| 341 | if (template.acl_spam_alias == 1){ |
| 342 | acl.push("spam_alias"); |
| 343 | } |
| 344 | if (template.acl_tls_policy == 1){ |
| 345 | acl.push("tls_policy"); |
| 346 | } |
| 347 | if (template.acl_spam_score == 1){ |
| 348 | acl.push("spam_score"); |
| 349 | } |
| 350 | if (template.acl_spam_policy == 1){ |
| 351 | acl.push("spam_policy"); |
| 352 | } |
| 353 | if (template.acl_delimiter_action == 1){ |
| 354 | acl.push("delimiter_action"); |
| 355 | } |
| 356 | if (template.acl_syncjobs == 1){ |
| 357 | acl.push("syncjobs"); |
| 358 | } |
| 359 | if (template.acl_eas_reset == 1){ |
| 360 | acl.push("eas_reset"); |
| 361 | } |
| 362 | if (template.acl_sogo_profile_reset == 1){ |
| 363 | acl.push("sogo_profile_reset"); |
| 364 | } |
| 365 | if (template.acl_pushover == 1){ |
| 366 | acl.push("pushover"); |
| 367 | } |
| 368 | if (template.acl_quarantine == 1){ |
| 369 | acl.push("quarantine"); |
| 370 | } |
| 371 | if (template.acl_quarantine_attachments == 1){ |
| 372 | acl.push("quarantine_attachments"); |
| 373 | } |
| 374 | if (template.acl_quarantine_notification == 1){ |
| 375 | acl.push("quarantine_notification"); |
| 376 | } |
| 377 | if (template.acl_quarantine_category == 1){ |
| 378 | acl.push("quarantine_category"); |
| 379 | } |
| 380 | if (template.acl_app_passwds == 1){ |
| 381 | acl.push("app_passwds"); |
| 382 | } |
| 383 | $('#user_acl').selectpicker('val', acl); |
| 384 | |
| 385 | $('#rl_value').val(template.rl_value); |
| 386 | if (template.rl_frame){ |
| 387 | $('#rl_frame').selectpicker('val', template.rl_frame); |
| 388 | } |
| 389 | |
| 390 | console.log(template.active) |
| 391 | if (template.active){ |
| 392 | $('#mbox_active').selectpicker('val', template.active.toString()); |
| 393 | } else { |
| 394 | $('#mbox_active').selectpicker('val', ''); |
| 395 | } |
| 396 | |
| 397 | if (template.force_pw_update == 1){ |
| 398 | $('#force_pw_update').prop('checked', true); |
| 399 | } else { |
| 400 | $('#force_pw_update').prop('checked', false); |
| 401 | } |
| 402 | if (template.sogo_access == 1){ |
| 403 | $('#sogo_access').prop('checked', true); |
| 404 | } else { |
| 405 | $('#sogo_access').prop('checked', false); |
| 406 | } |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 407 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 408 | // load tags |
| 409 | $('#addMailbox_tags').val(""); |
| 410 | $($('#addMailbox_tags').parent().find(".tag-values")[0]).val(""); |
| 411 | $('#addMailbox_tags').parent().find(".tag-badge").remove(); |
| 412 | for (var i = 0; i < template.tags.length; i++) |
| 413 | addTag($('#addMailbox_tags'), template.tags[i]); |
| 414 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 415 | }); |
| 416 | jQuery(function($){ |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 417 | // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript |
| 418 | 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]} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 419 | function unix_time_format(i){return""==i?'<i class="bi bi-x"></i>':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"})} |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 420 | |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 421 | $(".refresh_table").on('click', function(e) { |
| 422 | e.preventDefault(); |
| 423 | var table_name = $(this).data('table'); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 424 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 425 | if ($.fn.DataTable.isDataTable('#' + table_name)) |
| 426 | $('#' + table_name).DataTable().ajax.reload(); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 427 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 428 | function draw_domain_table() { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 429 | // just recalc width if instance already exists |
| 430 | if ($.fn.DataTable.isDataTable('#domain_table') ) { |
| 431 | $('#domain_table').DataTable().columns.adjust().responsive.recalc(); |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | var table = $('#domain_table').DataTable({ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 436 | responsive: true, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 437 | processing: true, |
| 438 | serverSide: false, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 439 | stateSave: true, |
| 440 | pageLength: pagination_size, |
| 441 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 442 | "tr" + |
| 443 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 444 | language: lang_datatables, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 445 | initComplete: function(){ |
| 446 | hideTableExpandCollapseBtn('#tab-domains', '#domain_table'); |
| 447 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 448 | ajax: { |
| 449 | type: "GET", |
| 450 | url: "/api/v1/get/domain/all", |
| 451 | dataSrc: function(json){ |
| 452 | $.each(json, function(i, item) { |
| 453 | item.domain_name = escapeHtml(item.domain_name); |
| 454 | |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 455 | item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain; |
| 456 | item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain; |
| 457 | item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain + "/" + item.bytes_total; |
| 458 | item.stats = item.msgs_total + "/" + item.bytes_total; |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 459 | |
| 460 | if (!item.rl) item.rl = '∞'; |
| 461 | else { |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 462 | item.rl = $.map(item.rl, function(e){ |
| 463 | return e; |
| 464 | }).join('/1'); |
| 465 | } |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 466 | |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 467 | item.def_quota_for_mbox = humanFileSize(item.def_quota_for_mbox); |
| 468 | item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 469 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />'; |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 470 | item.action = '<div class="btn-group">'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 471 | if (role == "admin") { |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 472 | item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 473 | '<a href="#" data-action="delete_selected" data-id="single-domain" data-api-url="delete/domain" data-item="' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
| 474 | '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-lg btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 475 | } |
| 476 | else { |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 477 | item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 478 | '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-lg btn-xs-half btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>'; |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | if (Array.isArray(item.tags)){ |
| 482 | var tags = ''; |
| 483 | for (var i = 0; i < item.tags.length; i++) |
| 484 | tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>'; |
| 485 | item.tags = tags; |
| 486 | } else { |
| 487 | item.tags = ''; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 488 | } |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 489 | |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 490 | if (item.backupmx == 1) { |
| 491 | if (item.relay_unknown_only == 1) { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 492 | item.domain_name = '<div class="badge fs-6 bg-info">Relay Non-Local</div> ' + item.domain_name; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 493 | } else if (item.relay_all_recipients == 1) { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 494 | item.domain_name = '<div class="badge fs-6 bg-info">Relay All</div> ' + item.domain_name; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 495 | } else { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 496 | item.domain_name = '<div class="badge fs-6 bg-info">Relay</div> ' + item.domain_name; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | }); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 500 | |
| 501 | return json; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 502 | } |
| 503 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 504 | columns: [ |
| 505 | { |
| 506 | // placeholder, so checkbox will not block child row toggle |
| 507 | title: '', |
| 508 | data: null, |
| 509 | searchable: false, |
| 510 | orderable: false, |
| 511 | defaultContent: '', |
| 512 | responsivePriority: 1 |
| 513 | }, |
| 514 | { |
| 515 | title: '', |
| 516 | data: 'chkbox', |
| 517 | searchable: false, |
| 518 | orderable: false, |
| 519 | defaultContent: '', |
| 520 | responsivePriority: 2 |
| 521 | }, |
| 522 | { |
| 523 | title: lang.domain, |
| 524 | data: 'domain_name', |
| 525 | responsivePriority: 3, |
| 526 | defaultContent: '' |
| 527 | }, |
| 528 | { |
| 529 | title: lang.aliases, |
| 530 | data: 'aliases', |
| 531 | defaultContent: '' |
| 532 | }, |
| 533 | { |
| 534 | title: lang.mailboxes, |
| 535 | data: 'mailboxes', |
| 536 | responsivePriority: 4, |
| 537 | defaultContent: '' |
| 538 | }, |
| 539 | { |
| 540 | title: lang.domain_quota, |
| 541 | data: 'quota', |
| 542 | defaultContent: '', |
| 543 | render: function (data, type) { |
| 544 | data = data.split("/"); |
| 545 | return humanFileSize(data[0]) + " / " + humanFileSize(data[1]); |
| 546 | } |
| 547 | }, |
| 548 | { |
| 549 | title: lang.stats, |
| 550 | data: 'stats', |
| 551 | defaultContent: '', |
| 552 | render: function (data, type) { |
| 553 | data = data.split("/"); |
| 554 | return '<i class="bi bi-files"></i> ' + data[0] + ' / ' + humanFileSize(data[1]); |
| 555 | } |
| 556 | }, |
| 557 | { |
| 558 | title: lang.mailbox_defquota, |
| 559 | data: 'def_quota_for_mbox', |
| 560 | defaultContent: '' |
| 561 | }, |
| 562 | { |
| 563 | title: lang.mailbox_quota, |
| 564 | data: 'max_quota_for_mbox', |
| 565 | defaultContent: '' |
| 566 | }, |
| 567 | { |
| 568 | title: 'RL', |
| 569 | data: 'rl', |
| 570 | defaultContent: '' |
| 571 | }, |
| 572 | { |
| 573 | title: lang.backup_mx, |
| 574 | data: 'backupmx', |
| 575 | defaultContent: '', |
| 576 | redner: function (data, type){ |
| 577 | return 1==value ? '<i class="bi bi-check-lg"></i>' : 0==value && '<i class="bi bi-x-lg"></i>'; |
| 578 | } |
| 579 | }, |
| 580 | { |
| 581 | title: lang.domain_admins, |
| 582 | data: 'domain_admins', |
| 583 | defaultContent: '', |
| 584 | className: 'none' |
| 585 | }, |
| 586 | { |
| 587 | title: lang.created_on, |
| 588 | data: 'created', |
| 589 | defaultContent: '', |
| 590 | className: 'none' |
| 591 | }, |
| 592 | { |
| 593 | title: lang.last_modified, |
| 594 | data: 'modified', |
| 595 | defaultContent: '', |
| 596 | className: 'none' |
| 597 | }, |
| 598 | { |
| 599 | title: 'Tags', |
| 600 | data: 'tags', |
| 601 | defaultContent: '', |
| 602 | className: 'none' |
| 603 | }, |
| 604 | { |
| 605 | title: lang.active, |
| 606 | data: 'active', |
| 607 | defaultContent: '', |
| 608 | responsivePriority: 6, |
| 609 | render: function (data, type) { |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 610 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'—'); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 611 | } |
| 612 | }, |
| 613 | { |
| 614 | title: lang.action, |
| 615 | data: 'action', |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 616 | className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right', |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 617 | responsivePriority: 5, |
| 618 | defaultContent: '' |
| 619 | }, |
| 620 | ] |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 621 | }); |
| 622 | |
| 623 | table.on('responsive-resize', function (e, datatable, columns){ |
| 624 | hideTableExpandCollapseBtn('#tab-domains', '#domain_table'); |
| 625 | }); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 626 | } |
| 627 | function draw_templates_domain_table() { |
| 628 | // just recalc width if instance already exists |
| 629 | if ($.fn.DataTable.isDataTable('#templates_domain_table') ) { |
| 630 | $('#templates_domain_table').DataTable().columns.adjust().responsive.recalc(); |
| 631 | return; |
| 632 | } |
| 633 | |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 634 | var table = $('#templates_domain_table').DataTable({ |
| 635 | responsive: true, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 636 | processing: true, |
| 637 | serverSide: false, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 638 | stateSave: true, |
| 639 | pageLength: pagination_size, |
| 640 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 641 | "tr" + |
| 642 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 643 | language: lang_datatables, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 644 | order: [[2, 'desc']], |
| 645 | initComplete: function(){ |
| 646 | hideTableExpandCollapseBtn('#tab-templates-domains', '#templates_domain_table'); |
| 647 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 648 | ajax: { |
| 649 | type: "GET", |
| 650 | url: "/api/v1/get/domain/template/all", |
| 651 | dataSrc: function(json){ |
| 652 | $.each(json, function (i, item) { |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 653 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="domain_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />'; |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 654 | |
| 655 | item.attributes.def_quota_for_mbox = humanFileSize(item.attributes.def_quota_for_mbox); |
| 656 | item.attributes.max_quota_for_mbox = humanFileSize(item.attributes.max_quota_for_mbox); |
| 657 | item.attributes.max_quota_for_domain = humanFileSize(item.attributes.max_quota_for_domain); |
| 658 | |
| 659 | item.template = escapeHtml(item.template); |
| 660 | if (item.attributes.rl_frame === "s"){ |
| 661 | item.attributes.rl_frame = lang_rl.second; |
| 662 | } else if (item.attributes.rl_frame === "m"){ |
| 663 | item.attributes.rl_frame = lang_rl.minute; |
| 664 | } else if (item.attributes.rl_frame === "h"){ |
| 665 | item.attributes.rl_frame = lang_rl.hour; |
| 666 | } else if (item.attributes.rl_frame === "d"){ |
| 667 | item.attributes.rl_frame = lang_rl.day; |
| 668 | } |
| 669 | item.attributes.rl_value = escapeHtml(item.attributes.rl_value); |
| 670 | |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 671 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 672 | if (item.template.toLowerCase() == "default"){ |
| 673 | item.action = '<div class="btn-group">' + |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 674 | '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 675 | '</div>'; |
| 676 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 677 | else { |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 678 | item.action = '<div class="btn-group">' + |
| 679 | '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 680 | '<a href="#" data-action="delete_selected" data-id="single-template" data-api-url="delete/domain/template" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 681 | '</div>'; |
| 682 | } |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 683 | |
| 684 | if (Array.isArray(item.attributes.tags)){ |
| 685 | var tags = ''; |
| 686 | for (var i = 0; i < item.attributes.tags.length; i++) |
| 687 | tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>'; |
| 688 | item.attributes.tags = tags; |
| 689 | } else { |
| 690 | item.attributes.tags = ''; |
| 691 | } |
| 692 | }); |
| 693 | |
| 694 | return json; |
| 695 | } |
| 696 | }, |
| 697 | columns: [ |
| 698 | { |
| 699 | // placeholder, so checkbox will not block child row toggle |
| 700 | title: '', |
| 701 | data: null, |
| 702 | searchable: false, |
| 703 | orderable: false, |
| 704 | defaultContent: '', |
| 705 | responsivePriority: 1 |
| 706 | }, |
| 707 | { |
| 708 | title: '', |
| 709 | data: 'chkbox', |
| 710 | searchable: false, |
| 711 | orderable: false, |
| 712 | defaultContent: '', |
| 713 | responsivePriority: 1 |
| 714 | }, |
| 715 | { |
| 716 | title: "ID", |
| 717 | data: 'id', |
| 718 | responsivePriority: 2, |
| 719 | defaultContent: '' |
| 720 | }, |
| 721 | { |
| 722 | title: lang.template, |
| 723 | data: 'template', |
| 724 | responsivePriority: 3, |
| 725 | defaultContent: '' |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 726 | }, |
| 727 | { |
| 728 | title: lang.max_aliases, |
| 729 | data: 'attributes.max_num_aliases_for_domain', |
| 730 | defaultContent: '', |
| 731 | }, |
| 732 | { |
| 733 | title: lang.max_mailboxes, |
| 734 | data: 'attributes.max_num_mboxes_for_domain', |
| 735 | defaultContent: '', |
| 736 | }, |
| 737 | { |
| 738 | title: lang.mailbox_defquota, |
| 739 | data: 'attributes.def_quota_for_mbox', |
| 740 | defaultContent: '', |
| 741 | }, |
| 742 | { |
| 743 | title: lang.max_quota, |
| 744 | data: 'attributes.max_quota_for_mbox', |
| 745 | defaultContent: '', |
| 746 | }, |
| 747 | { |
| 748 | title: lang.domain_quota_total, |
| 749 | data: 'attributes.max_quota_for_domain', |
| 750 | defaultContent: '', |
| 751 | }, |
| 752 | { |
| 753 | title: lang.gal, |
| 754 | data: 'attributes.gal', |
| 755 | defaultContent: '', |
| 756 | render: function (data, type) { |
| 757 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>'; |
| 758 | } |
| 759 | }, |
| 760 | { |
| 761 | title: lang.backup_mx, |
| 762 | data: 'attributes.backupmx', |
| 763 | defaultContent: '', |
| 764 | render: function (data, type) { |
| 765 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>'; |
| 766 | } |
| 767 | }, |
| 768 | { |
| 769 | title: lang.relay_all, |
| 770 | data: 'attributes.relay_all_recipients', |
| 771 | defaultContent: '', |
| 772 | render: function (data, type) { |
| 773 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>'; |
| 774 | } |
| 775 | }, |
| 776 | { |
| 777 | title: lang.relay_unknown, |
| 778 | data: 'attributes.relay_unknown_only', |
| 779 | defaultContent: '', |
| 780 | render: function (data, type) { |
| 781 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>'; |
| 782 | } |
| 783 | }, |
| 784 | { |
| 785 | title: lang.active, |
| 786 | data: 'attributes.active', |
| 787 | defaultContent: '', |
| 788 | responsivePriority: 4, |
| 789 | render: function (data, type) { |
| 790 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>'; |
| 791 | } |
| 792 | }, |
| 793 | { |
| 794 | title: 'rl_frame', |
| 795 | data: 'attributes.rl_frame', |
| 796 | defaultContent: '', |
| 797 | class: 'none', |
| 798 | }, |
| 799 | { |
| 800 | title: 'rl_value', |
| 801 | data: 'attributes.rl_value', |
| 802 | defaultContent: '', |
| 803 | class: 'none', |
| 804 | }, |
| 805 | { |
| 806 | title: lang.dkim_domains_selector, |
| 807 | data: 'attributes.dkim_selector', |
| 808 | defaultContent: '', |
| 809 | class: 'none', |
| 810 | }, |
| 811 | { |
| 812 | title: lang.dkim_key_length, |
| 813 | data: 'attributes.key_size', |
| 814 | defaultContent: '', |
| 815 | class: 'none', |
| 816 | }, |
| 817 | { |
| 818 | title: 'Tags', |
| 819 | data: 'attributes.tags', |
| 820 | defaultContent: '', |
| 821 | className: 'none' |
| 822 | }, |
| 823 | { |
| 824 | title: lang.action, |
| 825 | data: 'action', |
| 826 | className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right', |
| 827 | responsivePriority: 6, |
| 828 | defaultContent: '' |
| 829 | }, |
| 830 | ] |
| 831 | }); |
| 832 | |
| 833 | table.on('responsive-resize', function (e, datatable, columns){ |
| 834 | hideTableExpandCollapseBtn('#tab-templates-domains', '#templates_domain_table'); |
| 835 | }); |
| 836 | } |
| 837 | function draw_mailbox_table() { |
| 838 | // just recalc width if instance already exists |
| 839 | if ($.fn.DataTable.isDataTable('#mailbox_table') ) { |
| 840 | $('#mailbox_table').DataTable().columns.adjust().responsive.recalc(); |
| 841 | return; |
| 842 | } |
| 843 | |
| 844 | var table = $('#mailbox_table').DataTable({ |
| 845 | responsive: true, |
| 846 | processing: true, |
| 847 | serverSide: false, |
| 848 | stateSave: true, |
| 849 | pageLength: pagination_size, |
| 850 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 851 | "tr" + |
| 852 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
| 853 | language: lang_datatables, |
| 854 | initComplete: function(settings, json){ |
| 855 | hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table'); |
| 856 | filterByDomain(json, 8, table); |
| 857 | }, |
| 858 | ajax: { |
| 859 | type: "GET", |
| 860 | url: "/api/v1/get/mailbox/reduced", |
| 861 | dataSrc: function(json){ |
| 862 | $.each(json, function (i, item) { |
| 863 | item.quota = { |
| 864 | sortBy: item.quota_used, |
| 865 | value: item.quota |
| 866 | } |
| 867 | item.quota.value = (item.quota.value == 0 ? "∞" : humanFileSize(item.quota.value)); |
| 868 | item.quota.value = humanFileSize(item.quota_used) + "/" + item.quota.value; |
| 869 | |
| 870 | item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox); |
| 871 | item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login; |
| 872 | /* |
| 873 | if (!item.rl) { |
| 874 | item.rl = '∞'; |
| 875 | } else { |
| 876 | item.rl = $.map(item.rl, function(e){ |
| 877 | return e; |
| 878 | }).join('/1'); |
| 879 | if (item.rl_scope === 'domain') { |
| 880 | item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')'; |
| 881 | } |
| 882 | } |
| 883 | */ |
| 884 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />'; |
| 885 | if (item.attributes.passwd_update != '0') { |
| 886 | var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/")); |
| 887 | item.last_pw_change = last_pw_change.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"}); |
| 888 | } else { |
| 889 | item.last_pw_change = '-'; |
| 890 | } |
| 891 | item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>'; |
| 892 | item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>'; |
| 893 | item.pop3_access = '<i class="text-' + (item.attributes.pop3_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.pop3_access == 1 ? 'check-lg' : 'x-lg') + '"></i>'; |
| 894 | item.imap_access = '<i class="text-' + (item.attributes.imap_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.imap_access == 1 ? 'check-lg' : 'x-lg') + '"></i>'; |
| 895 | item.smtp_access = '<i class="text-' + (item.attributes.smtp_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.smtp_access == 1 ? 'check-lg' : 'x-lg') + '"></i>'; |
| 896 | item.sieve_access = '<i class="text-' + (item.attributes.sieve_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sieve_access == 1 ? 'check-lg' : 'x-lg') + '"></i>'; |
| 897 | if (item.attributes.quarantine_notification === 'never') { |
| 898 | item.quarantine_notification = lang.never; |
| 899 | } else if (item.attributes.quarantine_notification === 'hourly') { |
| 900 | item.quarantine_notification = lang.hourly; |
| 901 | } else if (item.attributes.quarantine_notification === 'daily') { |
| 902 | item.quarantine_notification = lang.daily; |
| 903 | } else if (item.attributes.quarantine_notification === 'weekly') { |
| 904 | item.quarantine_notification = lang.weekly; |
| 905 | } |
| 906 | if (item.attributes.quarantine_category === 'reject') { |
| 907 | item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>'; |
| 908 | } else if (item.attributes.quarantine_category === 'add_header') { |
| 909 | item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>'; |
| 910 | } else if (item.attributes.quarantine_category === 'all') { |
| 911 | item.quarantine_category = lang.q_all; |
| 912 | } |
| 913 | if (acl_data.login_as === 1) { |
| 914 | |
| 915 | item.action = '<div class="btn-group">' + |
| 916 | '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 917 | '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
| 918 | '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="login_as btn btn-sm btn-xs-lg btn-xs-half btn-success"><i class="bi bi-person-fill"></i> Login</a>'; |
| 919 | if (ALLOW_ADMIN_EMAIL_LOGIN) { |
| 920 | item.action += '<a href="/sogo-auth.php?login=' + encodeURIComponent(item.username) + '" class="login_as btn btn-sm btn-xs-lg btn-xs-half btn-primary" target="_blank"><i class="bi bi-envelope-fill"></i> SOGo</a>'; |
| 921 | } |
| 922 | item.action += '</div>'; |
| 923 | } |
| 924 | else { |
| 925 | item.action = '<div class="btn-group">' + |
| 926 | '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 927 | '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
| 928 | '</div>'; |
| 929 | } |
| 930 | item.in_use = { |
| 931 | sortBy: item.percent_in_use, |
| 932 | value: '<div class="progress">' + |
| 933 | '<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" ' + |
| 934 | 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>' |
| 935 | }; |
| 936 | item.username = escapeHtml(item.username); |
| 937 | |
| 938 | if (Array.isArray(item.tags)){ |
| 939 | var tags = ''; |
| 940 | for (var i = 0; i < item.tags.length; i++) |
| 941 | tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>'; |
| 942 | item.tags = tags; |
| 943 | } else { |
| 944 | item.tags = ''; |
| 945 | } |
| 946 | }); |
| 947 | |
| 948 | return json; |
| 949 | } |
| 950 | }, |
| 951 | columns: [ |
| 952 | { |
| 953 | // placeholder, so checkbox will not block child row toggle |
| 954 | title: '', |
| 955 | data: null, |
| 956 | searchable: false, |
| 957 | orderable: false, |
| 958 | defaultContent: '', |
| 959 | responsivePriority: 1 |
| 960 | }, |
| 961 | { |
| 962 | title: '', |
| 963 | data: 'chkbox', |
| 964 | searchable: false, |
| 965 | orderable: false, |
| 966 | defaultContent: '', |
| 967 | responsivePriority: 2 |
| 968 | }, |
| 969 | { |
| 970 | title: lang.username, |
| 971 | data: 'username', |
| 972 | responsivePriority: 3, |
| 973 | defaultContent: '' |
| 974 | }, |
| 975 | { |
| 976 | title: lang.domain_quota, |
| 977 | data: 'quota.value', |
| 978 | responsivePriority: 8, |
| 979 | defaultContent: '', |
| 980 | orderData: 23 |
| 981 | }, |
| 982 | { |
| 983 | title: lang.last_mail_login, |
| 984 | data: 'last_mail_login', |
| 985 | defaultContent: '', |
| 986 | responsivePriority: 7, |
| 987 | render: function (data, type) { |
| 988 | res = data.split("/"); |
| 989 | return '<div class="badge bg-info mb-2">IMAP @ ' + unix_time_format(Number(res[0])) + '</div><br>' + |
| 990 | '<div class="badge bg-info mb-2">POP3 @ ' + unix_time_format(Number(res[1])) + '</div><br>' + |
| 991 | '<div class="badge bg-info">SMTP @ ' + unix_time_format(Number(res[2])) + '</div>'; |
| 992 | } |
| 993 | }, |
| 994 | { |
| 995 | title: lang.last_pw_change, |
| 996 | data: 'last_pw_change', |
| 997 | defaultContent: '' |
| 998 | }, |
| 999 | { |
| 1000 | title: lang.in_use, |
| 1001 | data: 'in_use.value', |
| 1002 | defaultContent: '', |
| 1003 | responsivePriority: 9, |
| 1004 | className: 'dt-data-w100', |
| 1005 | orderData: 24 |
| 1006 | }, |
| 1007 | { |
| 1008 | title: lang.fname, |
| 1009 | data: 'name', |
| 1010 | defaultContent: '', |
| 1011 | className: 'none' |
| 1012 | }, |
| 1013 | { |
| 1014 | title: lang.domain, |
| 1015 | data: 'domain', |
| 1016 | defaultContent: '', |
| 1017 | className: 'none' |
| 1018 | }, |
| 1019 | { |
| 1020 | title: lang.tls_enforce_in, |
| 1021 | data: 'tls_enforce_in', |
| 1022 | defaultContent: '', |
| 1023 | className: 'none' |
| 1024 | }, |
| 1025 | { |
| 1026 | title: lang.tls_enforce_out, |
| 1027 | data: 'tls_enforce_out', |
| 1028 | defaultContent: '', |
| 1029 | className: 'none' |
| 1030 | }, |
| 1031 | { |
| 1032 | title: 'SMTP', |
| 1033 | data: 'smtp_access', |
| 1034 | defaultContent: '', |
| 1035 | className: 'none' |
| 1036 | }, |
| 1037 | { |
| 1038 | title: 'IMAP', |
| 1039 | data: 'imap_access', |
| 1040 | defaultContent: '', |
| 1041 | className: 'none' |
| 1042 | }, |
| 1043 | { |
| 1044 | title: 'POP3', |
| 1045 | data: 'pop3_access', |
| 1046 | defaultContent: '', |
| 1047 | className: 'none' |
| 1048 | }, |
| 1049 | { |
| 1050 | title: 'SIEVE', |
| 1051 | data: 'sieve_access', |
| 1052 | defaultContent: '', |
| 1053 | className: 'none' |
| 1054 | }, |
| 1055 | { |
| 1056 | title: lang.quarantine_notification, |
| 1057 | data: 'quarantine_notification', |
| 1058 | defaultContent: '', |
| 1059 | className: 'none' |
| 1060 | }, |
| 1061 | { |
| 1062 | title: lang.quarantine_category, |
| 1063 | data: 'quarantine_category', |
| 1064 | defaultContent: '', |
| 1065 | className: 'none' |
| 1066 | }, |
| 1067 | { |
| 1068 | title: lang.msg_num, |
| 1069 | data: 'messages', |
| 1070 | defaultContent: '', |
| 1071 | responsivePriority: 5 |
| 1072 | }, |
| 1073 | { |
| 1074 | title: lang.created_on, |
| 1075 | data: 'created', |
| 1076 | defaultContent: '', |
| 1077 | className: 'none' |
| 1078 | }, |
| 1079 | { |
| 1080 | title: lang.last_modified, |
| 1081 | data: 'modified', |
| 1082 | defaultContent: '', |
| 1083 | className: 'none' |
| 1084 | }, |
| 1085 | { |
| 1086 | title: 'Tags', |
| 1087 | data: 'tags', |
| 1088 | defaultContent: '', |
| 1089 | className: 'none' |
| 1090 | }, |
| 1091 | { |
| 1092 | title: lang.active, |
| 1093 | data: 'active', |
| 1094 | defaultContent: '', |
| 1095 | responsivePriority: 4, |
| 1096 | render: function (data, type) { |
| 1097 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'—'); |
| 1098 | } |
| 1099 | }, |
| 1100 | { |
| 1101 | title: lang.action, |
| 1102 | data: 'action', |
| 1103 | className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right', |
| 1104 | responsivePriority: 6, |
| 1105 | defaultContent: '' |
| 1106 | }, |
| 1107 | { |
| 1108 | title: "", |
| 1109 | data: 'quota.sortBy', |
| 1110 | defaultContent: '', |
| 1111 | className: "d-none" |
| 1112 | }, |
| 1113 | { |
| 1114 | title: "", |
| 1115 | data: 'in_use.sortBy', |
| 1116 | defaultContent: '', |
| 1117 | className: "d-none" |
| 1118 | }, |
| 1119 | ] |
| 1120 | }); |
| 1121 | |
| 1122 | table.on('responsive-resize', function (e, datatable, columns){ |
| 1123 | hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table'); |
| 1124 | }); |
| 1125 | } |
| 1126 | function draw_templates_mbox_table() { |
| 1127 | // just recalc width if instance already exists |
| 1128 | if ($.fn.DataTable.isDataTable('#templates_mbox_table') ) { |
| 1129 | $('#templates_mbox_table').DataTable().columns.adjust().responsive.recalc(); |
| 1130 | return; |
| 1131 | } |
| 1132 | |
| 1133 | var table = $('#templates_mbox_table').DataTable({ |
| 1134 | responsive: true, |
| 1135 | processing: true, |
| 1136 | serverSide: false, |
| 1137 | stateSave: true, |
| 1138 | pageLength: pagination_size, |
| 1139 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 1140 | "tr" + |
| 1141 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
| 1142 | language: lang_datatables, |
| 1143 | order: [[2, 'desc']], |
| 1144 | initComplete: function(){ |
| 1145 | hideTableExpandCollapseBtn('#tab-templates-mbox', '#templates_mbox_table'); |
| 1146 | }, |
| 1147 | ajax: { |
| 1148 | type: "GET", |
| 1149 | url: "/api/v1/get/mailbox/template/all", |
| 1150 | dataSrc: function(json){ |
| 1151 | $.each(json, function (i, item) { |
| 1152 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="mailbox_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />'; |
| 1153 | |
| 1154 | item.template = escapeHtml(item.template); |
| 1155 | if (item.attributes.rl_frame === "s"){ |
| 1156 | item.attributes.rl_frame = lang_rl.second; |
| 1157 | } else if (item.attributes.rl_frame === "m"){ |
| 1158 | item.attributes.rl_frame = lang_rl.minute; |
| 1159 | } else if (item.attributes.rl_frame === "h"){ |
| 1160 | item.attributes.rl_frame = lang_rl.hour; |
| 1161 | } else if (item.attributes.rl_frame === "d"){ |
| 1162 | item.attributes.rl_frame = lang_rl.day; |
| 1163 | } |
| 1164 | item.attributes.rl_value = escapeHtml(item.attributes.rl_value); |
| 1165 | |
| 1166 | item.attributes.quota = humanFileSize(item.attributes.quota); |
| 1167 | |
| 1168 | item.attributes.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"><span class="sorting-value">' + (item.attributes.tls_enforce_in == 1 ? '1' : '0') + '</span></i>'; |
| 1169 | item.attributes.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"><span class="sorting-value">' + (item.attributes.tls_enforce_out == 1 ? '1' : '0') + '</span></i>'; |
| 1170 | item.attributes.pop3_access = '<i class="text-' + (item.attributes.pop3_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.pop3_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.pop3_access == 1 ? '1' : '0') + '</span></i>'; |
| 1171 | item.attributes.imap_access = '<i class="text-' + (item.attributes.imap_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.imap_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.imap_access == 1 ? '1' : '0') + '</span></i>'; |
| 1172 | item.attributes.smtp_access = '<i class="text-' + (item.attributes.smtp_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.smtp_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.smtp_access == 1 ? '1' : '0') + '</span></i>'; |
| 1173 | item.attributes.sieve_access = '<i class="text-' + (item.attributes.sieve_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sieve_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.sieve_access == 1 ? '1' : '0') + '</span></i>'; |
| 1174 | item.attributes.sogo_access = '<i class="text-' + (item.attributes.sogo_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sogo_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.sogo_access == 1 ? '1' : '0') + '</span></i>'; |
| 1175 | if (item.attributes.quarantine_notification === 'never') { |
| 1176 | item.attributes.quarantine_notification = lang.never; |
| 1177 | } else if (item.attributes.quarantine_notification === 'hourly') { |
| 1178 | item.attributes.quarantine_notification = lang.hourly; |
| 1179 | } else if (item.attributes.quarantine_notification === 'daily') { |
| 1180 | item.attributes.quarantine_notification = lang.daily; |
| 1181 | } else if (item.attributes.quarantine_notification === 'weekly') { |
| 1182 | item.attributes.quarantine_notification = lang.weekly; |
| 1183 | } |
| 1184 | if (item.attributes.quarantine_category === 'reject') { |
| 1185 | item.attributes.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>'; |
| 1186 | } else if (item.attributes.quarantine_category === 'add_header') { |
| 1187 | item.attributes.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>'; |
| 1188 | } else if (item.attributes.quarantine_category === 'all') { |
| 1189 | item.attributes.quarantine_category = lang.q_all; |
| 1190 | } |
| 1191 | |
| 1192 | if (item.template.toLowerCase() == "default"){ |
| 1193 | item.action = '<div class="btn-group">' + |
| 1194 | '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 1195 | '</div>'; |
| 1196 | } |
| 1197 | else { |
| 1198 | item.action = '<div class="btn-group">' + |
| 1199 | '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 1200 | '<a href="#" data-action="delete_selected" data-id="single-template" data-api-url="delete/mailbox/template" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
| 1201 | '</div>'; |
| 1202 | } |
| 1203 | |
| 1204 | if (Array.isArray(item.attributes.tags)){ |
| 1205 | var tags = ''; |
| 1206 | for (var i = 0; i < item.attributes.tags.length; i++) |
| 1207 | tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>'; |
| 1208 | item.attributes.tags = tags; |
| 1209 | } else { |
| 1210 | item.attributes.tags = ''; |
| 1211 | } |
| 1212 | }); |
| 1213 | |
| 1214 | return json; |
| 1215 | } |
| 1216 | }, |
| 1217 | columns: [ |
| 1218 | { |
| 1219 | // placeholder, so checkbox will not block child row toggle |
| 1220 | title: '', |
| 1221 | data: null, |
| 1222 | searchable: false, |
| 1223 | orderable: false, |
| 1224 | defaultContent: '', |
| 1225 | responsivePriority: 1 |
| 1226 | }, |
| 1227 | { |
| 1228 | title: '', |
| 1229 | data: 'chkbox', |
| 1230 | searchable: false, |
| 1231 | orderable: false, |
| 1232 | defaultContent: '', |
| 1233 | responsivePriority: 1 |
| 1234 | }, |
| 1235 | { |
| 1236 | title: "ID", |
| 1237 | data: 'id', |
| 1238 | responsivePriority: 2, |
| 1239 | defaultContent: '' |
| 1240 | }, |
| 1241 | { |
| 1242 | title: lang.template, |
| 1243 | data: 'template', |
| 1244 | responsivePriority: 3, |
| 1245 | defaultContent: '' |
| 1246 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1247 | { |
| 1248 | title: lang.domain_quota, |
| 1249 | data: 'attributes.quota', |
| 1250 | defaultContent: '', |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1251 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1252 | { |
| 1253 | title: lang.tls_enforce_in, |
| 1254 | data: 'attributes.tls_enforce_in', |
| 1255 | defaultContent: '' |
| 1256 | }, |
| 1257 | { |
| 1258 | title: lang.tls_enforce_out, |
| 1259 | data: 'attributes.tls_enforce_out', |
| 1260 | defaultContent: '' |
| 1261 | }, |
| 1262 | { |
| 1263 | title: 'SMTP', |
| 1264 | data: 'attributes.smtp_access', |
| 1265 | defaultContent: '', |
| 1266 | }, |
| 1267 | { |
| 1268 | title: 'IMAP', |
| 1269 | data: 'attributes.imap_access', |
| 1270 | defaultContent: '', |
| 1271 | }, |
| 1272 | { |
| 1273 | title: 'POP3', |
| 1274 | data: 'attributes.pop3_access', |
| 1275 | defaultContent: '', |
| 1276 | }, |
| 1277 | { |
| 1278 | title: 'SIEVE', |
| 1279 | data: 'attributes.sieve_access', |
| 1280 | defaultContent: '', |
| 1281 | }, |
| 1282 | { |
| 1283 | title: 'SOGO', |
| 1284 | data: 'attributes.sogo_access', |
| 1285 | defaultContent: '', |
| 1286 | }, |
| 1287 | { |
| 1288 | title: lang.quarantine_notification, |
| 1289 | data: 'attributes.quarantine_notification', |
| 1290 | defaultContent: '', |
| 1291 | className: 'none' |
| 1292 | }, |
| 1293 | { |
| 1294 | title: lang.quarantine_category, |
| 1295 | data: 'attributes.quarantine_category', |
| 1296 | defaultContent: '', |
| 1297 | className: 'none' |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1298 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1299 | { |
| 1300 | title: lang.force_pw_update, |
| 1301 | data: 'attributes.force_pw_update', |
| 1302 | defaultContent: '', |
| 1303 | class: 'none', |
| 1304 | render: function (data, type) { |
| 1305 | return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>'; |
| 1306 | } |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1307 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1308 | { |
| 1309 | title: "rl_frame", |
| 1310 | data: 'attributes.rl_frame', |
| 1311 | defaultContent: '', |
| 1312 | class: 'none', |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1313 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1314 | { |
| 1315 | title: 'rl_value', |
| 1316 | data: 'attributes.rl_value', |
| 1317 | defaultContent: '', |
| 1318 | class: 'none', |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1319 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1320 | { |
| 1321 | title: 'Tags', |
| 1322 | data: 'attributes.tags', |
| 1323 | defaultContent: '', |
| 1324 | className: 'none' |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1325 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1326 | { |
| 1327 | title: lang.active, |
| 1328 | data: 'attributes.active', |
| 1329 | defaultContent: '', |
| 1330 | responsivePriority: 4, |
| 1331 | render: function (data, type) { |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1332 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'—'); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1333 | } |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1334 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1335 | { |
| 1336 | title: lang.action, |
| 1337 | data: 'action', |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1338 | className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right', |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1339 | responsivePriority: 6, |
| 1340 | defaultContent: '' |
| 1341 | }, |
| 1342 | ] |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1343 | }); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1344 | |
| 1345 | table.on('responsive-resize', function (e, datatable, columns){ |
| 1346 | hideTableExpandCollapseBtn('#tab-templates-mbox', '#templates_mbox_table'); |
| 1347 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1348 | } |
| 1349 | function draw_resource_table() { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1350 | // just recalc width if instance already exists |
| 1351 | if ($.fn.DataTable.isDataTable('#resource_table') ) { |
| 1352 | $('#resource_table').DataTable().columns.adjust().responsive.recalc(); |
| 1353 | return; |
| 1354 | } |
| 1355 | |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1356 | var table = $('#resource_table').DataTable({ |
| 1357 | responsive: true, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1358 | processing: true, |
| 1359 | serverSide: false, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1360 | stateSave: true, |
| 1361 | pageLength: pagination_size, |
| 1362 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 1363 | "tr" + |
| 1364 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1365 | language: lang_datatables, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1366 | initComplete: function(settings, json){ |
| 1367 | hideTableExpandCollapseBtn('#tab-resources', '#resource_table'); |
| 1368 | filterByDomain(json, 5, table); |
| 1369 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1370 | ajax: { |
| 1371 | type: "GET", |
| 1372 | url: "/api/v1/get/resource/all", |
| 1373 | dataSrc: function(json){ |
| 1374 | $.each(json, function (i, item) { |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1375 | if (item.multiple_bookings == '0') { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1376 | item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-success">' + lang.booking_0_short + '</span>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1377 | } else if (item.multiple_bookings == '-1') { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1378 | item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-warning">' + lang.booking_lt0_short + '</span>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1379 | } else { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1380 | item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1381 | } |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1382 | item.action = '<div class="btn-group">' + |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1383 | '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 1384 | '<a href="#" data-action="delete_selected" data-id="single-resource" data-api-url="delete/resource" data-item="' + item.name + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1385 | '</div>'; |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1386 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1387 | item.name = escapeHtml(item.name); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1388 | item.description = escapeHtml(item.description); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1389 | }); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1390 | |
| 1391 | return json; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1392 | } |
| 1393 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1394 | columns: [ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1395 | { |
| 1396 | // placeholder, so checkbox will not block child row toggle |
| 1397 | title: '', |
| 1398 | data: null, |
| 1399 | searchable: false, |
| 1400 | orderable: false, |
| 1401 | defaultContent: '', |
| 1402 | responsivePriority: 1 |
| 1403 | }, |
| 1404 | { |
| 1405 | title: '', |
| 1406 | data: 'chkbox', |
| 1407 | searchable: false, |
| 1408 | orderable: false, |
| 1409 | defaultContent: '', |
| 1410 | responsivePriority: 2 |
| 1411 | }, |
| 1412 | { |
| 1413 | title: lang.description, |
| 1414 | data: 'description', |
| 1415 | responsivePriority: 3, |
| 1416 | defaultContent: '' |
| 1417 | }, |
| 1418 | { |
| 1419 | title: lang.alias, |
| 1420 | data: 'name', |
| 1421 | defaultContent: '' |
| 1422 | }, |
| 1423 | { |
| 1424 | title: lang.kind, |
| 1425 | data: 'kind', |
| 1426 | defaultContent: '' |
| 1427 | }, |
| 1428 | { |
| 1429 | title: lang.domain, |
| 1430 | data: 'domain', |
| 1431 | responsivePriority: 4, |
| 1432 | defaultContent: '' |
| 1433 | }, |
| 1434 | { |
| 1435 | title: lang.multiple_bookings, |
| 1436 | data: 'multiple_bookings', |
| 1437 | defaultContent: '' |
| 1438 | }, |
| 1439 | { |
| 1440 | title: lang.active, |
| 1441 | data: 'active', |
| 1442 | defaultContent: '', |
| 1443 | render: function (data, type) { |
| 1444 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'—'); |
| 1445 | } |
| 1446 | }, |
| 1447 | { |
| 1448 | title: lang.action, |
| 1449 | data: 'action', |
| 1450 | responsivePriority: 5, |
| 1451 | defaultContent: '', |
| 1452 | className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right' |
| 1453 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1454 | ] |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1455 | }); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1456 | |
| 1457 | table.on('responsive-resize', function (e, datatable, columns){ |
| 1458 | hideTableExpandCollapseBtn('#tab-resources', '#resource_table'); |
| 1459 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1460 | } |
| 1461 | function draw_bcc_table() { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1462 | $.get("/api/v1/get/bcc-destination-options", function(data){ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1463 | var optgroup = ""; |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1464 | // Domains |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1465 | if (data.domains && data.domains.length > 0) { |
| 1466 | optgroup = "<optgroup label='" + lang.domains + "'>"; |
| 1467 | $.each(data.domains, function(index, domain){ |
| 1468 | optgroup += "<option value='" + domain + "'>" + domain + "</option>"; |
| 1469 | }); |
| 1470 | optgroup += "</optgroup>"; |
| 1471 | $('#bcc-local-dest').append(optgroup); |
| 1472 | } |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1473 | // Alias domains |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1474 | if (data.alias_domains && data.alias_domains.length > 0) { |
| 1475 | optgroup = "<optgroup label='" + lang.domain_aliases + "'>"; |
| 1476 | $.each(data.alias_domains, function(index, alias_domain){ |
| 1477 | optgroup += "<option value='" + alias_domain + "'>" + alias_domain + "</option>"; |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1478 | }); |
| 1479 | optgroup += "</optgroup>" |
| 1480 | $('#bcc-local-dest').append(optgroup); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1481 | } |
| 1482 | // Mailboxes and aliases |
| 1483 | if (data.mailboxes && Object.keys(data.mailboxes).length > 0) { |
| 1484 | $.each(data.mailboxes, function(mailbox, aliases){ |
| 1485 | optgroup = "<optgroup label='" + mailbox + "'>"; |
| 1486 | $.each(aliases, function(index, alias){ |
| 1487 | optgroup += "<option value='" + alias + "'>" + alias + "</option>"; |
| 1488 | }); |
| 1489 | optgroup += "</optgroup>"; |
| 1490 | $('#bcc-local-dest').append(optgroup); |
| 1491 | }); |
| 1492 | } |
| 1493 | // Recreate picker |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1494 | $('#bcc-local-dest').selectpicker('refresh'); |
| 1495 | }); |
| 1496 | |
| 1497 | // just recalc width if instance already exists |
| 1498 | if ($.fn.DataTable.isDataTable('#bcc_table') ) { |
| 1499 | $('#bcc_table').DataTable().columns.adjust().responsive.recalc(); |
| 1500 | return; |
| 1501 | } |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1502 | |
| 1503 | var table = $('#bcc_table').DataTable({ |
| 1504 | responsive: true, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1505 | processing: true, |
| 1506 | serverSide: false, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1507 | stateSave: true, |
| 1508 | pageLength: pagination_size, |
| 1509 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 1510 | "tr" + |
| 1511 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1512 | language: lang_datatables, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1513 | order: [[2, 'desc']], |
| 1514 | initComplete: function(settings, json){ |
| 1515 | hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table'); |
| 1516 | filterByDomain(json, 6, table); |
| 1517 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1518 | ajax: { |
| 1519 | type: "GET", |
| 1520 | url: "/api/v1/get/bcc/all", |
| 1521 | dataSrc: function(json){ |
| 1522 | $.each(json, function (i, item) { |
| 1523 | item.action = '<div class="btn-group">' + |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1524 | '<a href="/edit/bcc/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 1525 | '<a href="#" data-action="delete_selected" data-id="single-bcc" data-api-url="delete/bcc" data-item="' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1526 | '</div>'; |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1527 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="bcc" name="multi_select" value="' + item.id + '" />'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1528 | item.local_dest = escapeHtml(item.local_dest); |
| 1529 | item.bcc_dest = escapeHtml(item.bcc_dest); |
| 1530 | if (item.type == 'sender') { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1531 | item.type = '<span id="active-script" class="badge fs-6 bg-success">' + lang.bcc_sender_map + '</span>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1532 | } else { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1533 | item.type = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.bcc_rcpt_map + '</span>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1534 | } |
| 1535 | }); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1536 | |
| 1537 | return json; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1538 | } |
| 1539 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1540 | columns: [ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1541 | { |
| 1542 | // placeholder, so checkbox will not block child row toggle |
| 1543 | title: '', |
| 1544 | data: null, |
| 1545 | searchable: false, |
| 1546 | orderable: false, |
| 1547 | defaultContent: '', |
| 1548 | responsivePriority: 1 |
| 1549 | }, |
| 1550 | { |
| 1551 | title: '', |
| 1552 | data: 'chkbox', |
| 1553 | searchable: false, |
| 1554 | orderable: false, |
| 1555 | defaultContent: '', |
| 1556 | responsivePriority: 2 |
| 1557 | }, |
| 1558 | { |
| 1559 | title: 'ID', |
| 1560 | data: 'id', |
| 1561 | responsivePriority: 3, |
| 1562 | defaultContent: '' |
| 1563 | }, |
| 1564 | { |
| 1565 | title: lang.bcc_type, |
| 1566 | data: 'type', |
| 1567 | defaultContent: '' |
| 1568 | }, |
| 1569 | { |
| 1570 | title: lang.bcc_local_dest, |
| 1571 | data: 'local_dest', |
| 1572 | defaultContent: '' |
| 1573 | }, |
| 1574 | { |
| 1575 | title: lang.bcc_destinations, |
| 1576 | data: 'bcc_dest', |
| 1577 | defaultContent: '' |
| 1578 | }, |
| 1579 | { |
| 1580 | title: lang.domain, |
| 1581 | data: 'domain', |
| 1582 | responsivePriority: 4, |
| 1583 | defaultContent: '' |
| 1584 | }, |
| 1585 | { |
| 1586 | title: lang.active, |
| 1587 | data: 'active', |
| 1588 | defaultContent: '', |
| 1589 | render: function (data, type) { |
| 1590 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'—'); |
| 1591 | } |
| 1592 | }, |
| 1593 | { |
| 1594 | title: lang.action, |
| 1595 | data: 'action', |
| 1596 | className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right', |
| 1597 | responsivePriority: 5, |
| 1598 | defaultContent: '' |
| 1599 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1600 | ] |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1601 | }); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1602 | |
| 1603 | table.on('responsive-resize', function (e, datatable, columns){ |
| 1604 | hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table'); |
| 1605 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1606 | } |
| 1607 | function draw_recipient_map_table() { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1608 | // just recalc width if instance already exists |
| 1609 | if ($.fn.DataTable.isDataTable('#recipient_map_table') ) { |
| 1610 | $('#recipient_map_table').DataTable().columns.adjust().responsive.recalc(); |
| 1611 | return; |
| 1612 | } |
| 1613 | |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1614 | var table = $('#recipient_map_table').DataTable({ |
| 1615 | responsive: true, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1616 | processing: true, |
| 1617 | serverSide: false, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1618 | stateSave: true, |
| 1619 | pageLength: pagination_size, |
| 1620 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 1621 | "tr" + |
| 1622 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1623 | language: lang_datatables, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1624 | order: [[2, 'desc']], |
| 1625 | initComplete: function(){ |
| 1626 | hideTableExpandCollapseBtn('#collapse-tab-bcc-filters', '#recipient_map_table'); |
| 1627 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1628 | ajax: { |
| 1629 | type: "GET", |
| 1630 | url: "/api/v1/get/recipient_map/all", |
| 1631 | dataSrc: function(json){ |
| 1632 | if (role !== "admin") return null; |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1633 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1634 | $.each(json, function (i, item) { |
| 1635 | item.recipient_map_old = escapeHtml(item.recipient_map_old); |
| 1636 | item.recipient_map_new = escapeHtml(item.recipient_map_new); |
| 1637 | item.action = '<div class="btn-group">' + |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1638 | '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 1639 | '<a href="#" data-action="delete_selected" data-id="single-recipient_map" data-api-url="delete/recipient_map" data-item="' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1640 | '</div>'; |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1641 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="recipient_map" name="multi_select" value="' + item.id + '" />'; |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1642 | }); |
| 1643 | |
| 1644 | return json; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1645 | } |
| 1646 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1647 | columns: [ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1648 | { |
| 1649 | // placeholder, so checkbox will not block child row toggle |
| 1650 | title: '', |
| 1651 | data: null, |
| 1652 | searchable: false, |
| 1653 | orderable: false, |
| 1654 | defaultContent: '', |
| 1655 | responsivePriority: 1 |
| 1656 | }, |
| 1657 | { |
| 1658 | title: '', |
| 1659 | data: 'chkbox', |
| 1660 | searchable: false, |
| 1661 | orderable: false, |
| 1662 | defaultContent: '', |
| 1663 | responsivePriority: 2 |
| 1664 | }, |
| 1665 | { |
| 1666 | title: 'ID', |
| 1667 | data: 'id', |
| 1668 | responsivePriority: 3, |
| 1669 | defaultContent: '' |
| 1670 | }, |
| 1671 | { |
| 1672 | title: lang.recipient_map_old, |
| 1673 | data: 'recipient_map_old', |
| 1674 | defaultContent: '' |
| 1675 | }, |
| 1676 | { |
| 1677 | title: lang.recipient_map_new, |
| 1678 | data: 'recipient_map_new', |
| 1679 | defaultContent: '', |
| 1680 | responsivePriority: 4 |
| 1681 | }, |
| 1682 | { |
| 1683 | title: lang.active, |
| 1684 | data: 'active', |
| 1685 | defaultContent: '', |
| 1686 | render: function (data, type) { |
| 1687 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>'; |
| 1688 | } |
| 1689 | }, |
| 1690 | { |
| 1691 | title: lang.action, |
| 1692 | data: 'action', |
| 1693 | className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right', |
| 1694 | responsivePriority: 5, |
| 1695 | defaultContent: '' |
| 1696 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1697 | ] |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1698 | }); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1699 | |
| 1700 | table.on('responsive-resize', function (e, datatable, columns){ |
| 1701 | hideTableExpandCollapseBtn('#collapse-tab-bcc-filters', '#recipient_map_table'); |
| 1702 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1703 | } |
| 1704 | function draw_tls_policy_table() { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1705 | // just recalc width if instance already exists |
| 1706 | if ($.fn.DataTable.isDataTable('#tls_policy_table') ) { |
| 1707 | $('#tls_policy_table').DataTable().columns.adjust().responsive.recalc(); |
| 1708 | return; |
| 1709 | } |
| 1710 | |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1711 | var table = $('#tls_policy_table').DataTable({ |
| 1712 | responsive: true, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1713 | processing: true, |
| 1714 | serverSide: false, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1715 | stateSave: true, |
| 1716 | pageLength: pagination_size, |
| 1717 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 1718 | "tr" + |
| 1719 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1720 | language: lang_datatables, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1721 | order: [[2, 'desc']], |
| 1722 | initComplete: function(){ |
| 1723 | hideTableExpandCollapseBtn('#tab-tls-policy', '#tls_policy_table'); |
| 1724 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1725 | ajax: { |
| 1726 | type: "GET", |
| 1727 | url: "/api/v1/get/tls-policy-map/all", |
| 1728 | dataSrc: function(json){ |
| 1729 | if (role !== "admin") return null; |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1730 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1731 | $.each(json, function (i, item) { |
| 1732 | item.dest = escapeHtml(item.dest); |
| 1733 | item.policy = '<b>' + escapeHtml(item.policy) + '</b>'; |
| 1734 | if (item.parameters == '') { |
| 1735 | item.parameters = '<code>-</code>'; |
| 1736 | } else { |
| 1737 | item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>'; |
| 1738 | } |
| 1739 | item.action = '<div class="btn-group">' + |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1740 | '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 1741 | '<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-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1742 | '</div>'; |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1743 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />'; |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1744 | }); |
| 1745 | |
| 1746 | return json; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1747 | } |
| 1748 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1749 | columns: [ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1750 | { |
| 1751 | // placeholder, so checkbox will not block child row toggle |
| 1752 | title: '', |
| 1753 | data: null, |
| 1754 | searchable: false, |
| 1755 | orderable: false, |
| 1756 | defaultContent: '', |
| 1757 | responsivePriority: 1 |
| 1758 | }, |
| 1759 | { |
| 1760 | title: '', |
| 1761 | data: 'chkbox', |
| 1762 | searchable: false, |
| 1763 | orderable: false, |
| 1764 | defaultContent: '', |
| 1765 | responsivePriority: 2 |
| 1766 | }, |
| 1767 | { |
| 1768 | title: 'ID', |
| 1769 | data: 'id', |
| 1770 | responsivePriority: 3, |
| 1771 | defaultContent: '' |
| 1772 | }, |
| 1773 | { |
| 1774 | title: lang.tls_map_dest, |
| 1775 | data: 'dest', |
| 1776 | defaultContent: '', |
| 1777 | responsivePriority: 4 |
| 1778 | }, |
| 1779 | { |
| 1780 | title: lang.tls_map_policy, |
| 1781 | data: 'policy', |
| 1782 | defaultContent: '' |
| 1783 | }, |
| 1784 | { |
| 1785 | title: lang.tls_map_parameters, |
| 1786 | data: 'parameters', |
| 1787 | defaultContent: '' |
| 1788 | }, |
| 1789 | { |
| 1790 | title: lang.active, |
| 1791 | data: 'active', |
| 1792 | defaultContent: '', |
| 1793 | render: function (data, type) { |
| 1794 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>'; |
| 1795 | } |
| 1796 | }, |
| 1797 | { |
| 1798 | title: lang.action, |
| 1799 | data: 'action', |
| 1800 | className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right', |
| 1801 | responsivePriority: 5, |
| 1802 | defaultContent: '' |
| 1803 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1804 | ] |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1805 | }); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1806 | |
| 1807 | table.on('responsive-resize', function (e, datatable, columns){ |
| 1808 | hideTableExpandCollapseBtn('#tab-tls-policy', '#tls_policy_table'); |
| 1809 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1810 | } |
| 1811 | function draw_alias_table() { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1812 | // just recalc width if instance already exists |
| 1813 | if ($.fn.DataTable.isDataTable('#alias_table') ) { |
| 1814 | $('#alias_table').DataTable().columns.adjust().responsive.recalc(); |
| 1815 | return; |
| 1816 | } |
| 1817 | |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1818 | var table = $('#alias_table').DataTable({ |
| 1819 | responsive: true, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1820 | processing: true, |
| 1821 | serverSide: false, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1822 | stateSave: true, |
| 1823 | pageLength: pagination_size, |
| 1824 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 1825 | "tr" + |
| 1826 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1827 | language: lang_datatables, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1828 | order: [[2, 'desc']], |
| 1829 | initComplete: function(settings, json){ |
| 1830 | hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table'); |
| 1831 | filterByDomain(json, 5, table); |
| 1832 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1833 | ajax: { |
| 1834 | type: "GET", |
| 1835 | url: "/api/v1/get/alias/all", |
| 1836 | dataSrc: function(json){ |
| 1837 | $.each(json, function (i, item) { |
| 1838 | item.action = '<div class="btn-group">' + |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1839 | '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 1840 | '<a href="#" data-action="delete_selected" data-id="single-alias" data-api-url="delete/alias" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1841 | '</div>'; |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1842 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1843 | item.goto = escapeHtml(item.goto.replace(/,/g, " ")); |
| 1844 | if (item.public_comment !== null) { |
| 1845 | item.public_comment = escapeHtml(item.public_comment); |
| 1846 | } |
| 1847 | else { |
| 1848 | item.public_comment = '-'; |
| 1849 | } |
| 1850 | if (item.private_comment !== null) { |
| 1851 | item.private_comment = escapeHtml(item.private_comment); |
| 1852 | } |
| 1853 | else { |
| 1854 | item.private_comment = '-'; |
| 1855 | } |
| 1856 | if (item.is_catch_all == 1) { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1857 | item.address = '<div class="badge fs-6 bg-secondary">' + lang.catch_all + '</div> ' + escapeHtml(item.address); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1858 | } |
| 1859 | else { |
| 1860 | item.address = escapeHtml(item.address); |
| 1861 | } |
| 1862 | if (item.goto == "null@localhost") { |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 1863 | item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1864 | } |
| 1865 | else if (item.goto == "spam@localhost") { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1866 | item.goto = '<span class="badge fs-6 bg-danger">' + lang.goto_spam + '</span>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1867 | } |
| 1868 | else if (item.goto == "ham@localhost") { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1869 | item.goto = '<span class="badge fs-6 bg-success">' + lang.goto_ham + '</span>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1870 | } |
| 1871 | if (item.in_primary_domain !== "") { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1872 | item.domain = '<i data-domainname="' + item.domain + '" class="bi bi-info-circle-fill alias-domain-info text-info" data-bs-toggle="tooltip" title="' + lang.target_domain + ': ' + item.in_primary_domain + '"></i> ' + item.domain; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1873 | } |
| 1874 | }); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1875 | |
| 1876 | return json; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1877 | } |
| 1878 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1879 | columns: [ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1880 | { |
| 1881 | // placeholder, so checkbox will not block child row toggle |
| 1882 | title: '', |
| 1883 | data: null, |
| 1884 | searchable: false, |
| 1885 | orderable: false, |
| 1886 | defaultContent: '', |
| 1887 | responsivePriority: 1 |
| 1888 | }, |
| 1889 | { |
| 1890 | title: '', |
| 1891 | data: 'chkbox', |
| 1892 | searchable: false, |
| 1893 | orderable: false, |
| 1894 | defaultContent: '', |
| 1895 | responsivePriority: 2 |
| 1896 | }, |
| 1897 | { |
| 1898 | title: 'ID', |
| 1899 | data: 'id', |
| 1900 | responsivePriority: 3, |
| 1901 | defaultContent: '' |
| 1902 | }, |
| 1903 | { |
| 1904 | title: lang.alias, |
| 1905 | data: 'address', |
| 1906 | responsivePriority: 4, |
| 1907 | defaultContent: '' |
| 1908 | }, |
| 1909 | { |
| 1910 | title: lang.target_address, |
| 1911 | data: 'goto', |
| 1912 | defaultContent: '' |
| 1913 | }, |
| 1914 | { |
| 1915 | title: lang.domain, |
| 1916 | data: 'domain', |
| 1917 | defaultContent: '', |
| 1918 | responsivePriority: 5, |
| 1919 | }, |
| 1920 | { |
| 1921 | title: lang.bcc_destinations, |
| 1922 | data: 'bcc_dest', |
| 1923 | defaultContent: '' |
| 1924 | }, |
| 1925 | { |
| 1926 | title: lang.sogo_visible, |
| 1927 | data: 'sogo_visible', |
| 1928 | defaultContent: '', |
| 1929 | render: function(data, type){ |
| 1930 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>'; |
| 1931 | } |
| 1932 | }, |
| 1933 | { |
| 1934 | title: lang.public_comment, |
| 1935 | data: 'public_comment', |
| 1936 | defaultContent: '' |
| 1937 | }, |
| 1938 | { |
| 1939 | title: lang.private_comment, |
| 1940 | data: 'private_comment', |
| 1941 | defaultContent: '' |
| 1942 | }, |
| 1943 | { |
| 1944 | title: lang.active, |
| 1945 | data: 'active', |
| 1946 | defaultContent: '', |
| 1947 | responsivePriority: 6, |
| 1948 | render: function (data, type) { |
| 1949 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>'; |
| 1950 | } |
| 1951 | }, |
| 1952 | { |
| 1953 | title: lang.action, |
| 1954 | data: 'action', |
| 1955 | className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right', |
| 1956 | responsivePriority: 5, |
| 1957 | defaultContent: '' |
| 1958 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1959 | ] |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1960 | }); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1961 | |
| 1962 | table.on('responsive-resize', function (e, datatable, columns){ |
| 1963 | hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table'); |
| 1964 | }); |
| 1965 | |
| 1966 | table.on( 'draw', function (){ |
| 1967 | $('#alias_table [data-bs-toggle="tooltip"]').tooltip(); |
| 1968 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1969 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1970 | function draw_aliasdomain_table() { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1971 | // just recalc width if instance already exists |
| 1972 | if ($.fn.DataTable.isDataTable('#aliasdomain_table') ) { |
| 1973 | $('#aliasdomain_table').DataTable().columns.adjust().responsive.recalc(); |
| 1974 | return; |
| 1975 | } |
| 1976 | |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1977 | var table = $('#aliasdomain_table').DataTable({ |
| 1978 | responsive: true, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1979 | processing: true, |
| 1980 | serverSide: false, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1981 | stateSave: true, |
| 1982 | pageLength: pagination_size, |
| 1983 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 1984 | "tr" + |
| 1985 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1986 | language: lang_datatables, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1987 | initComplete: function(){ |
| 1988 | hideTableExpandCollapseBtn('#tab-domain-aliases', '#aliasdomain_table'); |
| 1989 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 1990 | ajax: { |
| 1991 | type: "GET", |
| 1992 | url: "/api/v1/get/alias-domain/all", |
| 1993 | dataSrc: function(json){ |
| 1994 | $.each(json, function (i, item) { |
| 1995 | item.alias_domain = escapeHtml(item.alias_domain); |
| 1996 | |
| 1997 | item.action = '<div class="btn-group">' + |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1998 | '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-sm btn-xs-lg btn-xs-third btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 1999 | '<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-sm btn-xs-lg btn-xs-third btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
| 2000 | '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-lg btn-xs-third btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.alias_domain) + '"><i class="bi bi-globe2"></i> DNS</a></div>' + |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2001 | '</div>'; |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2002 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2003 | if(item.parent_is_backupmx == '1') { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2004 | item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a> <div class="badge fs-6 bg-warning">' + lang.alias_domain_backupmx + '</div></span>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2005 | } else { |
| 2006 | item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>'; |
| 2007 | } |
| 2008 | }); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2009 | |
| 2010 | return json; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2011 | } |
| 2012 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2013 | columns: [ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2014 | { |
| 2015 | // placeholder, so checkbox will not block child row toggle |
| 2016 | title: '', |
| 2017 | data: null, |
| 2018 | searchable: false, |
| 2019 | orderable: false, |
| 2020 | defaultContent: '', |
| 2021 | responsivePriority: 1 |
| 2022 | }, |
| 2023 | { |
| 2024 | title: '', |
| 2025 | data: 'chkbox', |
| 2026 | searchable: false, |
| 2027 | orderable: false, |
| 2028 | defaultContent: '', |
| 2029 | responsivePriority: 2 |
| 2030 | }, |
| 2031 | { |
| 2032 | title: lang.alias, |
| 2033 | data: 'alias_domain', |
| 2034 | responsivePriority: 3, |
| 2035 | defaultContent: '' |
| 2036 | }, |
| 2037 | { |
| 2038 | title: lang.target_domain, |
| 2039 | data: 'target_domain', |
| 2040 | responsivePriority: 4, |
| 2041 | defaultContent: '' |
| 2042 | }, |
| 2043 | { |
| 2044 | title: lang.active, |
| 2045 | data: 'active', |
| 2046 | defaultContent: '', |
| 2047 | render: function (data, type) { |
| 2048 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>'; |
| 2049 | } |
| 2050 | }, |
| 2051 | { |
| 2052 | title: lang.action, |
| 2053 | data: 'action', |
| 2054 | className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right', |
| 2055 | responsivePriority: 5, |
| 2056 | defaultContent: '' |
| 2057 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2058 | ] |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2059 | }); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2060 | |
| 2061 | table.on('responsive-resize', function (e, datatable, columns){ |
| 2062 | hideTableExpandCollapseBtn('#tab-domain-aliases', '#aliasdomain_table'); |
| 2063 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2064 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2065 | function draw_sync_job_table() { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2066 | // just recalc width if instance already exists |
| 2067 | if ($.fn.DataTable.isDataTable('#sync_job_table') ) { |
| 2068 | $('#sync_job_table').DataTable().columns.adjust().responsive.recalc(); |
| 2069 | return; |
| 2070 | } |
| 2071 | |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2072 | var table = $('#sync_job_table').DataTable({ |
| 2073 | responsive: true, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2074 | processing: true, |
| 2075 | serverSide: false, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2076 | stateSave: true, |
| 2077 | pageLength: pagination_size, |
| 2078 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 2079 | "tr" + |
| 2080 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2081 | language: lang_datatables, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2082 | order: [[2, 'desc']], |
| 2083 | initComplete: function(){ |
| 2084 | hideTableExpandCollapseBtn('#tab-syncjobs', '#sync_job_table'); |
| 2085 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2086 | ajax: { |
| 2087 | type: "GET", |
| 2088 | url: "/api/v1/get/syncjobs/all/no_log", |
| 2089 | dataSrc: function(json){ |
| 2090 | $.each(json, function (i, item) { |
| 2091 | item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>' |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2092 | item.user2 = escapeHtml(item.user2); |
| 2093 | if (!item.exclude > 0) { |
| 2094 | item.exclude = '-'; |
| 2095 | } else { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2096 | item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2097 | } |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2098 | item.server_w_port = escapeHtml(item.user1) + '@' + escapeHtml(item.host1) + ':' + escapeHtml(item.port1); |
| 2099 | item.action = '<div class="btn-group">' + |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2100 | '<a href="/edit/syncjob/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 2101 | '<a href="#" data-action="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2102 | '</div>'; |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2103 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="syncjob" name="multi_select" value="' + item.id + '" />'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2104 | if (item.is_running == 1) { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2105 | item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2106 | } else { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2107 | item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2108 | } |
| 2109 | if (!item.last_run > 0) { |
| 2110 | item.last_run = lang.waiting; |
| 2111 | } |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 2112 | if (item.success == null) { |
| 2113 | item.success = '-'; |
| 2114 | item.exit_status = ''; |
| 2115 | } else { |
| 2116 | item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>'; |
| 2117 | } |
| 2118 | if (lang['syncjob_'+item.exit_status]) { |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2119 | item.exit_status = lang['syncjob_'+item.exit_status]; |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 2120 | } else if (item.success != '-') { |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2121 | item.exit_status = lang.syncjob_check_log; |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 2122 | } |
| 2123 | item.exit_status = item.success + ' ' + item.exit_status; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2124 | }); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2125 | |
| 2126 | return json; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2127 | } |
| 2128 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2129 | columns: [ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2130 | { |
| 2131 | // placeholder, so checkbox will not block child row toggle |
| 2132 | title: '', |
| 2133 | data: null, |
| 2134 | searchable: false, |
| 2135 | orderable: false, |
| 2136 | defaultContent: '', |
| 2137 | responsivePriority: 1 |
| 2138 | }, |
| 2139 | { |
| 2140 | title: '', |
| 2141 | data: 'chkbox', |
| 2142 | searchable: false, |
| 2143 | orderable: false, |
| 2144 | defaultContent: '', |
| 2145 | responsivePriority: 2 |
| 2146 | }, |
| 2147 | { |
| 2148 | title: 'ID', |
| 2149 | data: 'id', |
| 2150 | responsivePriority: 3, |
| 2151 | defaultContent: '' |
| 2152 | }, |
| 2153 | { |
| 2154 | title: lang.owner, |
| 2155 | data: 'user2', |
| 2156 | responsivePriority: 4, |
| 2157 | defaultContent: '' |
| 2158 | }, |
| 2159 | { |
| 2160 | title: 'Server', |
| 2161 | data: 'server_w_port', |
| 2162 | defaultContent: '' |
| 2163 | }, |
| 2164 | { |
| 2165 | title: lang.last_run, |
| 2166 | data: 'last_run', |
| 2167 | defaultContent: '' |
| 2168 | }, |
| 2169 | { |
| 2170 | title: lang.syncjob_last_run_result, |
| 2171 | data: 'exit_status', |
| 2172 | defaultContent: '' |
| 2173 | }, |
| 2174 | { |
| 2175 | title: 'Log', |
| 2176 | data: 'log', |
| 2177 | defaultContent: '' |
| 2178 | }, |
| 2179 | { |
| 2180 | title: lang.active, |
| 2181 | data: 'active', |
| 2182 | defaultContent: '', |
| 2183 | render: function (data, type) { |
| 2184 | return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>'; |
| 2185 | } |
| 2186 | }, |
| 2187 | { |
| 2188 | title: lang.status, |
| 2189 | data: 'is_running', |
| 2190 | defaultContent: '' |
| 2191 | }, |
| 2192 | { |
| 2193 | title: lang.excludes, |
| 2194 | data: 'exclude', |
| 2195 | defaultContent: '', |
| 2196 | className: 'none' |
| 2197 | }, |
| 2198 | { |
| 2199 | title: lang.mins_interval, |
| 2200 | data: 'mins_interval', |
| 2201 | defaultContent: '', |
| 2202 | className: 'none' |
| 2203 | }, |
| 2204 | { |
| 2205 | title: lang.action, |
| 2206 | data: 'action', |
| 2207 | className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right', |
| 2208 | responsivePriority: 5, |
| 2209 | defaultContent: '' |
| 2210 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2211 | ] |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2212 | }); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2213 | |
| 2214 | table.on('responsive-resize', function (e, datatable, columns){ |
| 2215 | hideTableExpandCollapseBtn('#tab-syncjobs', '#sync_job_table'); |
| 2216 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2217 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2218 | function draw_filter_table() { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2219 | // just recalc width if instance already exists |
| 2220 | if ($.fn.DataTable.isDataTable('#filter_table') ) { |
| 2221 | $('#filter_table').DataTable().columns.adjust().responsive.recalc(); |
| 2222 | return; |
| 2223 | } |
| 2224 | |
| 2225 | var table = $('#filter_table').DataTable({ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2226 | responsive: true, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2227 | autoWidth: false, |
| 2228 | processing: true, |
| 2229 | serverSide: false, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2230 | stateSave: true, |
| 2231 | pageLength: pagination_size, |
| 2232 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 2233 | "tr" + |
| 2234 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2235 | language: lang_datatables, |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2236 | order: [[2, 'desc']], |
| 2237 | initComplete: function(){ |
| 2238 | hideTableExpandCollapseBtn('#tab-filters', '#filter_table'); |
| 2239 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2240 | ajax: { |
| 2241 | type: "GET", |
| 2242 | url: "/api/v1/get/filters/all", |
| 2243 | dataSrc: function(json){ |
| 2244 | $.each(json, function (i, item) { |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2245 | if (item.active == 1) { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2246 | item.active = '<span id="active-script" class="badge fs-6 bg-success">' + lang.active + '</span>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2247 | } else { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2248 | item.active = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.inactive + '</span>'; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2249 | } |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2250 | item.script_desc = escapeHtml(item.script_desc); |
| 2251 | item.script_data = '<pre class="text-break" style="margin:0px">' + escapeHtml(item.script_data) + '</pre>' |
| 2252 | item.filter_type = '<div class="badge fs-6 bg-secondary">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>' |
| 2253 | item.action = '<div class="btn-group">' + |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2254 | '<a href="/edit/filter/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 2255 | '<a href="#" data-action="delete_selected" data-id="single-filter" data-api-url="delete/filter" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2256 | '</div>'; |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2257 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="filter_item" name="multi_select" value="' + item.id + '" />' |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2258 | }); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2259 | |
| 2260 | return json; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2261 | } |
| 2262 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2263 | columns: [ |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2264 | { |
| 2265 | // placeholder, so checkbox will not block child row toggle |
| 2266 | title: '', |
| 2267 | data: null, |
| 2268 | searchable: false, |
| 2269 | orderable: false, |
| 2270 | defaultContent: '', |
| 2271 | responsivePriority: 1 |
| 2272 | }, |
| 2273 | { |
| 2274 | title: '', |
| 2275 | data: 'chkbox', |
| 2276 | searchable: false, |
| 2277 | orderable: false, |
| 2278 | defaultContent: '', |
| 2279 | responsivePriority: 2 |
| 2280 | }, |
| 2281 | { |
| 2282 | title: 'ID', |
| 2283 | data: 'id', |
| 2284 | responsivePriority: 2, |
| 2285 | defaultContent: '' |
| 2286 | }, |
| 2287 | { |
| 2288 | title: lang.active, |
| 2289 | data: 'active', |
| 2290 | responsivePriority: 3, |
| 2291 | defaultContent: '' |
| 2292 | }, |
| 2293 | { |
| 2294 | title: 'Type', |
| 2295 | data: 'filter_type', |
| 2296 | responsivePriority: 4, |
| 2297 | defaultContent: '' |
| 2298 | }, |
| 2299 | { |
| 2300 | title: lang.owner, |
| 2301 | data: 'username', |
| 2302 | defaultContent: '' |
| 2303 | }, |
| 2304 | { |
| 2305 | title: lang.description, |
| 2306 | data: 'script_desc', |
| 2307 | defaultContent: '' |
| 2308 | }, |
| 2309 | { |
| 2310 | title: 'Script', |
| 2311 | data: 'script_data', |
| 2312 | defaultContent: '', |
| 2313 | className: 'none' |
| 2314 | }, |
| 2315 | { |
| 2316 | title: lang.action, |
| 2317 | data: 'action', |
| 2318 | className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right', |
| 2319 | responsivePriority: 5, |
| 2320 | defaultContent: '' |
| 2321 | }, |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2322 | ] |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2323 | }); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2324 | |
| 2325 | table.on('responsive-resize', function (e, datatable, columns){ |
| 2326 | hideTableExpandCollapseBtn('#tab-filters', '#filter_table'); |
| 2327 | }); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2328 | }; |
| 2329 | |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2330 | function hideTableExpandCollapseBtn(tab, table){ |
| 2331 | if ($(table).hasClass('collapsed')) |
| 2332 | $(tab).find(".table_collapse_option").show(); |
| 2333 | else |
| 2334 | $(tab).find(".table_collapse_option").hide(); |
| 2335 | } |
| 2336 | |
| 2337 | function filterByDomain(json, column, table){ |
| 2338 | var tableId = $(table.table().container()).attr('id'); |
| 2339 | // Create the `select` element |
| 2340 | var select = $('<select class="btn btn-sm btn-xs-lg btn-light text-start mx-2"><option value="">'+lang.all_domains+'</option></select>') |
| 2341 | .insertBefore( |
| 2342 | $('#'+tableId+' .dataTables_filter > label > input') |
| 2343 | ) |
| 2344 | .on( 'change', function(){ |
| 2345 | table.column(column) |
| 2346 | .search($(this).val()) |
| 2347 | .draw(); |
| 2348 | }); |
| 2349 | |
| 2350 | // get all domains |
| 2351 | var domains = []; |
| 2352 | json.forEach(obj => { |
| 2353 | Object.entries(obj).forEach(([key, value]) => { |
| 2354 | if(key === 'domain') { |
| 2355 | domains.push(value) |
| 2356 | } |
| 2357 | }); |
| 2358 | }); |
| 2359 | |
| 2360 | // get unique domain list |
| 2361 | domains = domains.filter(function(value, index, array) { |
| 2362 | return array.indexOf(value) === index; |
| 2363 | }); |
| 2364 | |
| 2365 | // add domains to select |
| 2366 | domains.forEach(function(domain) { |
| 2367 | select.append($('<option>' + domain + '</option>')); |
| 2368 | }); |
| 2369 | } |
| 2370 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2371 | // detect element visibility changes |
| 2372 | function onVisible(element, callback) { |
| 2373 | $(document).ready(function() { |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2374 | let element_object = document.querySelector(element); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2375 | if (element_object === null) return; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2376 | |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2377 | let observer = new IntersectionObserver((entries, observer) => { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2378 | entries.forEach(entry => { |
| 2379 | if(entry.intersectionRatio > 0) { |
| 2380 | callback(element_object); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2381 | observer.unobserve(element_object); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2382 | } |
| 2383 | }); |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 2384 | }) |
| 2385 | |
| 2386 | observer.observe(element_object); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2387 | }); |
| 2388 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2389 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 2390 | // Load only if the tab is visible |
| 2391 | onVisible("[id^=domain_table]", () => draw_domain_table()); |
| 2392 | onVisible("[id^=templates_domain_table]", () => draw_templates_domain_table()); |
| 2393 | onVisible("[id^=mailbox_table]", () => draw_mailbox_table()); |
| 2394 | onVisible("[id^=templates_mbox_table]", () => draw_templates_mbox_table()); |
| 2395 | onVisible("[id^=resource_table]", () => draw_resource_table()); |
| 2396 | onVisible("[id^=alias_table]", () => draw_alias_table()); |
| 2397 | onVisible("[id^=aliasdomain_table]", () => draw_aliasdomain_table()); |
| 2398 | onVisible("[id^=sync_job_table]", () => draw_sync_job_table()); |
| 2399 | onVisible("[id^=filter_table]", () => draw_filter_table()); |
| 2400 | onVisible("[id^=bcc_table]", () => draw_bcc_table()); |
| 2401 | onVisible("[id^=recipient_map_table]", () => draw_recipient_map_table()); |
| 2402 | onVisible("[id^=tls_policy_table]", () => draw_tls_policy_table()); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 2403 | }); |