mailbox.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. $(document).ready(function() {
  2. // Auto-fill domain quota when adding new domain
  3. auto_fill_quota = function(domain) {
  4. $.get("/api/v1/get/domain/" + domain, function(data){
  5. var result = $.parseJSON(JSON.stringify(data));
  6. max_new_mailbox_quota = ( result.max_new_mailbox_quota / 1048576);
  7. if (max_new_mailbox_quota != '0') {
  8. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  9. $('#addInputQuota').attr({"disabled": false, "value": "", "type": "number", "max": max_new_mailbox_quota});
  10. $('#addInputQuota').val(max_new_mailbox_quota);
  11. }
  12. else {
  13. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  14. $('#addInputQuota').attr({"disabled": true, "value": "", "type": "text", "value": "n/a"});
  15. $('#addInputQuota').val(max_new_mailbox_quota);
  16. }
  17. });
  18. }
  19. $('#addSelectDomain').on('change', function() {
  20. auto_fill_quota($('#addSelectDomain').val());
  21. });
  22. auto_fill_quota($('#addSelectDomain').val());
  23. $(".generate_password").click(function( event ) {
  24. event.preventDefault();
  25. var random_passwd = Math.random().toString(36).slice(-8)
  26. $('#password').prop('type', 'text');
  27. $('#password').val(random_passwd);
  28. $('#password2').prop('type', 'text');
  29. $('#password2').val(random_passwd);
  30. });
  31. $("#goto_null").click(function( event ) {
  32. if ($("#goto_null").is(":checked")) {
  33. $('#textarea_alias_goto').prop('disabled', true);
  34. }
  35. else {
  36. $("#textarea_alias_goto").removeAttr('disabled');
  37. }
  38. });
  39. // Log modal
  40. $('#syncjobLogModal').on('show.bs.modal', function(e) {
  41. var syncjob_id = $(e.relatedTarget).data('syncjob-id');
  42. $.ajax({
  43. url: '/inc/ajax/syncjob_logs.php',
  44. data: { id: syncjob_id },
  45. dataType: 'text',
  46. success: function(data){
  47. $(e.currentTarget).find('#logText').text(data);
  48. },
  49. error: function(xhr, status, error) {
  50. $(e.currentTarget).find('#logText').text(xhr.responseText);
  51. }
  52. });
  53. });
  54. // Sieve data modal
  55. $('#sieveDataModal').on('show.bs.modal', function(e) {
  56. var sieveScript = $(e.relatedTarget).data('sieve-script');
  57. $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
  58. });
  59. // Set line numbers for textarea
  60. $("#script_data").numberedtextarea({allowTabChar: true});
  61. // Disable submit button on script change
  62. $('#script_data').on('keyup', function() {
  63. $('#add_filter_btns > #add_item').attr({"disabled": true});
  64. $('#validation_msg').html('-');
  65. });
  66. // Validate script data
  67. $("#validate_sieve").click(function( event ) {
  68. event.preventDefault();
  69. var script = $('#script_data').val();
  70. $.ajax({
  71. dataType: 'jsonp',
  72. url: "/inc/ajax/sieve_validation.php",
  73. type: "get",
  74. data: { script: script },
  75. complete: function(data) {
  76. var response = (data.responseText);
  77. response_obj = JSON.parse(response);
  78. if (response_obj.type == "success") {
  79. $('#add_filter_btns > #add_item').attr({"disabled": false});
  80. }
  81. mailcow_alert_box(response_obj.msg, response_obj.type);
  82. },
  83. });
  84. });
  85. // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
  86. // $("#active-script").closest('td').css('background-color','#b0f0a0');
  87. // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
  88. // });
  89. });
  90. jQuery(function($){
  91. // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
  92. var entityMap = {
  93. '&': '&amp;',
  94. '<': '&lt;',
  95. '>': '&gt;',
  96. '"': '&quot;',
  97. "'": '&#39;',
  98. '/': '&#x2F;',
  99. '`': '&#x60;',
  100. '=': '&#x3D;'
  101. };
  102. function escapeHtml(string) {
  103. return String(string).replace(/[&<>"'`=\/]/g, function (s) {
  104. return entityMap[s];
  105. });
  106. }
  107. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  108. function validateEmail(email) {
  109. var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  110. return re.test(email);
  111. }
  112. // Calculation human readable file sizes
  113. function humanFileSize(bytes) {
  114. if(Math.abs(bytes) < 1024) {
  115. return bytes + ' B';
  116. }
  117. var units = ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
  118. var u = -1;
  119. do {
  120. bytes /= 1024;
  121. ++u;
  122. } while(Math.abs(bytes) >= 1024 && u < units.length - 1);
  123. return bytes.toFixed(1)+' '+units[u];
  124. }
  125. function unix_time_format(tm) {
  126. var date = new Date(tm ? tm * 1000 : 0);
  127. return date.toLocaleString();
  128. }
  129. function draw_domain_table() {
  130. ft_domain_table = FooTable.init('#domain_table', {
  131. "columns": [
  132. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  133. {"sorted": true,"name":"domain_name","title":lang.domain,"style":{"width":"250px"}},
  134. {"name":"aliases","title":lang.aliases,"breakpoints":"xs sm"},
  135. {"name":"mailboxes","title":lang.mailboxes},
  136. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  137. res = value.split("/");
  138. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  139. },
  140. "sortValue": function(value){
  141. res = value.split("/");
  142. return res[0];
  143. },
  144. },
  145. {"name":"max_quota_for_mbox","title":lang.mailbox_quota,"breakpoints":"xs sm"},
  146. {"name":"backupmx","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.backup_mx,"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. "rows": $.ajax({
  151. dataType: 'json',
  152. url: '/api/v1/get/domain/all',
  153. jsonp: false,
  154. error: function (data) {
  155. console.log('Cannot draw domain table');
  156. },
  157. success: function (data) {
  158. $.each(data, function (i, item) {
  159. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  160. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  161. item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain;
  162. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  163. item.chkbox = '<input type="checkbox" data-id="domain" name="multi_select" value="' + item.domain_name + '" />';
  164. if (role == "admin") {
  165. item.action = '<div class="btn-group">' +
  166. '<a href="/edit.php?domain=' + encodeURI(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  167. '<a href="#" id="delete_selected" data-id="single-domain" data-api-url="delete/domain" data-item="' + encodeURI(item.domain_name) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  168. '</div>';
  169. }
  170. else {
  171. item.action = '<div class="btn-group">' +
  172. '<a href="/edit.php?domain=' + encodeURI(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  173. '</div>';
  174. }
  175. });
  176. }
  177. }),
  178. "empty": lang.empty,
  179. "paging": {
  180. "enabled": true,
  181. "limit": 5,
  182. "size": pagination_size
  183. },
  184. "filtering": {
  185. "enabled": true,
  186. "position": "left",
  187. "placeholder": lang.filter_table
  188. },
  189. "sorting": {
  190. "enabled": true
  191. }
  192. });
  193. }
  194. function draw_mailbox_table() {
  195. ft_mailbox_table = FooTable.init('#mailbox_table', {
  196. "columns": [
  197. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  198. {"sorted": true,"name":"username","style":{"word-break":"break-all","min-width":"120px"},"title":lang.username},
  199. {"name":"name","title":lang.fname,"style":{"word-break":"break-all","min-width":"120px"},"breakpoints":"xs sm"},
  200. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  201. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  202. res = value.split("/");
  203. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  204. },
  205. "sortValue": function(value){
  206. res = value.split("/");
  207. return res[0];
  208. },
  209. },
  210. {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"xs sm md"},
  211. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use},
  212. {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
  213. {"name":"active","filterable": false,"title":lang.active},
  214. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  215. ],
  216. "empty": lang.empty,
  217. "rows": $.ajax({
  218. dataType: 'json',
  219. url: '/api/v1/get/mailbox/all',
  220. jsonp: false,
  221. error: function () {
  222. console.log('Cannot draw mailbox table');
  223. },
  224. success: function (data) {
  225. $.each(data, function (i, item) {
  226. item.quota = item.quota_used + "/" + item.quota;
  227. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  228. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + item.username + '" />';
  229. if (role == "admin") {
  230. item.action = '<div class="btn-group">' +
  231. '<a href="/edit.php?mailbox=' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  232. '<a href="#" id="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  233. '<a href="/index.php?duallogin=' + encodeURI(item.username) + '" class="btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>' +
  234. '</div>';
  235. }
  236. else {
  237. item.action = '<div class="btn-group">' +
  238. '<a href="/edit.php?mailbox=' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  239. '<a href="#" id="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  240. '</div>';
  241. }
  242. item.in_use = '<div class="progress">' +
  243. '<div class="progress-bar progress-bar-' + item.percent_class + ' role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  244. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  245. });
  246. }
  247. }),
  248. "paging": {
  249. "enabled": true,
  250. "limit": 5,
  251. "size": pagination_size
  252. },
  253. "filtering": {
  254. "enabled": true,
  255. "position": "left",
  256. "placeholder": lang.filter_table
  257. },
  258. "sorting": {
  259. "enabled": true
  260. }
  261. });
  262. }
  263. function draw_resource_table() {
  264. ft_resource_table = FooTable.init('#resource_table', {
  265. "columns": [
  266. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  267. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  268. {"name":"kind","title":lang.kind},
  269. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  270. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  271. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  272. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  273. ],
  274. "empty": lang.empty,
  275. "rows": $.ajax({
  276. dataType: 'json',
  277. url: '/api/v1/get/resource/all',
  278. jsonp: false,
  279. error: function () {
  280. console.log('Cannot draw resource table');
  281. },
  282. success: function (data) {
  283. $.each(data, function (i, item) {
  284. item.action = '<div class="btn-group">' +
  285. '<a href="/edit.php?resource=' + encodeURI(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  286. '<a href="#" id="delete_selected" data-id="single-resource" data-api-url="delete/resource" data-item="' + encodeURI(item.name) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  287. '</div>';
  288. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + item.name + '" />';
  289. });
  290. }
  291. }),
  292. "paging": {
  293. "enabled": true,
  294. "limit": 5,
  295. "size": pagination_size
  296. },
  297. "filtering": {
  298. "enabled": true,
  299. "position": "left",
  300. "placeholder": lang.filter_table
  301. },
  302. "sorting": {
  303. "enabled": true
  304. }
  305. });
  306. }
  307. function draw_alias_table() {
  308. ft_alias_table = FooTable.init('#alias_table', {
  309. "columns": [
  310. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  311. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  312. {"name":"goto","title":lang.target_address},
  313. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  314. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  315. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  316. ],
  317. "empty": lang.empty,
  318. "rows": $.ajax({
  319. dataType: 'json',
  320. url: '/api/v1/get/alias/all',
  321. jsonp: false,
  322. error: function () {
  323. console.log('Cannot draw alias table');
  324. },
  325. success: function (data) {
  326. $.each(data, function (i, item) {
  327. item.action = '<div class="btn-group">' +
  328. '<a href="/edit.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  329. '<a href="#" id="delete_selected" data-id="single-alias" data-api-url="delete/alias" data-item="' + encodeURI(item.address) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  330. '</div>';
  331. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + item.address + '" />';
  332. if (item.is_catch_all == 1) {
  333. item.address = '<div class="label label-default">Catch-All</div> ' + item.address;
  334. }
  335. if (item.goto == "null@localhost") {
  336. item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
  337. }
  338. if (item.in_primary_domain !== "") {
  339. item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
  340. }
  341. });
  342. }
  343. }),
  344. "paging": {
  345. "enabled": true,
  346. "limit": 5,
  347. "size": pagination_size
  348. },
  349. "filtering": {
  350. "enabled": true,
  351. "position": "left",
  352. "placeholder": lang.filter_table
  353. },
  354. "sorting": {
  355. "enabled": true
  356. }
  357. });
  358. }
  359. function draw_aliasdomain_table() {
  360. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  361. "columns": [
  362. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  363. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  364. {"name":"target_domain","title":lang.target_domain},
  365. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  366. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  367. ],
  368. "empty": lang.empty,
  369. "rows": $.ajax({
  370. dataType: 'json',
  371. url: '/api/v1/get/alias-domain/all',
  372. jsonp: false,
  373. error: function () {
  374. console.log('Cannot draw alias domain table');
  375. },
  376. success: function (data) {
  377. $.each(data, function (i, item) {
  378. item.action = '<div class="btn-group">' +
  379. '<a href="/edit.php?aliasdomain=' + encodeURI(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  380. '<a href="#" id="delete_selected" data-id="single-alias-domain" data-api-url="delete/alias-domain" data-item="' + encodeURI(item.alias_domain) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  381. '</div>';
  382. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + item.alias_domain + '" />';
  383. });
  384. }
  385. }),
  386. "paging": {
  387. "enabled": true,
  388. "limit": 5,
  389. "size": pagination_size
  390. },
  391. "filtering": {
  392. "enabled": true,
  393. "position": "left",
  394. "placeholder": lang.filter_table
  395. },
  396. "sorting": {
  397. "enabled": true
  398. }
  399. });
  400. }
  401. function draw_sync_job_table() {
  402. ft_syncjob_table = FooTable.init('#sync_job_table', {
  403. "columns": [
  404. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  405. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  406. {"name":"user2","title":lang.owner},
  407. {"name":"server_w_port","title":"Server","breakpoints":"xs"},
  408. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  409. {"name":"last_run","title":lang.last_run,"breakpoints":"all"},
  410. {"name":"log","title":"Log"},
  411. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active},
  412. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  413. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  414. ],
  415. "empty": lang.empty,
  416. "rows": $.ajax({
  417. dataType: 'json',
  418. url: '/api/v1/get/syncjobs/all/no_log',
  419. jsonp: false,
  420. error: function () {
  421. console.log('Cannot draw sync job table');
  422. },
  423. success: function (data) {
  424. $.each(data, function (i, item) {
  425. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURI(item.id) + '">Open logs</a>'
  426. item.exclude = '<code>' + item.exclude + '</code>'
  427. item.server_w_port = item.user1 + '@' + item.host1 + ':' + item.port1;
  428. item.action = '<div class="btn-group">' +
  429. '<a href="/edit.php?syncjob=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  430. '<a href="#" id="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  431. '</div>';
  432. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  433. if (item.is_running == 1) {
  434. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  435. } else {
  436. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  437. }
  438. if (!item.last_run > 0) {
  439. item.last_run = lang.waiting;
  440. }
  441. });
  442. }
  443. }),
  444. "paging": {
  445. "enabled": true,
  446. "limit": 5,
  447. "size": pagination_size
  448. },
  449. "filtering": {
  450. "enabled": true,
  451. "position": "left",
  452. "placeholder": lang.filter_table
  453. },
  454. "sorting": {
  455. "enabled": true
  456. }
  457. });
  458. }
  459. function draw_filter_table() {
  460. ft_filter_table = FooTable.init('#filter_table', {
  461. "columns": [
  462. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  463. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  464. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  465. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  466. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  467. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  468. {"name":"script_data","title":"Script","breakpoints":"all"},
  469. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  470. ],
  471. "empty": lang.empty,
  472. "rows": $.ajax({
  473. dataType: 'json',
  474. url: '/api/v1/get/filters/all',
  475. jsonp: false,
  476. error: function () {
  477. console.log('Cannot draw filter table');
  478. },
  479. success: function (data) {
  480. $.each(data, function (i, item) {
  481. if (item.active_int == 1) {
  482. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  483. } else {
  484. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  485. }
  486. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  487. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  488. item.action = '<div class="btn-group">' +
  489. '<a href="/edit.php?filter=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  490. '<a href="#" id="delete_selected" data-id="single-filter" data-api-url="delete/filter" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  491. '</div>';
  492. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  493. });
  494. }
  495. }),
  496. "paging": {
  497. "enabled": true,
  498. "limit": 5,
  499. "size": pagination_size
  500. },
  501. "filtering": {
  502. "enabled": true,
  503. "position": "left",
  504. "placeholder": lang.filter_table
  505. },
  506. "sorting": {
  507. "enabled": true
  508. }
  509. });
  510. };
  511. draw_domain_table();
  512. draw_mailbox_table();
  513. draw_resource_table();
  514. draw_alias_table();
  515. draw_aliasdomain_table();
  516. draw_sync_job_table();
  517. draw_filter_table();
  518. });