mailbox.js 47 KB

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