mailbox.js 46 KB

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