mailbox.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 draw domain table');
  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> ' + lang.edit + '</a>' +
  31. '<a href="/delete.php?domain=' + item.domain_name + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  32. '</div>';
  33. });
  34. $('#domain_table').footable({
  35. "columns": [
  36. {"sorted": true,"name":"domain_name","title":lang.domain,"style":{"width":"250px"}},
  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,"breakpoints":"xs sm"},
  41. {"name":"backupmx","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.backup_mx,"breakpoints":"xs sm"},
  42. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  43. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  44. ],
  45. "rows": data,
  46. "empty": lang.empty,
  47. "paging": {
  48. "enabled": true,
  49. "limit": 5,
  50. "size": 25
  51. },
  52. "filtering": {
  53. "enabled": true,
  54. "position": "left",
  55. "placeholder": lang.filter_table
  56. },
  57. "sorting": {
  58. "enabled": true
  59. }
  60. });
  61. }
  62. });
  63. $.ajax({
  64. dataType: 'json',
  65. url: '/json_api.php?action=mailbox_table_data',
  66. jsonp: false,
  67. error: function () {
  68. alert('Cannot draw mailbox table');
  69. },
  70. success: function (data) {
  71. $.each(data, function (i, item) {
  72. item.quota = humanFileSize(item.quota_used) + " / " + humanFileSize(item.quota);
  73. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  74. item.action = '<div class="btn-group">' +
  75. '<a href="/edit.php?mailbox=' + item.username + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  76. '<a href="/delete.php?mailbox=' + item.username + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  77. '</div>';
  78. item.in_use = '<div class="progress">' +
  79. '<div class="progress-bar progress-bar-' + item.percent_class + ' role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  80. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  81. });
  82. $('#mailbox_table').footable({
  83. "columns": [
  84. {"sorted": true,"name":"username","title":lang.username,"style":{"width":"250px"}},
  85. {"name":"name","title":lang.fname,"breakpoints":"xs sm"},
  86. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  87. {"name":"quota","title":lang.domain_quota},
  88. {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"xs sm"},
  89. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use},
  90. {"name":"messages","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.msg_num,"breakpoints":"xs sm"},
  91. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  92. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  93. ],
  94. "empty": lang.empty,
  95. "rows": data,
  96. "paging": {
  97. "enabled": true,
  98. "limit": 5,
  99. "size": 25
  100. },
  101. "filtering": {
  102. "enabled": true,
  103. "position": "left",
  104. "placeholder": lang.filter_table
  105. },
  106. "sorting": {
  107. "enabled": true
  108. }
  109. });
  110. }
  111. });
  112. $.ajax({
  113. dataType: 'json',
  114. url: '/json_api.php?action=resource_table_data',
  115. jsonp: false,
  116. error: function () {
  117. alert('Cannot draw resource table');
  118. },
  119. success: function (data) {
  120. $.each(data, function (i, item) {
  121. item.action = '<div class="btn-group">' +
  122. '<a href="/edit.php?resource=' + item.name + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  123. '<a href="/delete.php?resource=' + item.name + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  124. '</div>';
  125. });
  126. $('#resources_table').footable({
  127. "columns": [
  128. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  129. {"name":"kind","title":lang.kind},
  130. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  131. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  132. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  133. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  134. ],
  135. "empty": lang.empty,
  136. "rows": data,
  137. "paging": {
  138. "enabled": true,
  139. "limit": 5,
  140. "size": 25
  141. },
  142. "filtering": {
  143. "enabled": true,
  144. "position": "left",
  145. "placeholder": lang.filter_table
  146. },
  147. "sorting": {
  148. "enabled": true
  149. }
  150. });
  151. }
  152. });
  153. $.ajax({
  154. dataType: 'json',
  155. url: '/json_api.php?action=domain_alias_table_data',
  156. jsonp: false,
  157. error: function () {
  158. alert('Cannot draw alias domain table');
  159. },
  160. success: function (data) {
  161. $.each(data, function (i, item) {
  162. item.action = '<div class="btn-group">' +
  163. '<a href="/edit.php?aliasdomain=' + item.alias_domain + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  164. '<a href="/delete.php?aliasdomain=' + item.alias_domain + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  165. '</div>';
  166. });
  167. $('#aliasdomain_table').footable({
  168. "columns": [
  169. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  170. {"name":"target_domain","title":lang.target_domain},
  171. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  172. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  173. ],
  174. "empty": lang.empty,
  175. "rows": data,
  176. "paging": {
  177. "enabled": true,
  178. "limit": 5,
  179. "size": 25
  180. },
  181. "filtering": {
  182. "enabled": true,
  183. "position": "left",
  184. "placeholder": lang.filter_table
  185. },
  186. "sorting": {
  187. "enabled": true
  188. }
  189. });
  190. }
  191. });
  192. $.ajax({
  193. dataType: 'json',
  194. url: '/json_api.php?action=alias_table_data',
  195. jsonp: false,
  196. error: function () {
  197. alert('Cannot draw alias table');
  198. },
  199. success: function (data) {
  200. $.each(data, function (i, item) {
  201. if (item.is_catch_all == 1) {
  202. item.address = '<div class="label label-default">Catch-All</div> ' + item.address;
  203. }
  204. item.action = '<div class="btn-group">' +
  205. '<a href="/edit.php?alias=' + item.address + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  206. '<a href="/delete.php?alias=' + item.address + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  207. '</div>';
  208. });
  209. $('#alias_table').footable({
  210. "columns": [
  211. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  212. {"name":"goto","title":lang.target_address},
  213. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  214. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  215. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  216. ],
  217. "empty": lang.empty,
  218. "rows": data,
  219. "paging": {
  220. "enabled": true,
  221. "limit": 5,
  222. "size": 5
  223. },
  224. "filtering": {
  225. "enabled": true,
  226. "position": "left",
  227. "placeholder": lang.filter_table
  228. },
  229. "sorting": {
  230. "enabled": true
  231. }
  232. });
  233. }
  234. });
  235. });