mailbox.js 48 KB

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