mailbox.js 51 KB

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