mailbox.js 46 KB

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