mailbox.js 46 KB

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