mailbox.js 48 KB

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