mailbox.js 48 KB

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