mailbox.js 48 KB

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