mailbox.js 46 KB

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