mailbox.js 49 KB

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