mailbox.js 49 KB

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