mailbox.js 11 KB

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