mailbox.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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_bcc_table() {
  308. ft_bcc_table = FooTable.init('#bcc_table', {
  309. "columns": [
  310. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  311. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  312. {"name":"type","title":lang.bcc_type},
  313. {"name":"local_dest","title":lang.bcc_local_dest},
  314. {"name":"bcc_dest","title":lang.bcc_destinations},
  315. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  316. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  317. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  318. ],
  319. "empty": lang.empty,
  320. "rows": $.ajax({
  321. dataType: 'json',
  322. url: '/api/v1/get/bcc/all',
  323. jsonp: false,
  324. error: function () {
  325. console.log('Cannot draw bcc table');
  326. },
  327. success: function (data) {
  328. $.each(data, function (i, item) {
  329. item.action = '<div class="btn-group">' +
  330. '<a href="/edit.php?bcc=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  331. '<a href="#" id="delete_selected" data-id="single-bcc" data-api-url="delete/bcc" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  332. '</div>';
  333. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  334. if (item.type == 'sender') {
  335. item.type = '<span id="active-script" class="label label-success">Sender</span>';
  336. } else {
  337. item.type = '<span id="inactive-script" class="label label-warning">Recipient</span>';
  338. }
  339. });
  340. }
  341. }),
  342. "paging": {
  343. "enabled": true,
  344. "limit": 5,
  345. "size": pagination_size
  346. },
  347. "filtering": {
  348. "enabled": true,
  349. "position": "left",
  350. "placeholder": lang.filter_table
  351. },
  352. "sorting": {
  353. "enabled": true
  354. }
  355. });
  356. }
  357. function draw_alias_table() {
  358. ft_alias_table = FooTable.init('#alias_table', {
  359. "columns": [
  360. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  361. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  362. {"name":"goto","title":lang.target_address},
  363. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  364. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  365. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  366. ],
  367. "empty": lang.empty,
  368. "rows": $.ajax({
  369. dataType: 'json',
  370. url: '/api/v1/get/alias/all',
  371. jsonp: false,
  372. error: function () {
  373. console.log('Cannot draw alias table');
  374. },
  375. success: function (data) {
  376. $.each(data, function (i, item) {
  377. item.action = '<div class="btn-group">' +
  378. '<a href="/edit.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  379. '<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>' +
  380. '</div>';
  381. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + item.address + '" />';
  382. if (item.is_catch_all == 1) {
  383. item.address = '<div class="label label-default">Catch-All</div> ' + item.address;
  384. }
  385. if (item.goto == "null@localhost") {
  386. item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
  387. }
  388. if (item.in_primary_domain !== "") {
  389. item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
  390. }
  391. });
  392. }
  393. }),
  394. "paging": {
  395. "enabled": true,
  396. "limit": 5,
  397. "size": pagination_size
  398. },
  399. "filtering": {
  400. "enabled": true,
  401. "position": "left",
  402. "placeholder": lang.filter_table
  403. },
  404. "sorting": {
  405. "enabled": true
  406. }
  407. });
  408. }
  409. function draw_aliasdomain_table() {
  410. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  411. "columns": [
  412. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  413. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  414. {"name":"target_domain","title":lang.target_domain},
  415. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  416. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  417. ],
  418. "empty": lang.empty,
  419. "rows": $.ajax({
  420. dataType: 'json',
  421. url: '/api/v1/get/alias-domain/all',
  422. jsonp: false,
  423. error: function () {
  424. console.log('Cannot draw alias domain table');
  425. },
  426. success: function (data) {
  427. $.each(data, function (i, item) {
  428. item.action = '<div class="btn-group">' +
  429. '<a href="/edit.php?aliasdomain=' + encodeURI(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  430. '<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>' +
  431. '</div>';
  432. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + item.alias_domain + '" />';
  433. });
  434. }
  435. }),
  436. "paging": {
  437. "enabled": true,
  438. "limit": 5,
  439. "size": pagination_size
  440. },
  441. "filtering": {
  442. "enabled": true,
  443. "position": "left",
  444. "placeholder": lang.filter_table
  445. },
  446. "sorting": {
  447. "enabled": true
  448. }
  449. });
  450. }
  451. function draw_sync_job_table() {
  452. ft_syncjob_table = FooTable.init('#sync_job_table', {
  453. "columns": [
  454. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  455. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  456. {"name":"user2","title":lang.owner},
  457. {"name":"server_w_port","title":"Server","breakpoints":"xs"},
  458. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  459. {"name":"last_run","title":lang.last_run,"breakpoints":"all"},
  460. {"name":"log","title":"Log"},
  461. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active},
  462. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  463. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  464. ],
  465. "empty": lang.empty,
  466. "rows": $.ajax({
  467. dataType: 'json',
  468. url: '/api/v1/get/syncjobs/all/no_log',
  469. jsonp: false,
  470. error: function () {
  471. console.log('Cannot draw sync job table');
  472. },
  473. success: function (data) {
  474. $.each(data, function (i, item) {
  475. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURI(item.id) + '">Open logs</a>'
  476. item.exclude = '<code>' + item.exclude + '</code>'
  477. item.server_w_port = item.user1 + '@' + item.host1 + ':' + item.port1;
  478. item.action = '<div class="btn-group">' +
  479. '<a href="/edit.php?syncjob=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  480. '<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>' +
  481. '</div>';
  482. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  483. if (item.is_running == 1) {
  484. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  485. } else {
  486. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  487. }
  488. if (!item.last_run > 0) {
  489. item.last_run = lang.waiting;
  490. }
  491. });
  492. }
  493. }),
  494. "paging": {
  495. "enabled": true,
  496. "limit": 5,
  497. "size": pagination_size
  498. },
  499. "filtering": {
  500. "enabled": true,
  501. "position": "left",
  502. "placeholder": lang.filter_table
  503. },
  504. "sorting": {
  505. "enabled": true
  506. }
  507. });
  508. }
  509. function draw_filter_table() {
  510. ft_filter_table = FooTable.init('#filter_table', {
  511. "columns": [
  512. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  513. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  514. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  515. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  516. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  517. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  518. {"name":"script_data","title":"Script","breakpoints":"all"},
  519. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  520. ],
  521. "empty": lang.empty,
  522. "rows": $.ajax({
  523. dataType: 'json',
  524. url: '/api/v1/get/filters/all',
  525. jsonp: false,
  526. error: function () {
  527. console.log('Cannot draw filter table');
  528. },
  529. success: function (data) {
  530. $.each(data, function (i, item) {
  531. if (item.active_int == 1) {
  532. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  533. } else {
  534. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  535. }
  536. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  537. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  538. item.action = '<div class="btn-group">' +
  539. '<a href="/edit.php?filter=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  540. '<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>' +
  541. '</div>';
  542. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  543. });
  544. }
  545. }),
  546. "paging": {
  547. "enabled": true,
  548. "limit": 5,
  549. "size": pagination_size
  550. },
  551. "filtering": {
  552. "enabled": true,
  553. "position": "left",
  554. "placeholder": lang.filter_table
  555. },
  556. "sorting": {
  557. "enabled": true
  558. }
  559. });
  560. };
  561. draw_domain_table();
  562. draw_mailbox_table();
  563. draw_resource_table();
  564. draw_alias_table();
  565. draw_aliasdomain_table();
  566. draw_sync_job_table();
  567. draw_filter_table();
  568. draw_bcc_table();
  569. });