mailbox.js 48 KB

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