mailbox.js 47 KB

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