mailbox.js 46 KB

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