mailbox.js 46 KB

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