mailbox.js 48 KB

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