2
0

mailbox.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  1. $(document).ready(function() {
  2. acl_data = JSON.parse(acl);
  3. FooTable.domainFilter = FooTable.Filtering.extend({
  4. construct: function(instance){
  5. this._super(instance);
  6. var domain_list = [];
  7. $.ajax({
  8. dataType: 'json',
  9. url: '/api/v1/get/domain/all',
  10. jsonp: false,
  11. async: true,
  12. error: function () {
  13. domain_list.push('Cannot read domain list');
  14. },
  15. success: function (data) {
  16. $.each(data, function (i, item) {
  17. domain_list.push(item.domain_name);
  18. });
  19. }
  20. });
  21. this.domains = domain_list;
  22. this.def = 'All Domains';
  23. this.$domain = null;
  24. },
  25. $create: function(){
  26. this._super();
  27. var self = this,
  28. $form_grp = $('<div/>', {'class': 'form-group'})
  29. .append($('<label/>', {'class': 'sr-only', text: 'Domain'}))
  30. .prependTo(self.$form);
  31. self.$domain = $('<select/>', { 'class': 'aform-control' })
  32. .on('change', {self: self}, self._onDomainDropdownChanged)
  33. .append($('<option/>', {text: self.def}))
  34. .appendTo($form_grp);
  35. $.each(self.domains, function(i, domain){
  36. self.$domain.append($('<option/>').text(domain));
  37. });
  38. },
  39. _onDomainDropdownChanged: function(e){
  40. var self = e.data.self,
  41. selected = $(this).val();
  42. if (selected !== self.def){
  43. self.addFilter('domain', selected, ['domain']);
  44. } else {
  45. self.removeFilter('domain');
  46. }
  47. self.filter();
  48. },
  49. draw: function(){
  50. this._super();
  51. var domain = this.find('domain');
  52. if (domain instanceof FooTable.Filter){
  53. this.$domain.val(domain.query.val());
  54. } else {
  55. this.$domain.val(this.def);
  56. }
  57. $(this.$domain).closest("select").selectpicker();
  58. }
  59. });
  60. // Auto-fill domain quota when adding new domain
  61. auto_fill_quota = function(domain) {
  62. $.get("/api/v1/get/domain/" + domain, function(data){
  63. var result = $.parseJSON(JSON.stringify(data));
  64. max_new_mailbox_quota = ( result.max_new_mailbox_quota / 1048576);
  65. if (max_new_mailbox_quota != '0') {
  66. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  67. $('#addInputQuota').attr({"disabled": false, "value": "", "type": "number", "max": max_new_mailbox_quota});
  68. $('#addInputQuota').val(max_new_mailbox_quota);
  69. }
  70. else {
  71. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  72. $('#addInputQuota').attr({"disabled": true, "value": "", "type": "text", "value": "n/a"});
  73. $('#addInputQuota').val(max_new_mailbox_quota);
  74. }
  75. });
  76. }
  77. $('#addSelectDomain').on('change', function() {
  78. auto_fill_quota($('#addSelectDomain').val());
  79. });
  80. auto_fill_quota($('#addSelectDomain').val());
  81. $(".generate_password").click(function( event ) {
  82. event.preventDefault();
  83. $('[data-hibp]').trigger('input');
  84. var random_passwd = Math.random().toString(36).slice(-8)
  85. $(this).closest("form").find("input[name='password']").prop('type', 'text');
  86. $(this).closest("form").find("input[name='password2']").prop('type', 'text');
  87. $(this).closest("form").find("input[name='password']").val(random_passwd);
  88. $(this).closest("form").find("input[name='password2']").val(random_passwd);
  89. });
  90. $(".goto_checkbox").click(function( event ) {
  91. $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false);
  92. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  93. $('#textarea_alias_goto').prop('disabled', true);
  94. }
  95. else {
  96. $("#textarea_alias_goto").removeAttr('disabled');
  97. }
  98. });
  99. $('#addAliasModal').on('show.bs.modal', function(e) {
  100. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  101. $('#textarea_alias_goto').prop('disabled', true);
  102. }
  103. else {
  104. $("#textarea_alias_goto").removeAttr('disabled');
  105. }
  106. });
  107. // Log modal
  108. $('#syncjobLogModal').on('show.bs.modal', function(e) {
  109. var syncjob_id = $(e.relatedTarget).data('syncjob-id');
  110. $.ajax({
  111. url: '/inc/ajax/syncjob_logs.php',
  112. data: { id: syncjob_id },
  113. dataType: 'text',
  114. success: function(data){
  115. $(e.currentTarget).find('#logText').text(data);
  116. },
  117. error: function(xhr, status, error) {
  118. $(e.currentTarget).find('#logText').text(xhr.responseText);
  119. }
  120. });
  121. });
  122. // Log modal
  123. $('#dnsInfoModal').on('show.bs.modal', function(e) {
  124. var domain = $(e.relatedTarget).data('domain');
  125. $('.dns-modal-body').html('<center><span style="font-size:18pt;margin:50px" class="glyphicon glyphicon-refresh glyphicon-spin"></span></center>');
  126. $.ajax({
  127. url: '/inc/ajax/dns_diagnostics.php',
  128. data: { domain: domain },
  129. dataType: 'text',
  130. success: function(data){
  131. $('.dns-modal-body').html(data);
  132. },
  133. error: function(xhr, status, error) {
  134. $('.dns-modal-body').html(xhr.responseText);
  135. }
  136. });
  137. });
  138. // Sieve data modal
  139. $('#sieveDataModal').on('show.bs.modal', function(e) {
  140. var sieveScript = $(e.relatedTarget).data('sieve-script');
  141. $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
  142. });
  143. // Disable submit button on script change
  144. $('#script_data').on('keyup', function() {
  145. $('#add_filter_btns > #add_sieve_script').attr({"disabled": true});
  146. $('#validation_msg').html('-');
  147. });
  148. // Validate script data
  149. $("#validate_sieve").click(function( event ) {
  150. event.preventDefault();
  151. var script = $('#script_data').val();
  152. $.ajax({
  153. dataType: 'jsonp',
  154. url: "/inc/ajax/sieve_validation.php",
  155. type: "get",
  156. data: { script: script },
  157. complete: function(data) {
  158. var response = (data.responseText);
  159. response_obj = JSON.parse(response);
  160. if (response_obj.type == "success") {
  161. $('#add_filter_btns > #add_sieve_script').attr({"disabled": false});
  162. }
  163. mailcow_alert_box(response_obj.msg, response_obj.type);
  164. },
  165. });
  166. });
  167. // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
  168. // $("#active-script").closest('td').css('background-color','#b0f0a0');
  169. // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
  170. // });
  171. $('#addResourceModal').on('shown.bs.modal', function() {
  172. $("#multiple_bookings").val($("#multiple_bookings_select").val());
  173. if ($("#multiple_bookings").val() == "custom") {
  174. $("#multiple_bookings_custom_div").show();
  175. $("#multiple_bookings").val($("#multiple_bookings_custom").val());
  176. }
  177. })
  178. $("#multiple_bookings_select").change(function() {
  179. $("#multiple_bookings").val($("#multiple_bookings_select").val());
  180. if ($("#multiple_bookings").val() == "custom") {
  181. $("#multiple_bookings_custom_div").show();
  182. }
  183. else {
  184. $("#multiple_bookings_custom_div").hide();
  185. }
  186. });
  187. $("#multiple_bookings_custom").bind ("change keypress keyup blur", function () {
  188. $("#multiple_bookings").val($("#multiple_bookings_custom").val());
  189. });
  190. });
  191. jQuery(function($){
  192. // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
  193. var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};
  194. function escapeHtml(n){return String(n).replace(/[&<>"'`=\/]/g,function(n){return entityMap[n]})}
  195. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  196. function validateEmail(email) {
  197. 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,}))$/;
  198. return re.test(email);
  199. }
  200. function humanFileSize(i){if(Math.abs(i)<1024)return i+" B";var B=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],e=-1;do{i/=1024,++e}while(Math.abs(i)>=1024&&e<B.length-1);return i.toFixed(1)+" "+B[e]}
  201. $(".refresh_table").on('click', function(e) {
  202. e.preventDefault();
  203. var table_name = $(this).data('table');
  204. $('#' + table_name).find("tr.footable-empty").remove();
  205. draw_table = $(this).data('draw');
  206. eval(draw_table + '()');
  207. });
  208. function table_mailbox_ready(ft, name) {
  209. if(is_dual) {
  210. $('.login_as').data("toggle", "tooltip")
  211. .attr("disabled", true)
  212. .removeAttr("href")
  213. .attr("title", "Dual login cannot be used twice")
  214. .tooltip();
  215. }
  216. heading = ft.$el.parents('.tab-pane').find('.panel-heading')
  217. var ft_paging = ft.use(FooTable.Paging)
  218. $(heading).children('.table-lines').text(function(){
  219. return ft_paging.totalRows;
  220. })
  221. }
  222. function draw_domain_table() {
  223. ft_domain_table = FooTable.init('#domain_table', {
  224. "columns": [
  225. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  226. {"sorted": true,"name":"domain_name","title":lang.domain,"style":{"width":"250px"}},
  227. {"name":"aliases","title":lang.aliases,"breakpoints":"xs sm"},
  228. {"name":"mailboxes","title":lang.mailboxes},
  229. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  230. res = value.split("/");
  231. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  232. },
  233. "sortValue": function(value){
  234. res = value.split("/");
  235. return Number(res[0]);
  236. },
  237. },
  238. {"name":"max_quota_for_mbox","title":lang.mailbox_quota,"breakpoints":"xs sm","style":{"width":"125px"}},
  239. {"name":"rl","title":"RL","breakpoints":"xs sm md","style":{"maxWidth":"100px","width":"100px"}},
  240. {"name":"backupmx","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.backup_mx,"breakpoints":"xs sm md"},
  241. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  242. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"240px","width":"240px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  243. ],
  244. "rows": $.ajax({
  245. dataType: 'json',
  246. url: '/api/v1/get/domain/all',
  247. jsonp: false,
  248. error: function (data) {
  249. console.log('Cannot draw domain table');
  250. },
  251. success: function (data) {
  252. $.each(data, function (i, item) {
  253. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  254. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  255. item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain;
  256. if (!item.rl) {
  257. item.rl = '∞';
  258. } else {
  259. item.rl = $.map(item.rl, function(e){
  260. return e;
  261. }).join('/1');
  262. }
  263. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  264. item.chkbox = '<input type="checkbox" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
  265. item.action = '<div class="btn-group">';
  266. if (role == "admin") {
  267. item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  268. '<a href="#" data-action="delete_selected" data-id="single-domain" data-api-url="delete/domain" data-item="' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>';
  269. }
  270. else {
  271. item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>';
  272. }
  273. item.action += '<a href="#dnsInfoModal" class="btn btn-xs btn-info" data-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><span class="glyphicon glyphicon-question-sign"></span> DNS</a></div>';
  274. });
  275. }
  276. }),
  277. "empty": lang.empty,
  278. "paging": {
  279. "enabled": true,
  280. "limit": 5,
  281. "size": pagination_size
  282. },
  283. "state": {
  284. "enabled": true
  285. },
  286. "filtering": {
  287. "enabled": true,
  288. "delay": 100,
  289. "position": "left",
  290. "connectors": false,
  291. "placeholder": lang.filter_table
  292. },
  293. "sorting": {
  294. "enabled": true
  295. },
  296. "on": {
  297. "ready.ft.table": function(e, ft){
  298. table_mailbox_ready(ft, 'domain_table');
  299. }
  300. }
  301. });
  302. }
  303. function draw_mailbox_table() {
  304. ft_mailbox_table = FooTable.init('#mailbox_table', {
  305. "columns": [
  306. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  307. {"sorted": true,"name":"username","style":{"word-break":"break-all","min-width":"120px"},"title":lang.username},
  308. {"name":"name","title":lang.fname,"style":{"word-break":"break-all","min-width":"120px"},"breakpoints":"xs sm"},
  309. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  310. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  311. res = value.split("/");
  312. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  313. },
  314. "sortValue": function(value){
  315. res = value.split("/");
  316. return Number(res[0]);
  317. },
  318. },
  319. {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"xs sm md"},
  320. {"name":"tls_enforce_in","filterable": false,"title":lang.tls_enforce_in,"breakpoints":"all"},
  321. {"name":"tls_enforce_out","filterable": false,"title":lang.tls_enforce_out,"breakpoints":"all"},
  322. {"name":"quarantine_notification","filterable": false,"title":lang.quarantine_notification,"breakpoints":"all"},
  323. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use,"sortValue": function(value){
  324. return Number($(value).find(".progress-bar").attr('aria-valuenow'));
  325. },
  326. },
  327. {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
  328. {"name":"rl","title":"RL","breakpoints":"xs sm md","style":{"width":"125px"}},
  329. {"name":"active","filterable": false,"title":lang.active},
  330. {"name":"action","filterable": false,"sortable": false,"style":{"min-width":"290px","text-align":"right"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  331. ],
  332. "empty": lang.empty,
  333. "rows": $.ajax({
  334. dataType: 'json',
  335. url: '/api/v1/get/mailbox/all',
  336. jsonp: false,
  337. error: function () {
  338. console.log('Cannot draw mailbox table');
  339. },
  340. success: function (data) {
  341. $.each(data, function (i, item) {
  342. item.quota = item.quota_used + "/" + item.quota;
  343. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  344. if (!item.rl) {
  345. item.rl = '∞';
  346. } else {
  347. item.rl = $.map(item.rl, function(e){
  348. return e;
  349. }).join('/1');
  350. }
  351. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  352. item.tls_enforce_in = '<span class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success' : 'danger') + ' glyphicon glyphicon-lock"></span>';
  353. item.tls_enforce_out = '<span class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success' : 'danger') + ' glyphicon glyphicon-lock"></span>';
  354. if (item.attributes.quarantine_notification === 'never') {
  355. item.quarantine_notification = lang.never;
  356. } else if (item.attributes.quarantine_notification === 'hourly') {
  357. item.quarantine_notification = lang.hourly;
  358. } else if (item.attributes.quarantine_notification === 'daily') {
  359. item.quarantine_notification = lang.daily;
  360. } else if (item.attributes.quarantine_notification === 'weekly') {
  361. item.quarantine_notification = lang.weekly;
  362. }
  363. if (acl_data.login_as === 1) {
  364. item.action = '<div class="btn-group">' +
  365. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  366. '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  367. '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="login_as btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>';
  368. if (ALLOW_ADMIN_EMAIL_LOGIN) {
  369. item.action += '<a href="/sogo-auth.php?login=' + encodeURIComponent(item.username) + '" class="login_as btn btn-xs btn-primary" target="_blank"><span class="glyphicon glyphicon-envelope"></span> SOGo</a>';
  370. }
  371. item.action += '</div>';
  372. }
  373. else {
  374. item.action = '<div class="btn-group">' +
  375. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  376. '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  377. '</div>';
  378. }
  379. item.in_use = '<div class="progress">' +
  380. '<div class="progress-bar progress-bar-' + item.percent_class + ' role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  381. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  382. item.username = escapeHtml(item.username);
  383. });
  384. }
  385. }),
  386. "paging": {
  387. "enabled": true,
  388. "limit": 5,
  389. "size": pagination_size
  390. },
  391. "state": {
  392. "enabled": true
  393. },
  394. "filtering": {
  395. "enabled": true,
  396. "delay": 100,
  397. "position": "left",
  398. "connectors": false,
  399. //"container": "#tab-mailboxes.panel",
  400. "placeholder": lang.filter_table
  401. },
  402. "components": {
  403. "filtering": FooTable.domainFilter
  404. },
  405. "sorting": {
  406. "enabled": true
  407. },
  408. "on": {
  409. "ready.ft.table": function(e, ft){
  410. table_mailbox_ready(ft, 'mailbox_table');
  411. }
  412. }
  413. });
  414. }
  415. function draw_resource_table() {
  416. ft_resource_table = FooTable.init('#resource_table', {
  417. "columns": [
  418. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  419. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  420. {"name":"kind","title":lang.kind},
  421. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  422. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"150px","width":"140px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  423. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  424. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  425. ],
  426. "empty": lang.empty,
  427. "rows": $.ajax({
  428. dataType: 'json',
  429. url: '/api/v1/get/resource/all',
  430. jsonp: false,
  431. error: function () {
  432. console.log('Cannot draw resource table');
  433. },
  434. success: function (data) {
  435. $.each(data, function (i, item) {
  436. if (item.multiple_bookings == '0') {
  437. item.multiple_bookings = '<span id="active-script" class="label label-success">' + lang.booking_0_short + '</span>';
  438. } else if (item.multiple_bookings == '-1') {
  439. item.multiple_bookings = '<span id="active-script" class="label label-warning">' + lang.booking_lt0_short + '</span>';
  440. } else {
  441. item.multiple_bookings = '<span id="active-script" class="label label-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  442. }
  443. item.action = '<div class="btn-group">' +
  444. '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  445. '<a href="#" data-action="delete_selected" data-id="single-resource" data-api-url="delete/resource" data-item="' + item.name + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  446. '</div>';
  447. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  448. item.name = escapeHtml(item.name);
  449. });
  450. }
  451. }),
  452. "paging": {
  453. "enabled": true,
  454. "limit": 5,
  455. "size": pagination_size
  456. },
  457. "state": {
  458. "enabled": true
  459. },
  460. "filtering": {
  461. "enabled": true,
  462. "delay": 100,
  463. "position": "left",
  464. "connectors": false,
  465. "placeholder": lang.filter_table
  466. },
  467. "components": {
  468. "filtering": FooTable.domainFilter
  469. },
  470. "sorting": {
  471. "enabled": true
  472. },
  473. "on": {
  474. "ready.ft.table": function(e, ft){
  475. table_mailbox_ready(ft, 'resource_table');
  476. }
  477. }
  478. });
  479. }
  480. function draw_bcc_table() {
  481. ft_bcc_table = FooTable.init('#bcc_table', {
  482. "columns": [
  483. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  484. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  485. {"name":"type","title":lang.bcc_type},
  486. {"name":"local_dest","title":lang.bcc_local_dest},
  487. {"name":"bcc_dest","title":lang.bcc_destinations},
  488. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  489. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  490. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  491. ],
  492. "empty": lang.empty,
  493. "rows": $.ajax({
  494. dataType: 'json',
  495. url: '/api/v1/get/bcc/all',
  496. jsonp: false,
  497. error: function () {
  498. console.log('Cannot draw bcc table');
  499. },
  500. success: function (data) {
  501. $.each(data, function (i, item) {
  502. item.action = '<div class="btn-group">' +
  503. '<a href="/edit/bcc/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  504. '<a href="#" data-action="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>' +
  505. '</div>';
  506. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  507. item.local_dest = escapeHtml(item.local_dest);
  508. item.bcc_dest = escapeHtml(item.bcc_dest);
  509. if (item.type == 'sender') {
  510. item.type = '<span id="active-script" class="label label-success">Sender</span>';
  511. } else {
  512. item.type = '<span id="inactive-script" class="label label-warning">Recipient</span>';
  513. }
  514. });
  515. }
  516. }),
  517. "paging": {
  518. "enabled": true,
  519. "limit": 5,
  520. "size": pagination_size
  521. },
  522. "state": {
  523. "enabled": true
  524. },
  525. "filtering": {
  526. "enabled": true,
  527. "delay": 100,
  528. "position": "left",
  529. "connectors": false,
  530. "placeholder": lang.filter_table
  531. },
  532. "sorting": {
  533. "enabled": true
  534. },
  535. "on": {
  536. "ready.ft.table": function(e, ft){
  537. table_mailbox_ready(ft, 'bcc_table');
  538. }
  539. }
  540. });
  541. }
  542. function draw_recipient_map_table() {
  543. ft_recipient_map_table = FooTable.init('#recipient_map_table', {
  544. "columns": [
  545. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  546. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  547. {"name":"recipient_map_old","title":lang.recipient_map_old},
  548. {"name":"recipient_map_new","title":lang.recipient_map_new},
  549. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  550. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  551. ],
  552. "empty": lang.empty,
  553. "rows": $.ajax({
  554. dataType: 'json',
  555. url: '/api/v1/get/recipient_map/all',
  556. jsonp: false,
  557. error: function () {
  558. console.log('Cannot draw recipient map table');
  559. },
  560. success: function (data) {
  561. if (role == "admin") {
  562. $.each(data, function (i, item) {
  563. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  564. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  565. item.action = '<div class="btn-group">' +
  566. '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  567. '<a href="#" data-action="delete_selected" data-id="single-recipient_map" data-api-url="delete/recipient_map" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  568. '</div>';
  569. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  570. });
  571. }
  572. }
  573. }),
  574. "paging": {
  575. "enabled": true,
  576. "limit": 5,
  577. "size": pagination_size
  578. },
  579. "state": {
  580. "enabled": true
  581. },
  582. "filtering": {
  583. "enabled": true,
  584. "delay": 100,
  585. "position": "left",
  586. "connectors": false,
  587. "placeholder": lang.filter_table
  588. },
  589. "sorting": {
  590. "enabled": true
  591. },
  592. "on": {
  593. "ready.ft.table": function(e, ft){
  594. table_mailbox_ready(ft, 'recipient_map_table');
  595. }
  596. }
  597. });
  598. }
  599. function draw_tls_policy_table() {
  600. ft_tls_policy_table = FooTable.init('#tls_policy_table', {
  601. "columns": [
  602. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  603. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  604. {"name":"dest","title":lang.tls_map_dest},
  605. {"name":"policy","title":lang.tls_map_policy},
  606. {"name":"parameters","title":lang.tls_map_parameters},
  607. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  608. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  609. ],
  610. "empty": lang.empty,
  611. "rows": $.ajax({
  612. dataType: 'json',
  613. url: '/api/v1/get/tls-policy-map/all',
  614. jsonp: false,
  615. error: function () {
  616. console.log('Cannot draw tls policy map table');
  617. },
  618. success: function (data) {
  619. if (role == "admin") {
  620. $.each(data, function (i, item) {
  621. item.dest = escapeHtml(item.dest);
  622. item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
  623. if (item.parameters == '') {
  624. item.parameters = '<code>-</code>';
  625. } else {
  626. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  627. }
  628. item.action = '<div class="btn-group">' +
  629. '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  630. '<a href="#" data-action="delete_selected" data-id="single-tls-policy-map" data-api-url="delete/tls-policy-map" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  631. '</div>';
  632. item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
  633. });
  634. }
  635. }
  636. }),
  637. "paging": {
  638. "enabled": true,
  639. "limit": 5,
  640. "size": pagination_size
  641. },
  642. "state": {
  643. "enabled": true
  644. },
  645. "filtering": {
  646. "enabled": true,
  647. "delay": 100,
  648. "position": "left",
  649. "connectors": false,
  650. "placeholder": lang.filter_table
  651. },
  652. "sorting": {
  653. "enabled": true
  654. },
  655. "on": {
  656. "ready.ft.table": function(e, ft){
  657. table_mailbox_ready(ft, 'tls_policy_table');
  658. }
  659. }
  660. });
  661. }
  662. function draw_transport_maps_table() {
  663. ft_transport_maps_table = FooTable.init('#transport_maps_table', {
  664. "columns": [
  665. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  666. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  667. {"name":"dest","title":lang.tls_map_dest},
  668. {"name":"parameters","title":lang.tls_map_parameters},
  669. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  670. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  671. ],
  672. "empty": lang.empty,
  673. "rows": $.ajax({
  674. dataType: 'json',
  675. url: '/api/v1/get/transport-map/all',
  676. jsonp: false,
  677. error: function () {
  678. console.log('Cannot draw transport map table');
  679. },
  680. success: function (data) {
  681. if (role == "admin") {
  682. $.each(data, function (i, item) {
  683. item.dest = escapeHtml(item.dest);
  684. if (item.parameters == '') {
  685. item.parameters = '<code>-</code>';
  686. } else {
  687. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  688. }
  689. item.action = '<div class="btn-group">' +
  690. '<a href="/edit/transport_map/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  691. '<a href="#" data-action="delete_selected" data-id="single-transport-map" data-api-url="delete/transport-map" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  692. '</div>';
  693. item.chkbox = '<input type="checkbox" data-id="transport-map" name="multi_select" value="' + item.id + '" />';
  694. });
  695. }
  696. }
  697. }),
  698. "paging": {
  699. "enabled": true,
  700. "limit": 5,
  701. "size": pagination_size
  702. },
  703. "state": {
  704. "enabled": true
  705. },
  706. "filtering": {
  707. "enabled": true,
  708. "delay": 100,
  709. "position": "left",
  710. "connectors": false,
  711. "placeholder": lang.filter_table
  712. },
  713. "sorting": {
  714. "enabled": true
  715. },
  716. "on": {
  717. "ready.ft.table": function(e, ft){
  718. table_mailbox_ready(ft, 'transport_maps_table');
  719. }
  720. }
  721. });
  722. }
  723. function draw_alias_table() {
  724. ft_alias_table = FooTable.init('#alias_table', {
  725. "columns": [
  726. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  727. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  728. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  729. {"name":"goto","title":lang.target_address},
  730. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  731. {"name":"public_comment","title":lang.public_comment,"breakpoints":"all"},
  732. {"name":"private_comment","title":lang.private_comment,"breakpoints":"all"},
  733. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  734. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  735. ],
  736. "empty": lang.empty,
  737. "rows": $.ajax({
  738. dataType: 'json',
  739. url: '/api/v1/get/alias/all',
  740. jsonp: false,
  741. error: function () {
  742. console.log('Cannot draw alias table');
  743. },
  744. success: function (data) {
  745. $.each(data, function (i, item) {
  746. item.action = '<div class="btn-group">' +
  747. '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  748. '<a href="#" data-action="delete_selected" data-id="single-alias" data-api-url="delete/alias" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  749. '</div>';
  750. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  751. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  752. if (item.public_comment !== null) {
  753. item.public_comment = escapeHtml(item.public_comment);
  754. }
  755. else {
  756. item.public_comment = '-';
  757. }
  758. if (item.private_comment !== null) {
  759. item.private_comment = escapeHtml(item.private_comment);
  760. }
  761. else {
  762. item.private_comment = '-';
  763. }
  764. if (item.is_catch_all == 1) {
  765. item.address = '<div class="label label-default">Catch-All</div> ' + escapeHtml(item.address);
  766. }
  767. else {
  768. item.address = escapeHtml(item.address);
  769. }
  770. if (item.goto == "null@localhost") {
  771. item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
  772. }
  773. else if (item.goto == "spam@localhost") {
  774. item.goto = '<span class="label label-danger">Learn as spam</span>';
  775. }
  776. else if (item.goto == "ham@localhost") {
  777. item.goto = '<span class="label label-success">Learn as ham</span>';
  778. }
  779. if (item.in_primary_domain !== "") {
  780. item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
  781. }
  782. });
  783. }
  784. }),
  785. "paging": {
  786. "enabled": true,
  787. "limit": 5,
  788. "size": pagination_size
  789. },
  790. "state": {
  791. "enabled": true
  792. },
  793. "filtering": {
  794. "enabled": true,
  795. "delay": 100,
  796. "position": "left",
  797. "connectors": false,
  798. "placeholder": lang.filter_table
  799. },
  800. "components": {
  801. "filtering": FooTable.domainFilter
  802. },
  803. "sorting": {
  804. "enabled": true
  805. },
  806. "on": {
  807. "ready.ft.table": function(e, ft){
  808. table_mailbox_ready(ft, 'alias_table');
  809. }
  810. }
  811. });
  812. }
  813. function draw_aliasdomain_table() {
  814. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  815. "columns": [
  816. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  817. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  818. {"name":"target_domain","title":lang.target_domain},
  819. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  820. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  821. ],
  822. "empty": lang.empty,
  823. "rows": $.ajax({
  824. dataType: 'json',
  825. url: '/api/v1/get/alias-domain/all',
  826. jsonp: false,
  827. error: function () {
  828. console.log('Cannot draw alias domain table');
  829. },
  830. success: function (data) {
  831. $.each(data, function (i, item) {
  832. item.action = '<div class="btn-group">' +
  833. '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  834. '<a href="#" data-action="delete_selected" data-id="single-alias-domain" data-api-url="delete/alias-domain" data-item="' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  835. '<a href="#dnsInfoModal" class="btn btn-xs btn-info" data-toggle="modal" data-domain="' + encodeURIComponent(item.alias_domain) + '"><span class="glyphicon glyphicon-question-sign"></span> DNS</a></div>' +
  836. '</div>';
  837. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  838. });
  839. }
  840. }),
  841. "paging": {
  842. "enabled": true,
  843. "limit": 5,
  844. "size": pagination_size
  845. },
  846. "state": {
  847. "enabled": true
  848. },
  849. "filtering": {
  850. "enabled": true,
  851. "delay": 100,
  852. "position": "left",
  853. "connectors": false,
  854. "placeholder": lang.filter_table
  855. },
  856. "sorting": {
  857. "enabled": true
  858. },
  859. "on": {
  860. "ready.ft.table": function(e, ft){
  861. table_mailbox_ready(ft, 'aliasdomain_table');
  862. }
  863. }
  864. });
  865. }
  866. function draw_sync_job_table() {
  867. ft_syncjob_table = FooTable.init('#sync_job_table', {
  868. "columns": [
  869. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  870. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  871. {"name":"user2","title":lang.owner},
  872. {"name":"server_w_port","title":"Server","breakpoints":"xs","style":{"word-break":"break-all"}},
  873. {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
  874. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  875. {"name":"last_run","title":lang.last_run,"breakpoints":"sm"},
  876. {"name":"log","title":"Log"},
  877. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active},
  878. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  879. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  880. ],
  881. "empty": lang.empty,
  882. "rows": $.ajax({
  883. dataType: 'json',
  884. url: '/api/v1/get/syncjobs/all/no_log',
  885. jsonp: false,
  886. error: function () {
  887. console.log('Cannot draw sync job table');
  888. },
  889. success: function (data) {
  890. $.each(data, function (i, item) {
  891. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">Open logs</a>'
  892. item.user2 = escapeHtml(item.user2);
  893. if (!item.exclude > 0) {
  894. item.exclude = '-';
  895. } else {
  896. item.exclude = '<code>' + item.exclude + '</code>';
  897. }
  898. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  899. item.action = '<div class="btn-group">' +
  900. '<a href="/edit/syncjob/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  901. '<a href="#" data-action="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  902. '</div>';
  903. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  904. if (item.is_running == 1) {
  905. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  906. } else {
  907. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  908. }
  909. if (!item.last_run > 0) {
  910. item.last_run = lang.waiting;
  911. }
  912. });
  913. }
  914. }),
  915. "paging": {
  916. "enabled": true,
  917. "limit": 5,
  918. "size": pagination_size
  919. },
  920. "state": {
  921. "enabled": true
  922. },
  923. "filtering": {
  924. "enabled": true,
  925. "delay": 100,
  926. "position": "left",
  927. "connectors": false,
  928. "placeholder": lang.filter_table
  929. },
  930. "sorting": {
  931. "enabled": true
  932. },
  933. "on": {
  934. "ready.ft.table": function(e, ft){
  935. table_mailbox_ready(ft, 'sync_job_table');
  936. }
  937. }
  938. });
  939. }
  940. function draw_filter_table() {
  941. ft_filter_table = FooTable.init('#filter_table', {
  942. "columns": [
  943. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  944. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  945. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  946. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  947. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  948. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  949. {"name":"script_data","title":"Script","breakpoints":"all"},
  950. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  951. ],
  952. "empty": lang.empty,
  953. "rows": $.ajax({
  954. dataType: 'json',
  955. url: '/api/v1/get/filters/all',
  956. jsonp: false,
  957. error: function () {
  958. console.log('Cannot draw filter table');
  959. },
  960. success: function (data) {
  961. $.each(data, function (i, item) {
  962. if (item.active_int == 1) {
  963. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  964. } else {
  965. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  966. }
  967. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  968. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  969. item.action = '<div class="btn-group">' +
  970. '<a href="/edit/filter/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  971. '<a href="#" data-action="delete_selected" data-id="single-filter" data-api-url="delete/filter" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  972. '</div>';
  973. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  974. });
  975. }
  976. }),
  977. "paging": {
  978. "enabled": true,
  979. "limit": 5,
  980. "size": pagination_size
  981. },
  982. "state": {
  983. "enabled": true
  984. },
  985. "filtering": {
  986. "enabled": true,
  987. "delay": 100,
  988. "position": "left",
  989. "connectors": false,
  990. "placeholder": lang.filter_table
  991. },
  992. "sorting": {
  993. "enabled": true
  994. },
  995. "on": {
  996. "ready.ft.table": function(e, ft){
  997. table_mailbox_ready(ft, 'filter_table');
  998. }
  999. }
  1000. });
  1001. };
  1002. draw_domain_table();
  1003. draw_mailbox_table();
  1004. draw_resource_table();
  1005. draw_alias_table();
  1006. draw_aliasdomain_table();
  1007. draw_sync_job_table();
  1008. draw_filter_table();
  1009. draw_bcc_table();
  1010. draw_recipient_map_table();
  1011. draw_tls_policy_table();
  1012. draw_transport_maps_table();
  1013. });