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