mailbox.js 47 KB

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