mailbox.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. jQuery(function($){
  2. // Calculation human readable file sizes
  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. function unix_time_format(tm) {
  16. var date = new Date(tm ? tm * 1000 : 0);
  17. return date.toLocaleString();
  18. }
  19. function draw_domain_table() {
  20. ft_domain_table = FooTable.init('#domain_table', {
  21. "columns": [
  22. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  23. {"sorted": true,"name":"domain_name","title":lang.domain,"style":{"width":"250px"}},
  24. {"name":"aliases","title":lang.aliases,"breakpoints":"xs sm"},
  25. {"name":"mailboxes","title":lang.mailboxes},
  26. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  27. res = value.split("/");
  28. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  29. },
  30. "sortValue": function(value){
  31. res = value.split("/");
  32. return res[0];
  33. },
  34. },
  35. {"name":"max_quota_for_mbox","title":lang.mailbox_quota,"breakpoints":"xs sm"},
  36. {"name":"backupmx","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.backup_mx,"breakpoints":"xs sm"},
  37. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  38. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  39. ],
  40. "rows": $.ajax({
  41. dataType: 'json',
  42. url: '/api/v1/get/domain/all',
  43. jsonp: false,
  44. error: function (data) {
  45. console.log('Cannot draw domain table');
  46. },
  47. success: function (data) {
  48. $.each(data, function (i, item) {
  49. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  50. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  51. item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain;
  52. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  53. item.chkbox = '<input type="checkbox" data-id="domain" name="multi_select" value="' + item.domain_name + '" />';
  54. if (role == "admin") {
  55. item.action = '<div class="btn-group">' +
  56. '<a href="/edit.php?domain=' + encodeURI(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  57. '<a href="/delete.php?domain=' + encodeURI(item.domain_name) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  58. '</div>';
  59. }
  60. else {
  61. item.action = '<div class="btn-group">' +
  62. '<a href="/edit.php?domain=' + encodeURI(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  63. '</div>';
  64. }
  65. });
  66. }
  67. }),
  68. "empty": lang.empty,
  69. "paging": {
  70. "enabled": true,
  71. "limit": 5,
  72. "size": pagination_size
  73. },
  74. "filtering": {
  75. "enabled": true,
  76. "position": "left",
  77. "placeholder": lang.filter_table
  78. },
  79. "sorting": {
  80. "enabled": true
  81. }
  82. });
  83. }
  84. function draw_mailbox_table() {
  85. ft_mailbox_table = FooTable.init('#mailbox_table', {
  86. "columns": [
  87. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  88. {"sorted": true,"name":"username","style":{"word-break":"break-all","min-width":"120px"},"title":lang.username},
  89. {"name":"name","title":lang.fname,"style":{"word-break":"break-all","min-width":"120px"},"breakpoints":"xs sm"},
  90. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  91. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  92. res = value.split("/");
  93. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  94. },
  95. "sortValue": function(value){
  96. res = value.split("/");
  97. return res[0];
  98. },
  99. },
  100. {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"xs sm md"},
  101. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use},
  102. {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
  103. {"name":"active","filterable": false,"title":lang.active},
  104. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  105. ],
  106. "empty": lang.empty,
  107. "rows": $.ajax({
  108. dataType: 'json',
  109. url: '/api/v1/get/mailbox/all',
  110. jsonp: false,
  111. error: function () {
  112. console.log('Cannot draw mailbox table');
  113. },
  114. success: function (data) {
  115. $.each(data, function (i, item) {
  116. item.quota = item.quota_used + "/" + item.quota;
  117. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  118. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + item.username + '" />';
  119. if (role == "admin") {
  120. item.action = '<div class="btn-group">' +
  121. '<a href="/edit.php?mailbox=' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  122. '<a href="/delete.php?mailbox=' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  123. '<a href="/index.php?duallogin=' + encodeURI(item.username) + '" class="btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>' +
  124. '</div>';
  125. }
  126. else {
  127. item.action = '<div class="btn-group">' +
  128. '<a href="/edit.php?mailbox=' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  129. '<a href="/delete.php?mailbox=' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  130. '</div>';
  131. }
  132. item.in_use = '<div class="progress">' +
  133. '<div class="progress-bar progress-bar-' + item.percent_class + ' role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  134. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  135. });
  136. }
  137. }),
  138. "paging": {
  139. "enabled": true,
  140. "limit": 5,
  141. "size": pagination_size
  142. },
  143. "filtering": {
  144. "enabled": true,
  145. "position": "left",
  146. "placeholder": lang.filter_table
  147. },
  148. "sorting": {
  149. "enabled": true
  150. }
  151. });
  152. }
  153. function draw_resource_table() {
  154. ft_resource_table = FooTable.init('#resource_table', {
  155. "columns": [
  156. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  157. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  158. {"name":"kind","title":lang.kind},
  159. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  160. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  161. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  162. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  163. ],
  164. "empty": lang.empty,
  165. "rows": $.ajax({
  166. dataType: 'json',
  167. url: '/api/v1/get/resource/all',
  168. jsonp: false,
  169. error: function () {
  170. console.log('Cannot draw resource table');
  171. },
  172. success: function (data) {
  173. $.each(data, function (i, item) {
  174. item.action = '<div class="btn-group">' +
  175. '<a href="/edit.php?resource=' + encodeURI(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  176. '<a href="/delete.php?resource=' + encodeURI(item.name) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  177. '</div>';
  178. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + item.name + '" />';
  179. });
  180. }
  181. }),
  182. "paging": {
  183. "enabled": true,
  184. "limit": 5,
  185. "size": pagination_size
  186. },
  187. "filtering": {
  188. "enabled": true,
  189. "position": "left",
  190. "placeholder": lang.filter_table
  191. },
  192. "sorting": {
  193. "enabled": true
  194. }
  195. });
  196. }
  197. function draw_alias_table() {
  198. ft_alias_table = FooTable.init('#alias_table', {
  199. "columns": [
  200. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  201. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  202. {"name":"goto","title":lang.target_address},
  203. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  204. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  205. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  206. ],
  207. "empty": lang.empty,
  208. "rows": $.ajax({
  209. dataType: 'json',
  210. url: '/api/v1/get/alias/all',
  211. jsonp: false,
  212. error: function () {
  213. console.log('Cannot draw alias table');
  214. },
  215. success: function (data) {
  216. $.each(data, function (i, item) {
  217. item.action = '<div class="btn-group">' +
  218. '<a href="/edit.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  219. '<a href="/delete.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-pencil"></span> ' + lang.remove + '</a>' +
  220. '</div>';
  221. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + item.address + '" />';
  222. if (item.is_catch_all == 1) {
  223. item.address = '<div class="label label-default">Catch-All</div> ' + item.address;
  224. }
  225. if (item.in_primary_domain !== "") {
  226. item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
  227. }
  228. });
  229. }
  230. }),
  231. "paging": {
  232. "enabled": true,
  233. "limit": 5,
  234. "size": pagination_size
  235. },
  236. "filtering": {
  237. "enabled": true,
  238. "position": "left",
  239. "placeholder": lang.filter_table
  240. },
  241. "sorting": {
  242. "enabled": true
  243. }
  244. });
  245. }
  246. function draw_aliasdomain_table() {
  247. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  248. "columns": [
  249. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  250. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  251. {"name":"target_domain","title":lang.target_domain},
  252. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  253. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  254. ],
  255. "empty": lang.empty,
  256. "rows": $.ajax({
  257. dataType: 'json',
  258. url: '/api/v1/get/alias-domain/all',
  259. jsonp: false,
  260. error: function () {
  261. console.log('Cannot draw alias domain table');
  262. },
  263. success: function (data) {
  264. $.each(data, function (i, item) {
  265. item.action = '<div class="btn-group">' +
  266. '<a href="/edit.php?aliasdomain=' + encodeURI(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  267. '<a href="/delete.php?aliasdomain=' + encodeURI(item.alias_domain) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  268. '</div>';
  269. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + item.alias_domain + '" />';
  270. });
  271. }
  272. }),
  273. "paging": {
  274. "enabled": true,
  275. "limit": 5,
  276. "size": pagination_size
  277. },
  278. "filtering": {
  279. "enabled": true,
  280. "position": "left",
  281. "placeholder": lang.filter_table
  282. },
  283. "sorting": {
  284. "enabled": true
  285. }
  286. });
  287. }
  288. draw_domain_table();
  289. draw_mailbox_table();
  290. draw_resource_table();
  291. draw_alias_table();
  292. draw_aliasdomain_table();
  293. });