mailbox.js 28 KB

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