mailbox.js 47 KB

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