mailbox.js 50 KB

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