mailbox.js 48 KB

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