mailbox.js 12 KB

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