mailbox.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. $(document).ready(function() {
  2. // Show element counter for tables
  3. $('[data-toggle="tooltip"]').tooltip();
  4. function humanFileSize(bytes) {
  5. if(Math.abs(bytes) < 1024) {
  6. return bytes + ' B';
  7. }
  8. var units = ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
  9. var u = -1;
  10. do {
  11. bytes /= 1024;
  12. ++u;
  13. } while(Math.abs(bytes) >= 1024 && u < units.length - 1);
  14. return bytes.toFixed(1)+' '+units[u];
  15. }
  16. $.ajax({
  17. dataType: 'json',
  18. url: '/json_api.php?action=domain_table_data',
  19. jsonp: false,
  20. error: function () {
  21. alert('Cannot receive history');
  22. },
  23. success: function (data) {
  24. $.each(data, function (i, item) {
  25. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  26. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  27. item.quota = humanFileSize(item.quota_used_in_domain) + " / " + humanFileSize(item.max_quota_for_domain);
  28. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  29. item.action = '<div class="btn-group">' +
  30. '<a href="/edit.php?domain=' + item.domain_name + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> Edit</a>' +
  31. '<a href="/delete.php?domain=' + item.domain_name + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> Remove</a>' +
  32. '</div>';
  33. });
  34. $('#domain_table').footable({
  35. "columns": [
  36. {"sorted": true,"name":"domain_name","title":lang_domain},
  37. {"name":"aliases","title":lang_aliases,"breakpoints":"xs sm"},
  38. {"name":"mailboxes","title":lang_mailboxes},
  39. {"name":"quota","title":lang_domain_quota},
  40. {"name":"max_quota_for_mbox","title":lang_mailbox_quota},
  41. {"name":"backupmx","title":lang_backup_mx,"breakpoints":"xs sm"},
  42. {"name":"active","title":lang_active,"breakpoints":"xs sm"},
  43. {"name":"action","type":"html","title":lang_action,"breakpoints":"xs sm"}
  44. ],
  45. "rows": data,
  46. "paging": {
  47. "enabled": true,
  48. "limit": 5,
  49. "size": 25
  50. },
  51. "filtering": {
  52. "enabled": true,
  53. "position": "left"
  54. },
  55. "sorting": {
  56. "enabled": true
  57. }
  58. });
  59. }
  60. });
  61. $.ajax({
  62. dataType: 'json',
  63. url: '/json_api.php?action=mailbox_table_data',
  64. jsonp: false,
  65. error: function () {
  66. alert('Cannot receive history');
  67. },
  68. success: function (data) {
  69. $.each(data, function (i, item) {
  70. item.quota = humanFileSize(item.quota_used) + " / " + humanFileSize(item.quota);
  71. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  72. item.action = '<div class="btn-group">' +
  73. '<a href="/edit.php?mailbox=' + item.username + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> Edit</a>' +
  74. '<a href="/delete.php?mailbox=' + item.username + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> Remove</a>' +
  75. '</div>';
  76. item.in_use = '<div class="progress">' +
  77. '<div class="progress-bar progress-bar-' + item.percent_class + ' role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  78. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  79. });
  80. $('#mailbox_table').footable({
  81. "columns": [
  82. {"sorted": true,"name":"username","title":lang_username},
  83. {"name":"name","title":lang_fname,"breakpoints":"xs sm"},
  84. {"name":"domain","title":lang_domain},
  85. {"name":"quota","title":lang_domain_quota},
  86. {"name":"spam_aliases","title":lang_spam_aliases},
  87. {"name":"in_use","type":"html","title":lang_in_use},
  88. {"name":"messages","title":lang_msg_num,"breakpoints":"xs sm"},
  89. {"name":"active","title":lang_active,"breakpoints":"xs sm"},
  90. {"name":"action","type":"html","title":lang_action,"breakpoints":"xs sm"}
  91. ],
  92. "rows": data,
  93. "paging": {
  94. "enabled": true,
  95. "limit": 5,
  96. "size": 25
  97. },
  98. "filtering": {
  99. "enabled": true,
  100. "position": "left"
  101. },
  102. "sorting": {
  103. "enabled": true
  104. }
  105. });
  106. }
  107. });
  108. });