mailbox.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. $(document).ready(function() {
  2. $('[data-toggle="tooltip"]').tooltip();
  3. function humanFileSize(bytes) {
  4. if(Math.abs(bytes) < 1024) {
  5. return bytes + ' B';
  6. }
  7. var units = ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
  8. var u = -1;
  9. do {
  10. bytes /= 1024;
  11. ++u;
  12. } while(Math.abs(bytes) >= 1024 && u < units.length - 1);
  13. return bytes.toFixed(1)+' '+units[u];
  14. }
  15. $.ajax({
  16. dataType: 'json',
  17. url: '/json_api.php?action=domain_table_data',
  18. jsonp: false,
  19. error: function () {
  20. alert('Cannot draw domain table');
  21. },
  22. success: function (data) {
  23. $.each(data, function (i, item) {
  24. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  25. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  26. item.quota = humanFileSize(item.quota_used_in_domain) + " / " + humanFileSize(item.max_quota_for_domain);
  27. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  28. if (role == "admin") {
  29. item.action = '<div class="btn-group">' +
  30. '<a href="/edit.php?domain=' + encodeURI(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  31. '<a href="/delete.php?domain=' + encodeURI(item.domain_name) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  32. '</div>';
  33. }
  34. else {
  35. item.action = '<div class="btn-group">' +
  36. '<a href="/edit.php?domain=' + encodeURI(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  37. '</div>';
  38. }
  39. });
  40. $('#domain_table').footable({
  41. "columns": [
  42. {"sorted": true,"name":"domain_name","title":lang.domain,"style":{"width":"250px"}},
  43. {"name":"aliases","title":lang.aliases,"breakpoints":"xs sm"},
  44. {"name":"mailboxes","title":lang.mailboxes},
  45. {"name":"quota","title":lang.domain_quota},
  46. {"name":"max_quota_for_mbox","title":lang.mailbox_quota,"breakpoints":"xs sm"},
  47. {"name":"backupmx","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.backup_mx,"breakpoints":"xs sm"},
  48. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  49. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  50. ],
  51. "rows": data,
  52. "empty": lang.empty,
  53. "paging": {
  54. "enabled": true,
  55. "limit": 5,
  56. "size": pagination_size
  57. },
  58. "filtering": {
  59. "enabled": true,
  60. "position": "left",
  61. "placeholder": lang.filter_table
  62. },
  63. "sorting": {
  64. "enabled": true
  65. }
  66. });
  67. }
  68. });
  69. $.ajax({
  70. dataType: 'json',
  71. url: '/json_api.php?action=mailbox_table_data',
  72. jsonp: false,
  73. error: function () {
  74. alert('Cannot draw mailbox table');
  75. },
  76. success: function (data) {
  77. $.each(data, function (i, item) {
  78. item.quota = humanFileSize(item.quota_used) + " / " + humanFileSize(item.quota);
  79. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  80. if (role == "admin") {
  81. item.action = '<div class="btn-group">' +
  82. '<a href="/edit.php?mailbox=' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  83. '<a href="/delete.php?mailbox=' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  84. '<a href="/index.php?duallogin=' + encodeURI(item.username) + '" class="btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>' +
  85. '</div>';
  86. }
  87. else {
  88. item.action = '<div class="btn-group">' +
  89. '<a href="/edit.php?mailbox=' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  90. '<a href="/delete.php?mailbox=' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  91. '</div>';
  92. }
  93. item.in_use = '<div class="progress">' +
  94. '<div class="progress-bar progress-bar-' + item.percent_class + ' role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  95. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  96. });
  97. $('#mailbox_table').footable({
  98. "columns": [
  99. {"sorted": true,"name":"username","title":lang.username,"style":{"width":"250px"}},
  100. {"name":"name","title":lang.fname,"breakpoints":"xs sm"},
  101. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  102. {"name":"quota","title":lang.domain_quota},
  103. {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"xs sm"},
  104. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use},
  105. {"name":"messages","filterable": false,"style":{"width":"90px"},"title":lang.msg_num,"breakpoints":"xs sm"},
  106. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  107. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","width":"290px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  108. ],
  109. "empty": lang.empty,
  110. "rows": data,
  111. "paging": {
  112. "enabled": true,
  113. "limit": 5,
  114. "size": pagination_size
  115. },
  116. "filtering": {
  117. "enabled": true,
  118. "position": "left",
  119. "placeholder": lang.filter_table
  120. },
  121. "sorting": {
  122. "enabled": true
  123. }
  124. });
  125. }
  126. });
  127. $.ajax({
  128. dataType: 'json',
  129. url: '/json_api.php?action=resource_table_data',
  130. jsonp: false,
  131. error: function () {
  132. alert('Cannot draw resource table');
  133. },
  134. success: function (data) {
  135. $.each(data, function (i, item) {
  136. item.action = '<div class="btn-group">' +
  137. '<a href="/edit.php?resource=' + encodeURI(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  138. '<a href="/delete.php?resource=' + encodeURI(item.name) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  139. '</div>';
  140. });
  141. $('#resources_table').footable({
  142. "columns": [
  143. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  144. {"name":"kind","title":lang.kind},
  145. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  146. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  147. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  148. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  149. ],
  150. "empty": lang.empty,
  151. "rows": data,
  152. "paging": {
  153. "enabled": true,
  154. "limit": 5,
  155. "size": pagination_size
  156. },
  157. "filtering": {
  158. "enabled": true,
  159. "position": "left",
  160. "placeholder": lang.filter_table
  161. },
  162. "sorting": {
  163. "enabled": true
  164. }
  165. });
  166. }
  167. });
  168. $.ajax({
  169. dataType: 'json',
  170. url: '/json_api.php?action=domain_alias_table_data',
  171. jsonp: false,
  172. error: function () {
  173. alert('Cannot draw alias domain table');
  174. },
  175. success: function (data) {
  176. $.each(data, function (i, item) {
  177. item.action = '<div class="btn-group">' +
  178. '<a href="/edit.php?aliasdomain=' + encodeURI(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  179. '<a href="/delete.php?aliasdomain=' + encodeURI(item.alias_domain) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  180. '</div>';
  181. });
  182. $('#aliasdomain_table').footable({
  183. "columns": [
  184. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  185. {"name":"target_domain","title":lang.target_domain},
  186. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  187. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  188. ],
  189. "empty": lang.empty,
  190. "rows": data,
  191. "paging": {
  192. "enabled": true,
  193. "limit": 5,
  194. "size": pagination_size
  195. },
  196. "filtering": {
  197. "enabled": true,
  198. "position": "left",
  199. "placeholder": lang.filter_table
  200. },
  201. "sorting": {
  202. "enabled": true
  203. }
  204. });
  205. }
  206. });
  207. $.ajax({
  208. dataType: 'json',
  209. url: '/json_api.php?action=alias_table_data',
  210. jsonp: false,
  211. error: function () {
  212. alert('Cannot draw alias table');
  213. },
  214. success: function (data) {
  215. $.each(data, function (i, item) {
  216. if (item.is_catch_all == 1) {
  217. item.address = '<div class="label label-default">Catch-All</div> ' + item.address;
  218. }
  219. item.action = '<div class="btn-group">' +
  220. '<a href="/edit.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  221. '<a href="/delete.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  222. '</div>';
  223. });
  224. $('#alias_table').footable({
  225. "columns": [
  226. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  227. {"name":"goto","title":lang.target_address},
  228. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  229. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  230. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  231. ],
  232. "empty": lang.empty,
  233. "rows": data,
  234. "paging": {
  235. "enabled": true,
  236. "limit": 5,
  237. "size": 5
  238. },
  239. "filtering": {
  240. "enabled": true,
  241. "position": "left",
  242. "placeholder": lang.filter_table
  243. },
  244. "sorting": {
  245. "enabled": true
  246. }
  247. });
  248. }
  249. });
  250. });