mailbox.js 48 KB

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