mailbox.js 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  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 (item.backupmx_int == 1) {
  254. item.domain_name = '<span class="glyphicon glyphicon-export"></span> ' + item.domain_name;
  255. }
  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. });
  265. }
  266. }),
  267. "empty": lang.empty,
  268. "paging": {
  269. "enabled": true,
  270. "limit": 5,
  271. "size": pagination_size
  272. },
  273. "state": {
  274. "enabled": true
  275. },
  276. "filtering": {
  277. "enabled": true,
  278. "delay": 1200,
  279. "position": "left",
  280. "connectors": false,
  281. "placeholder": lang.filter_table
  282. },
  283. "sorting": {
  284. "enabled": true
  285. },
  286. "on": {
  287. "destroy.ft.table": function(e, ft){
  288. $('.refresh_table').attr('disabled', 'true');
  289. },
  290. "ready.ft.table": function(e, ft){
  291. table_mailbox_ready(ft, 'domain_table');
  292. },
  293. "after.ft.filtering": function(e, ft){
  294. table_mailbox_ready(ft, 'domain_table');
  295. }
  296. },
  297. "toggleSelector": "table tbody span.footable-toggle"
  298. });
  299. }
  300. function draw_mailbox_table() {
  301. ft_mailbox_table = FooTable.init('#mailbox_table', {
  302. "columns": [
  303. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  304. {"sorted": true,"name":"username","style":{"word-break":"break-all","min-width":"120px"},"title":lang.username},
  305. {"name":"name","title":lang.fname,"style":{"word-break":"break-all","min-width":"120px"},"breakpoints":"xs sm md lg"},
  306. {"name":"domain","title":lang.domain,"breakpoints":"xs sm md lg"},
  307. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  308. res = value.split("/");
  309. var of_q = (res[1] == 0 ? "∞" : humanFileSize(res[1]));
  310. return humanFileSize(res[0]) + " / " + of_q;
  311. },
  312. "sortValue": function(value){
  313. res = value.split("/");
  314. return Number(res[0]);
  315. },
  316. },
  317. {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"all"},
  318. {"name":"tls_enforce_in","filterable": false,"title":lang.tls_enforce_in,"breakpoints":"all"},
  319. {"name":"tls_enforce_out","filterable": false,"title":lang.tls_enforce_out,"breakpoints":"all"},
  320. {"name":"quarantine_notification","filterable": false,"title":lang.quarantine_notification,"breakpoints":"all"},
  321. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use,"sortValue": function(value){
  322. return Number($(value).find(".progress-bar").attr('aria-valuenow'));
  323. },
  324. },
  325. {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
  326. {"name":"rl","title":"RL","breakpoints":"all","style":{"width":"125px"}},
  327. {"name":"active","filterable": false,"title":lang.active},
  328. {"name":"action","filterable": false,"sortable": false,"style":{"min-width":"290px","text-align":"right"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  329. ],
  330. "empty": lang.empty,
  331. "rows": $.ajax({
  332. dataType: 'json',
  333. url: '/api/v1/get/mailbox/all',
  334. jsonp: false,
  335. error: function () {
  336. console.log('Cannot draw mailbox table');
  337. },
  338. success: function (data) {
  339. $.each(data, function (i, item) {
  340. item.quota = item.quota_used + "/" + item.quota;
  341. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  342. if (!item.rl) {
  343. item.rl = '∞';
  344. } else {
  345. item.rl = $.map(item.rl, function(e){
  346. return e;
  347. }).join('/1');
  348. if (item.rl_scope === 'domain') {
  349. item.rl = '↪ ' + item.rl + ' (via ' + item.domain + ')';
  350. }
  351. }
  352. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  353. item.tls_enforce_in = '<span class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success' : 'danger') + ' glyphicon glyphicon-lock"></span>';
  354. item.tls_enforce_out = '<span class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success' : 'danger') + ' glyphicon glyphicon-lock"></span>';
  355. if (item.attributes.quarantine_notification === 'never') {
  356. item.quarantine_notification = lang.never;
  357. } else if (item.attributes.quarantine_notification === 'hourly') {
  358. item.quarantine_notification = lang.hourly;
  359. } else if (item.attributes.quarantine_notification === 'daily') {
  360. item.quarantine_notification = lang.daily;
  361. } else if (item.attributes.quarantine_notification === 'weekly') {
  362. item.quarantine_notification = lang.weekly;
  363. }
  364. if (acl_data.login_as === 1) {
  365. item.action = '<div class="btn-group">' +
  366. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  367. '<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>' +
  368. '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="login_as btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>';
  369. if (ALLOW_ADMIN_EMAIL_LOGIN) {
  370. 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>';
  371. }
  372. item.action += '</div>';
  373. }
  374. else {
  375. item.action = '<div class="btn-group">' +
  376. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  377. '<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>' +
  378. '</div>';
  379. }
  380. item.in_use = '<div class="progress">' +
  381. '<div class="progress-bar progress-bar-' + item.percent_class + ' role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  382. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  383. item.username = escapeHtml(item.username);
  384. });
  385. }
  386. }),
  387. "paging": {
  388. "enabled": true,
  389. "limit": 5,
  390. "size": pagination_size
  391. },
  392. "state": {
  393. "enabled": true
  394. },
  395. "filtering": {
  396. "enabled": true,
  397. "delay": 1200,
  398. "position": "left",
  399. "connectors": false,
  400. //"container": "#tab-mailboxes.panel",
  401. "placeholder": lang.filter_table
  402. },
  403. "components": {
  404. "filtering": FooTable.domainFilter
  405. },
  406. "sorting": {
  407. "enabled": true
  408. },
  409. "on": {
  410. "destroy.ft.table": function(e, ft){
  411. $('.refresh_table').attr('disabled', 'true');
  412. },
  413. "ready.ft.table": function(e, ft){
  414. table_mailbox_ready(ft, 'mailbox_table');
  415. },
  416. "after.ft.filtering": function(e, ft){
  417. table_mailbox_ready(ft, 'mailbox_table');
  418. }
  419. },
  420. "toggleSelector": "table tbody span.footable-toggle"
  421. });
  422. }
  423. function draw_resource_table() {
  424. ft_resource_table = FooTable.init('#resource_table', {
  425. "columns": [
  426. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  427. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  428. {"name":"name","title":lang.alias},
  429. {"name":"kind","title":lang.kind},
  430. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  431. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"150px","width":"140px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  432. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  433. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  434. ],
  435. "empty": lang.empty,
  436. "rows": $.ajax({
  437. dataType: 'json',
  438. url: '/api/v1/get/resource/all',
  439. jsonp: false,
  440. error: function () {
  441. console.log('Cannot draw resource table');
  442. },
  443. success: function (data) {
  444. $.each(data, function (i, item) {
  445. if (item.multiple_bookings == '0') {
  446. item.multiple_bookings = '<span id="active-script" class="label label-success">' + lang.booking_0_short + '</span>';
  447. } else if (item.multiple_bookings == '-1') {
  448. item.multiple_bookings = '<span id="active-script" class="label label-warning">' + lang.booking_lt0_short + '</span>';
  449. } else {
  450. item.multiple_bookings = '<span id="active-script" class="label label-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  451. }
  452. item.action = '<div class="btn-group">' +
  453. '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  454. '<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>' +
  455. '</div>';
  456. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  457. item.name = escapeHtml(item.name);
  458. });
  459. }
  460. }),
  461. "paging": {
  462. "enabled": true,
  463. "limit": 5,
  464. "size": pagination_size
  465. },
  466. "state": {
  467. "enabled": true
  468. },
  469. "filtering": {
  470. "enabled": true,
  471. "delay": 1200,
  472. "position": "left",
  473. "connectors": false,
  474. "placeholder": lang.filter_table
  475. },
  476. "components": {
  477. "filtering": FooTable.domainFilter
  478. },
  479. "sorting": {
  480. "enabled": true
  481. },
  482. "on": {
  483. "destroy.ft.table": function(e, ft){
  484. $('.refresh_table').attr('disabled', 'true');
  485. },
  486. "ready.ft.table": function(e, ft){
  487. table_mailbox_ready(ft, 'resource_table');
  488. },
  489. "after.ft.filtering": function(e, ft){
  490. table_mailbox_ready(ft, 'resource_table');
  491. }
  492. },
  493. "toggleSelector": "table tbody span.footable-toggle"
  494. });
  495. }
  496. function draw_bcc_table() {
  497. ft_bcc_table = FooTable.init('#bcc_table', {
  498. "columns": [
  499. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  500. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  501. {"name":"type","title":lang.bcc_type},
  502. {"name":"local_dest","title":lang.bcc_local_dest},
  503. {"name":"bcc_dest","title":lang.bcc_destinations},
  504. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  505. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  506. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  507. ],
  508. "empty": lang.empty,
  509. "rows": $.ajax({
  510. dataType: 'json',
  511. url: '/api/v1/get/bcc/all',
  512. jsonp: false,
  513. error: function () {
  514. console.log('Cannot draw bcc table');
  515. },
  516. success: function (data) {
  517. $.each(data, function (i, item) {
  518. item.action = '<div class="btn-group">' +
  519. '<a href="/edit/bcc/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  520. '<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>' +
  521. '</div>';
  522. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  523. item.local_dest = escapeHtml(item.local_dest);
  524. item.bcc_dest = escapeHtml(item.bcc_dest);
  525. if (item.type == 'sender') {
  526. item.type = '<span id="active-script" class="label label-success">Sender</span>';
  527. } else {
  528. item.type = '<span id="inactive-script" class="label label-warning">Recipient</span>';
  529. }
  530. });
  531. }
  532. }),
  533. "paging": {
  534. "enabled": true,
  535. "limit": 5,
  536. "size": pagination_size
  537. },
  538. "state": {
  539. "enabled": true
  540. },
  541. "filtering": {
  542. "enabled": true,
  543. "delay": 1200,
  544. "position": "left",
  545. "connectors": false,
  546. "placeholder": lang.filter_table
  547. },
  548. "sorting": {
  549. "enabled": true
  550. },
  551. "on": {
  552. "destroy.ft.table": function(e, ft){
  553. $('.refresh_table').attr('disabled', 'true');
  554. },
  555. "ready.ft.table": function(e, ft){
  556. table_mailbox_ready(ft, 'bcc_table');
  557. },
  558. "after.ft.filtering": function(e, ft){
  559. table_mailbox_ready(ft, 'bcc_table');
  560. }
  561. },
  562. "toggleSelector": "table tbody span.footable-toggle"
  563. });
  564. }
  565. function draw_recipient_map_table() {
  566. ft_recipient_map_table = FooTable.init('#recipient_map_table', {
  567. "columns": [
  568. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  569. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  570. {"name":"recipient_map_old","title":lang.recipient_map_old},
  571. {"name":"recipient_map_new","title":lang.recipient_map_new},
  572. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  573. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  574. ],
  575. "empty": lang.empty,
  576. "rows": $.ajax({
  577. dataType: 'json',
  578. url: '/api/v1/get/recipient_map/all',
  579. jsonp: false,
  580. error: function () {
  581. console.log('Cannot draw recipient map table');
  582. },
  583. success: function (data) {
  584. if (role == "admin") {
  585. $.each(data, function (i, item) {
  586. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  587. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  588. item.action = '<div class="btn-group">' +
  589. '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  590. '<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>' +
  591. '</div>';
  592. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  593. });
  594. }
  595. }
  596. }),
  597. "paging": {
  598. "enabled": true,
  599. "limit": 5,
  600. "size": pagination_size
  601. },
  602. "state": {
  603. "enabled": true
  604. },
  605. "filtering": {
  606. "enabled": true,
  607. "delay": 1200,
  608. "position": "left",
  609. "connectors": false,
  610. "placeholder": lang.filter_table
  611. },
  612. "sorting": {
  613. "enabled": true
  614. },
  615. "on": {
  616. "destroy.ft.table": function(e, ft){
  617. $('.refresh_table').attr('disabled', 'true');
  618. },
  619. "ready.ft.table": function(e, ft){
  620. table_mailbox_ready(ft, 'recipient_map_table');
  621. },
  622. "after.ft.filtering": function(e, ft){
  623. table_mailbox_ready(ft, 'recipient_map_table');
  624. }
  625. },
  626. "toggleSelector": "table tbody span.footable-toggle"
  627. });
  628. }
  629. function draw_tls_policy_table() {
  630. ft_tls_policy_table = FooTable.init('#tls_policy_table', {
  631. "columns": [
  632. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  633. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  634. {"name":"dest","title":lang.tls_map_dest},
  635. {"name":"policy","title":lang.tls_map_policy},
  636. {"name":"parameters","title":lang.tls_map_parameters},
  637. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  638. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  639. ],
  640. "empty": lang.empty,
  641. "rows": $.ajax({
  642. dataType: 'json',
  643. url: '/api/v1/get/tls-policy-map/all',
  644. jsonp: false,
  645. error: function () {
  646. console.log('Cannot draw tls policy map table');
  647. },
  648. success: function (data) {
  649. if (role == "admin") {
  650. $.each(data, function (i, item) {
  651. item.dest = escapeHtml(item.dest);
  652. item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
  653. if (item.parameters == '') {
  654. item.parameters = '<code>-</code>';
  655. } else {
  656. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  657. }
  658. item.action = '<div class="btn-group">' +
  659. '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  660. '<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>' +
  661. '</div>';
  662. item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
  663. });
  664. }
  665. }
  666. }),
  667. "paging": {
  668. "enabled": true,
  669. "limit": 5,
  670. "size": pagination_size
  671. },
  672. "state": {
  673. "enabled": true
  674. },
  675. "filtering": {
  676. "enabled": true,
  677. "delay": 1200,
  678. "position": "left",
  679. "connectors": false,
  680. "placeholder": lang.filter_table
  681. },
  682. "sorting": {
  683. "enabled": true
  684. },
  685. "on": {
  686. "destroy.ft.table": function(e, ft){
  687. $('.refresh_table').attr('disabled', 'true');
  688. },
  689. "ready.ft.table": function(e, ft){
  690. table_mailbox_ready(ft, 'tls_policy_table');
  691. },
  692. "after.ft.filtering": function(e, ft){
  693. table_mailbox_ready(ft, 'tls_policy_table');
  694. }
  695. },
  696. "toggleSelector": "table tbody span.footable-toggle"
  697. });
  698. }
  699. function draw_alias_table() {
  700. ft_alias_table = FooTable.init('#alias_table', {
  701. "columns": [
  702. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  703. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  704. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  705. {"name":"goto","title":lang.target_address},
  706. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  707. {"name":"public_comment","title":lang.public_comment,"breakpoints":"all"},
  708. {"name":"private_comment","title":lang.private_comment,"breakpoints":"all"},
  709. {"name":"sogo_visible","title":lang.sogo_visible,"breakpoints":"all"},
  710. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  711. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  712. ],
  713. "empty": lang.empty,
  714. "rows": $.ajax({
  715. dataType: 'json',
  716. url: '/api/v1/get/alias/all',
  717. jsonp: false,
  718. error: function () {
  719. console.log('Cannot draw alias table');
  720. },
  721. success: function (data) {
  722. $.each(data, function (i, item) {
  723. item.action = '<div class="btn-group">' +
  724. '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  725. '<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>' +
  726. '</div>';
  727. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  728. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  729. if (item.public_comment !== null) {
  730. item.public_comment = escapeHtml(item.public_comment);
  731. }
  732. else {
  733. item.public_comment = '-';
  734. }
  735. if (item.private_comment !== null) {
  736. item.private_comment = escapeHtml(item.private_comment);
  737. }
  738. else {
  739. item.private_comment = '-';
  740. }
  741. if (item.is_catch_all == 1) {
  742. item.address = '<div class="label label-default">Catch-All</div> ' + escapeHtml(item.address);
  743. }
  744. else {
  745. item.address = escapeHtml(item.address);
  746. }
  747. if (item.goto == "null@localhost") {
  748. item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
  749. }
  750. else if (item.goto == "spam@localhost") {
  751. item.goto = '<span class="label label-danger">Learn as spam</span>';
  752. }
  753. else if (item.goto == "ham@localhost") {
  754. item.goto = '<span class="label label-success">Learn as ham</span>';
  755. }
  756. if (item.in_primary_domain !== "") {
  757. item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
  758. }
  759. });
  760. }
  761. }),
  762. "paging": {
  763. "enabled": true,
  764. "limit": 5,
  765. "size": pagination_size
  766. },
  767. "state": {
  768. "enabled": true
  769. },
  770. "filtering": {
  771. "enabled": true,
  772. "delay": 1200,
  773. "position": "left",
  774. "connectors": false,
  775. "placeholder": lang.filter_table
  776. },
  777. "components": {
  778. "filtering": FooTable.domainFilter
  779. },
  780. "sorting": {
  781. "enabled": true
  782. },
  783. "on": {
  784. "destroy.ft.table": function(e, ft){
  785. $('.refresh_table').attr('disabled', 'true');
  786. },
  787. "ready.ft.table": function(e, ft){
  788. table_mailbox_ready(ft, 'alias_table');
  789. },
  790. "after.ft.filtering": function(e, ft){
  791. table_mailbox_ready(ft, 'alias_table');
  792. }
  793. },
  794. "toggleSelector": "table tbody span.footable-toggle"
  795. });
  796. }
  797. function draw_aliasdomain_table() {
  798. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  799. "columns": [
  800. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  801. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  802. {"name":"target_domain","title":lang.target_domain,"type":"html"},
  803. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  804. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  805. ],
  806. "empty": lang.empty,
  807. "rows": $.ajax({
  808. dataType: 'json',
  809. url: '/api/v1/get/alias-domain/all',
  810. jsonp: false,
  811. error: function () {
  812. console.log('Cannot draw alias domain table');
  813. },
  814. success: function (data) {
  815. $.each(data, function (i, item) {
  816. item.action = '<div class="btn-group">' +
  817. '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  818. '<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>' +
  819. '<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>' +
  820. '</div>';
  821. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  822. if(item.parent_is_backupmx == '1') {
  823. 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>';
  824. } else {
  825. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
  826. }
  827. });
  828. }
  829. }),
  830. "paging": {
  831. "enabled": true,
  832. "limit": 5,
  833. "size": pagination_size
  834. },
  835. "state": {
  836. "enabled": true
  837. },
  838. "filtering": {
  839. "enabled": true,
  840. "delay": 1200,
  841. "position": "left",
  842. "connectors": false,
  843. "placeholder": lang.filter_table
  844. },
  845. "sorting": {
  846. "enabled": true
  847. },
  848. "on": {
  849. "destroy.ft.table": function(e, ft){
  850. $('.refresh_table').attr('disabled', 'true');
  851. },
  852. "ready.ft.table": function(e, ft){
  853. table_mailbox_ready(ft, 'aliasdomain_table');
  854. },
  855. "after.ft.filtering": function(e, ft){
  856. table_mailbox_ready(ft, 'aliasdomain_table');
  857. }
  858. },
  859. "toggleSelector": "table tbody span.footable-toggle"
  860. });
  861. }
  862. function draw_sync_job_table() {
  863. ft_syncjob_table = FooTable.init('#sync_job_table', {
  864. "columns": [
  865. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  866. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  867. {"name":"user2","title":lang.owner},
  868. {"name":"server_w_port","title":"Server","breakpoints":"xs sm md","style":{"word-break":"break-all"}},
  869. {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
  870. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  871. {"name":"last_run","title":lang.last_run,"breakpoints":"xs sm md"},
  872. {"name":"log","title":"Log"},
  873. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active},
  874. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  875. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  876. ],
  877. "empty": lang.empty,
  878. "rows": $.ajax({
  879. dataType: 'json',
  880. url: '/api/v1/get/syncjobs/all/no_log',
  881. jsonp: false,
  882. error: function () {
  883. console.log('Cannot draw sync job table');
  884. },
  885. success: function (data) {
  886. $.each(data, function (i, item) {
  887. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">Open logs</a>'
  888. item.user2 = escapeHtml(item.user2);
  889. if (!item.exclude > 0) {
  890. item.exclude = '-';
  891. } else {
  892. item.exclude = '<code>' + item.exclude + '</code>';
  893. }
  894. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  895. item.action = '<div class="btn-group">' +
  896. '<a href="/edit/syncjob/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  897. '<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>' +
  898. '</div>';
  899. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  900. if (item.is_running == 1) {
  901. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  902. } else {
  903. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  904. }
  905. if (!item.last_run > 0) {
  906. item.last_run = lang.waiting;
  907. }
  908. });
  909. }
  910. }),
  911. "paging": {
  912. "enabled": true,
  913. "limit": 5,
  914. "size": pagination_size
  915. },
  916. "state": {
  917. "enabled": true
  918. },
  919. "filtering": {
  920. "enabled": true,
  921. "delay": 1200,
  922. "position": "left",
  923. "connectors": false,
  924. "placeholder": lang.filter_table
  925. },
  926. "sorting": {
  927. "enabled": true
  928. },
  929. "on": {
  930. "destroy.ft.table": function(e, ft){
  931. $('.refresh_table').attr('disabled', 'true');
  932. },
  933. "ready.ft.table": function(e, ft){
  934. table_mailbox_ready(ft, 'sync_job_table');
  935. },
  936. "after.ft.filtering": function(e, ft){
  937. table_mailbox_ready(ft, 'sync_job_table');
  938. }
  939. },
  940. "toggleSelector": "table tbody span.footable-toggle"
  941. });
  942. }
  943. function draw_filter_table() {
  944. ft_filter_table = FooTable.init('#filter_table', {
  945. "columns": [
  946. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  947. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  948. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  949. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  950. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  951. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  952. {"name":"script_data","title":"Script","breakpoints":"all"},
  953. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  954. ],
  955. "empty": lang.empty,
  956. "rows": $.ajax({
  957. dataType: 'json',
  958. url: '/api/v1/get/filters/all',
  959. jsonp: false,
  960. error: function () {
  961. console.log('Cannot draw filter table');
  962. },
  963. success: function (data) {
  964. $.each(data, function (i, item) {
  965. if (item.active_int == 1) {
  966. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  967. } else {
  968. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  969. }
  970. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  971. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  972. item.action = '<div class="btn-group">' +
  973. '<a href="/edit/filter/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  974. '<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>' +
  975. '</div>';
  976. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  977. });
  978. }
  979. }),
  980. "paging": {
  981. "enabled": true,
  982. "limit": 5,
  983. "size": pagination_size
  984. },
  985. "state": {
  986. "enabled": true
  987. },
  988. "filtering": {
  989. "enabled": true,
  990. "delay": 1200,
  991. "position": "left",
  992. "connectors": false,
  993. "placeholder": lang.filter_table
  994. },
  995. "sorting": {
  996. "enabled": true
  997. },
  998. "on": {
  999. "destroy.ft.table": function(e, ft){
  1000. $('.refresh_table').attr('disabled', 'true');
  1001. },
  1002. "ready.ft.table": function(e, ft){
  1003. table_mailbox_ready(ft, 'filter_table');
  1004. },
  1005. "after.ft.filtering": function(e, ft){
  1006. table_mailbox_ready(ft, 'filter_table');
  1007. }
  1008. },
  1009. "toggleSelector": "table tbody span.footable-toggle"
  1010. });
  1011. };
  1012. $('body').on('click', 'span.footable-toggle', function () {
  1013. event.stopPropagation();
  1014. })
  1015. draw_domain_table();
  1016. draw_mailbox_table();
  1017. draw_resource_table();
  1018. draw_alias_table();
  1019. draw_aliasdomain_table();
  1020. draw_sync_job_table();
  1021. draw_filter_table();
  1022. draw_bcc_table();
  1023. draw_recipient_map_table();
  1024. draw_tls_policy_table();
  1025. });