mailbox.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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. "connectors": false,
  188. "placeholder": lang.filter_table
  189. },
  190. "sorting": {
  191. "enabled": true
  192. }
  193. });
  194. }
  195. function draw_mailbox_table() {
  196. ft_mailbox_table = FooTable.init('#mailbox_table', {
  197. "columns": [
  198. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  199. {"sorted": true,"name":"username","style":{"word-break":"break-all","min-width":"120px"},"title":lang.username},
  200. {"name":"name","title":lang.fname,"style":{"word-break":"break-all","min-width":"120px"},"breakpoints":"xs sm"},
  201. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  202. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  203. res = value.split("/");
  204. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  205. },
  206. "sortValue": function(value){
  207. res = value.split("/");
  208. return res[0];
  209. },
  210. },
  211. {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"xs sm md"},
  212. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use},
  213. {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
  214. {"name":"active","filterable": false,"title":lang.active},
  215. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  216. ],
  217. "empty": lang.empty,
  218. "rows": $.ajax({
  219. dataType: 'json',
  220. url: '/api/v1/get/mailbox/all',
  221. jsonp: false,
  222. error: function () {
  223. console.log('Cannot draw mailbox table');
  224. },
  225. success: function (data) {
  226. $.each(data, function (i, item) {
  227. item.quota = item.quota_used + "/" + item.quota;
  228. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  229. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + item.username + '" />';
  230. if (role == "admin") {
  231. item.action = '<div class="btn-group">' +
  232. '<a href="/edit.php?mailbox=' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  233. '<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>' +
  234. '<a href="/index.php?duallogin=' + encodeURI(item.username) + '" class="btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>' +
  235. '</div>';
  236. }
  237. else {
  238. item.action = '<div class="btn-group">' +
  239. '<a href="/edit.php?mailbox=' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  240. '<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>' +
  241. '</div>';
  242. }
  243. item.in_use = '<div class="progress">' +
  244. '<div class="progress-bar progress-bar-' + item.percent_class + ' role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  245. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  246. });
  247. }
  248. }),
  249. "paging": {
  250. "enabled": true,
  251. "limit": 5,
  252. "size": pagination_size
  253. },
  254. "filtering": {
  255. "enabled": true,
  256. "position": "left",
  257. "connectors": false,
  258. "placeholder": lang.filter_table
  259. },
  260. "sorting": {
  261. "enabled": true
  262. }
  263. });
  264. }
  265. function draw_resource_table() {
  266. ft_resource_table = FooTable.init('#resource_table', {
  267. "columns": [
  268. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  269. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  270. {"name":"kind","title":lang.kind},
  271. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  272. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  273. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  274. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  275. ],
  276. "empty": lang.empty,
  277. "rows": $.ajax({
  278. dataType: 'json',
  279. url: '/api/v1/get/resource/all',
  280. jsonp: false,
  281. error: function () {
  282. console.log('Cannot draw resource table');
  283. },
  284. success: function (data) {
  285. $.each(data, function (i, item) {
  286. item.action = '<div class="btn-group">' +
  287. '<a href="/edit.php?resource=' + encodeURI(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  288. '<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>' +
  289. '</div>';
  290. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + item.name + '" />';
  291. });
  292. }
  293. }),
  294. "paging": {
  295. "enabled": true,
  296. "limit": 5,
  297. "size": pagination_size
  298. },
  299. "filtering": {
  300. "enabled": true,
  301. "position": "left",
  302. "connectors": false,
  303. "placeholder": lang.filter_table
  304. },
  305. "sorting": {
  306. "enabled": true
  307. }
  308. });
  309. }
  310. function draw_bcc_table() {
  311. ft_bcc_table = FooTable.init('#bcc_table', {
  312. "columns": [
  313. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  314. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  315. {"name":"type","title":lang.bcc_type},
  316. {"name":"local_dest","title":lang.bcc_local_dest},
  317. {"name":"bcc_dest","title":lang.bcc_destinations},
  318. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  319. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  320. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  321. ],
  322. "empty": lang.empty,
  323. "rows": $.ajax({
  324. dataType: 'json',
  325. url: '/api/v1/get/bcc/all',
  326. jsonp: false,
  327. error: function () {
  328. console.log('Cannot draw bcc table');
  329. },
  330. success: function (data) {
  331. $.each(data, function (i, item) {
  332. item.action = '<div class="btn-group">' +
  333. '<a href="/edit.php?bcc=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  334. '<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>' +
  335. '</div>';
  336. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  337. if (item.type == 'sender') {
  338. item.type = '<span id="active-script" class="label label-success">Sender</span>';
  339. } else {
  340. item.type = '<span id="inactive-script" class="label label-warning">Recipient</span>';
  341. }
  342. });
  343. }
  344. }),
  345. "paging": {
  346. "enabled": true,
  347. "limit": 5,
  348. "size": pagination_size
  349. },
  350. "filtering": {
  351. "enabled": true,
  352. "position": "left",
  353. "connectors": false,
  354. "placeholder": lang.filter_table
  355. },
  356. "sorting": {
  357. "enabled": true
  358. }
  359. });
  360. }
  361. function draw_alias_table() {
  362. ft_alias_table = FooTable.init('#alias_table', {
  363. "columns": [
  364. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  365. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  366. {"name":"goto","title":lang.target_address},
  367. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  368. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  369. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  370. ],
  371. "empty": lang.empty,
  372. "rows": $.ajax({
  373. dataType: 'json',
  374. url: '/api/v1/get/alias/all',
  375. jsonp: false,
  376. error: function () {
  377. console.log('Cannot draw alias table');
  378. },
  379. success: function (data) {
  380. $.each(data, function (i, item) {
  381. item.action = '<div class="btn-group">' +
  382. '<a href="/edit.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  383. '<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>' +
  384. '</div>';
  385. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + item.address + '" />';
  386. if (item.is_catch_all == 1) {
  387. item.address = '<div class="label label-default">Catch-All</div> ' + item.address;
  388. }
  389. if (item.goto == "null@localhost") {
  390. item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
  391. }
  392. if (item.in_primary_domain !== "") {
  393. item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
  394. }
  395. });
  396. }
  397. }),
  398. "paging": {
  399. "enabled": true,
  400. "limit": 5,
  401. "size": pagination_size
  402. },
  403. "filtering": {
  404. "enabled": true,
  405. "position": "left",
  406. "connectors": false,
  407. "placeholder": lang.filter_table
  408. },
  409. "sorting": {
  410. "enabled": true
  411. }
  412. });
  413. }
  414. function draw_aliasdomain_table() {
  415. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  416. "columns": [
  417. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  418. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  419. {"name":"target_domain","title":lang.target_domain},
  420. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  421. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  422. ],
  423. "empty": lang.empty,
  424. "rows": $.ajax({
  425. dataType: 'json',
  426. url: '/api/v1/get/alias-domain/all',
  427. jsonp: false,
  428. error: function () {
  429. console.log('Cannot draw alias domain table');
  430. },
  431. success: function (data) {
  432. $.each(data, function (i, item) {
  433. item.action = '<div class="btn-group">' +
  434. '<a href="/edit.php?aliasdomain=' + encodeURI(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  435. '<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>' +
  436. '</div>';
  437. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + item.alias_domain + '" />';
  438. });
  439. }
  440. }),
  441. "paging": {
  442. "enabled": true,
  443. "limit": 5,
  444. "size": pagination_size
  445. },
  446. "filtering": {
  447. "enabled": true,
  448. "position": "left",
  449. "connectors": false,
  450. "placeholder": lang.filter_table
  451. },
  452. "sorting": {
  453. "enabled": true
  454. }
  455. });
  456. }
  457. function draw_sync_job_table() {
  458. ft_syncjob_table = FooTable.init('#sync_job_table', {
  459. "columns": [
  460. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  461. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  462. {"name":"user2","title":lang.owner},
  463. {"name":"server_w_port","title":"Server","breakpoints":"xs"},
  464. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  465. {"name":"last_run","title":lang.last_run,"breakpoints":"all"},
  466. {"name":"log","title":"Log"},
  467. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active},
  468. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  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/syncjobs/all/no_log',
  475. jsonp: false,
  476. error: function () {
  477. console.log('Cannot draw sync job table');
  478. },
  479. success: function (data) {
  480. $.each(data, function (i, item) {
  481. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURI(item.id) + '">Open logs</a>'
  482. item.exclude = '<code>' + item.exclude + '</code>'
  483. item.server_w_port = item.user1 + '@' + item.host1 + ':' + item.port1;
  484. item.action = '<div class="btn-group">' +
  485. '<a href="/edit.php?syncjob=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  486. '<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>' +
  487. '</div>';
  488. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  489. if (item.is_running == 1) {
  490. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  491. } else {
  492. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  493. }
  494. if (!item.last_run > 0) {
  495. item.last_run = lang.waiting;
  496. }
  497. });
  498. }
  499. }),
  500. "paging": {
  501. "enabled": true,
  502. "limit": 5,
  503. "size": pagination_size
  504. },
  505. "filtering": {
  506. "enabled": true,
  507. "position": "left",
  508. "connectors": false,
  509. "placeholder": lang.filter_table
  510. },
  511. "sorting": {
  512. "enabled": true
  513. }
  514. });
  515. }
  516. function draw_filter_table() {
  517. ft_filter_table = FooTable.init('#filter_table', {
  518. "columns": [
  519. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  520. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  521. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  522. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  523. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  524. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  525. {"name":"script_data","title":"Script","breakpoints":"all"},
  526. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  527. ],
  528. "empty": lang.empty,
  529. "rows": $.ajax({
  530. dataType: 'json',
  531. url: '/api/v1/get/filters/all',
  532. jsonp: false,
  533. error: function () {
  534. console.log('Cannot draw filter table');
  535. },
  536. success: function (data) {
  537. $.each(data, function (i, item) {
  538. if (item.active_int == 1) {
  539. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  540. } else {
  541. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  542. }
  543. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  544. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  545. item.action = '<div class="btn-group">' +
  546. '<a href="/edit.php?filter=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  547. '<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>' +
  548. '</div>';
  549. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  550. });
  551. }
  552. }),
  553. "paging": {
  554. "enabled": true,
  555. "limit": 5,
  556. "size": pagination_size
  557. },
  558. "filtering": {
  559. "enabled": true,
  560. "position": "left",
  561. "connectors": false,
  562. "placeholder": lang.filter_table
  563. },
  564. "sorting": {
  565. "enabled": true
  566. }
  567. });
  568. };
  569. draw_domain_table();
  570. draw_mailbox_table();
  571. draw_resource_table();
  572. draw_alias_table();
  573. draw_aliasdomain_table();
  574. draw_sync_job_table();
  575. draw_filter_table();
  576. draw_bcc_table();
  577. });