mailbox.js 45 KB

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