mailbox.js 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  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 = GPW.pronounceable(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": 1200,
  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. "toggleSelector": "table tbody span.footable-toggle"
  300. });
  301. }
  302. function draw_mailbox_table() {
  303. ft_mailbox_table = FooTable.init('#mailbox_table', {
  304. "columns": [
  305. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  306. {"sorted": true,"name":"username","style":{"word-break":"break-all","min-width":"120px"},"title":lang.username},
  307. {"name":"name","title":lang.fname,"style":{"word-break":"break-all","min-width":"120px"},"breakpoints":"xs sm md lg"},
  308. {"name":"domain","title":lang.domain,"breakpoints":"xs sm md lg"},
  309. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  310. res = value.split("/");
  311. var of_q = (res[1] == 0 ? "∞" : humanFileSize(res[1]));
  312. return humanFileSize(res[0]) + " / " + of_q;
  313. },
  314. "sortValue": function(value){
  315. res = value.split("/");
  316. return Number(res[0]);
  317. },
  318. },
  319. {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"all"},
  320. {"name":"tls_enforce_in","filterable": false,"title":lang.tls_enforce_in,"breakpoints":"all"},
  321. {"name":"tls_enforce_out","filterable": false,"title":lang.tls_enforce_out,"breakpoints":"all"},
  322. {"name":"quarantine_notification","filterable": false,"title":lang.quarantine_notification,"breakpoints":"all"},
  323. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use,"sortValue": function(value){
  324. return Number($(value).find(".progress-bar").attr('aria-valuenow'));
  325. },
  326. },
  327. {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
  328. {"name":"rl","title":"RL","breakpoints":"all","style":{"width":"125px"}},
  329. {"name":"active","filterable": false,"title":lang.active},
  330. {"name":"action","filterable": false,"sortable": false,"style":{"min-width":"290px","text-align":"right"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  331. ],
  332. "empty": lang.empty,
  333. "rows": $.ajax({
  334. dataType: 'json',
  335. url: '/api/v1/get/mailbox/all',
  336. jsonp: false,
  337. error: function () {
  338. console.log('Cannot draw mailbox table');
  339. },
  340. success: function (data) {
  341. $.each(data, function (i, item) {
  342. item.quota = item.quota_used + "/" + item.quota;
  343. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  344. if (!item.rl) {
  345. item.rl = '∞';
  346. } else {
  347. item.rl = $.map(item.rl, function(e){
  348. return e;
  349. }).join('/1');
  350. if (item.rl_scope === 'domain') {
  351. item.rl = '↪ ' + item.rl + ' (via ' + item.domain + ')';
  352. }
  353. }
  354. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  355. item.tls_enforce_in = '<span class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success' : 'danger') + ' glyphicon glyphicon-lock"></span>';
  356. item.tls_enforce_out = '<span class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success' : 'danger') + ' glyphicon glyphicon-lock"></span>';
  357. if (item.attributes.quarantine_notification === 'never') {
  358. item.quarantine_notification = lang.never;
  359. } else if (item.attributes.quarantine_notification === 'hourly') {
  360. item.quarantine_notification = lang.hourly;
  361. } else if (item.attributes.quarantine_notification === 'daily') {
  362. item.quarantine_notification = lang.daily;
  363. } else if (item.attributes.quarantine_notification === 'weekly') {
  364. item.quarantine_notification = lang.weekly;
  365. }
  366. if (acl_data.login_as === 1) {
  367. item.action = '<div class="btn-group">' +
  368. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  369. '<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>' +
  370. '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="login_as btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>';
  371. if (ALLOW_ADMIN_EMAIL_LOGIN) {
  372. 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>';
  373. }
  374. item.action += '</div>';
  375. }
  376. else {
  377. item.action = '<div class="btn-group">' +
  378. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  379. '<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>' +
  380. '</div>';
  381. }
  382. item.in_use = '<div class="progress">' +
  383. '<div class="progress-bar progress-bar-' + item.percent_class + ' role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  384. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  385. item.username = escapeHtml(item.username);
  386. });
  387. }
  388. }),
  389. "paging": {
  390. "enabled": true,
  391. "limit": 5,
  392. "size": pagination_size
  393. },
  394. "state": {
  395. "enabled": true
  396. },
  397. "filtering": {
  398. "enabled": true,
  399. "delay": 1200,
  400. "position": "left",
  401. "connectors": false,
  402. //"container": "#tab-mailboxes.panel",
  403. "placeholder": lang.filter_table
  404. },
  405. "components": {
  406. "filtering": FooTable.domainFilter
  407. },
  408. "sorting": {
  409. "enabled": true
  410. },
  411. "on": {
  412. "destroy.ft.table": function(e, ft){
  413. $('.refresh_table').attr('disabled', 'true');
  414. },
  415. "ready.ft.table": function(e, ft){
  416. table_mailbox_ready(ft, 'mailbox_table');
  417. },
  418. "after.ft.filtering": function(e, ft){
  419. table_mailbox_ready(ft, 'mailbox_table');
  420. }
  421. },
  422. "toggleSelector": "table tbody span.footable-toggle"
  423. });
  424. }
  425. function draw_resource_table() {
  426. ft_resource_table = FooTable.init('#resource_table', {
  427. "columns": [
  428. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  429. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  430. {"name":"name","title":lang.alias},
  431. {"name":"kind","title":lang.kind},
  432. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  433. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"150px","width":"140px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  434. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  435. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  436. ],
  437. "empty": lang.empty,
  438. "rows": $.ajax({
  439. dataType: 'json',
  440. url: '/api/v1/get/resource/all',
  441. jsonp: false,
  442. error: function () {
  443. console.log('Cannot draw resource table');
  444. },
  445. success: function (data) {
  446. $.each(data, function (i, item) {
  447. if (item.multiple_bookings == '0') {
  448. item.multiple_bookings = '<span id="active-script" class="label label-success">' + lang.booking_0_short + '</span>';
  449. } else if (item.multiple_bookings == '-1') {
  450. item.multiple_bookings = '<span id="active-script" class="label label-warning">' + lang.booking_lt0_short + '</span>';
  451. } else {
  452. item.multiple_bookings = '<span id="active-script" class="label label-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  453. }
  454. item.action = '<div class="btn-group">' +
  455. '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  456. '<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>' +
  457. '</div>';
  458. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  459. item.name = escapeHtml(item.name);
  460. });
  461. }
  462. }),
  463. "paging": {
  464. "enabled": true,
  465. "limit": 5,
  466. "size": pagination_size
  467. },
  468. "state": {
  469. "enabled": true
  470. },
  471. "filtering": {
  472. "enabled": true,
  473. "delay": 1200,
  474. "position": "left",
  475. "connectors": false,
  476. "placeholder": lang.filter_table
  477. },
  478. "components": {
  479. "filtering": FooTable.domainFilter
  480. },
  481. "sorting": {
  482. "enabled": true
  483. },
  484. "on": {
  485. "destroy.ft.table": function(e, ft){
  486. $('.refresh_table').attr('disabled', 'true');
  487. },
  488. "ready.ft.table": function(e, ft){
  489. table_mailbox_ready(ft, 'resource_table');
  490. },
  491. "after.ft.filtering": function(e, ft){
  492. table_mailbox_ready(ft, 'resource_table');
  493. }
  494. },
  495. "toggleSelector": "table tbody span.footable-toggle"
  496. });
  497. }
  498. function draw_bcc_table() {
  499. ft_bcc_table = FooTable.init('#bcc_table', {
  500. "columns": [
  501. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  502. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  503. {"name":"type","title":lang.bcc_type},
  504. {"name":"local_dest","title":lang.bcc_local_dest},
  505. {"name":"bcc_dest","title":lang.bcc_destinations},
  506. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  507. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  508. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  509. ],
  510. "empty": lang.empty,
  511. "rows": $.ajax({
  512. dataType: 'json',
  513. url: '/api/v1/get/bcc/all',
  514. jsonp: false,
  515. error: function () {
  516. console.log('Cannot draw bcc table');
  517. },
  518. success: function (data) {
  519. $.each(data, function (i, item) {
  520. item.action = '<div class="btn-group">' +
  521. '<a href="/edit/bcc/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  522. '<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>' +
  523. '</div>';
  524. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  525. item.local_dest = escapeHtml(item.local_dest);
  526. item.bcc_dest = escapeHtml(item.bcc_dest);
  527. if (item.type == 'sender') {
  528. item.type = '<span id="active-script" class="label label-success">Sender</span>';
  529. } else {
  530. item.type = '<span id="inactive-script" class="label label-warning">Recipient</span>';
  531. }
  532. });
  533. }
  534. }),
  535. "paging": {
  536. "enabled": true,
  537. "limit": 5,
  538. "size": pagination_size
  539. },
  540. "state": {
  541. "enabled": true
  542. },
  543. "filtering": {
  544. "enabled": true,
  545. "delay": 1200,
  546. "position": "left",
  547. "connectors": false,
  548. "placeholder": lang.filter_table
  549. },
  550. "sorting": {
  551. "enabled": true
  552. },
  553. "on": {
  554. "destroy.ft.table": function(e, ft){
  555. $('.refresh_table').attr('disabled', 'true');
  556. },
  557. "ready.ft.table": function(e, ft){
  558. table_mailbox_ready(ft, 'bcc_table');
  559. },
  560. "after.ft.filtering": function(e, ft){
  561. table_mailbox_ready(ft, 'bcc_table');
  562. }
  563. },
  564. "toggleSelector": "table tbody span.footable-toggle"
  565. });
  566. }
  567. function draw_recipient_map_table() {
  568. ft_recipient_map_table = FooTable.init('#recipient_map_table', {
  569. "columns": [
  570. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  571. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  572. {"name":"recipient_map_old","title":lang.recipient_map_old},
  573. {"name":"recipient_map_new","title":lang.recipient_map_new},
  574. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  575. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  576. ],
  577. "empty": lang.empty,
  578. "rows": $.ajax({
  579. dataType: 'json',
  580. url: '/api/v1/get/recipient_map/all',
  581. jsonp: false,
  582. error: function () {
  583. console.log('Cannot draw recipient map table');
  584. },
  585. success: function (data) {
  586. if (role == "admin") {
  587. $.each(data, function (i, item) {
  588. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  589. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  590. item.action = '<div class="btn-group">' +
  591. '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  592. '<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>' +
  593. '</div>';
  594. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  595. });
  596. }
  597. }
  598. }),
  599. "paging": {
  600. "enabled": true,
  601. "limit": 5,
  602. "size": pagination_size
  603. },
  604. "state": {
  605. "enabled": true
  606. },
  607. "filtering": {
  608. "enabled": true,
  609. "delay": 1200,
  610. "position": "left",
  611. "connectors": false,
  612. "placeholder": lang.filter_table
  613. },
  614. "sorting": {
  615. "enabled": true
  616. },
  617. "on": {
  618. "destroy.ft.table": function(e, ft){
  619. $('.refresh_table').attr('disabled', 'true');
  620. },
  621. "ready.ft.table": function(e, ft){
  622. table_mailbox_ready(ft, 'recipient_map_table');
  623. },
  624. "after.ft.filtering": function(e, ft){
  625. table_mailbox_ready(ft, 'recipient_map_table');
  626. }
  627. },
  628. "toggleSelector": "table tbody span.footable-toggle"
  629. });
  630. }
  631. function draw_tls_policy_table() {
  632. ft_tls_policy_table = FooTable.init('#tls_policy_table', {
  633. "columns": [
  634. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  635. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  636. {"name":"dest","title":lang.tls_map_dest},
  637. {"name":"policy","title":lang.tls_map_policy},
  638. {"name":"parameters","title":lang.tls_map_parameters},
  639. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  640. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  641. ],
  642. "empty": lang.empty,
  643. "rows": $.ajax({
  644. dataType: 'json',
  645. url: '/api/v1/get/tls-policy-map/all',
  646. jsonp: false,
  647. error: function () {
  648. console.log('Cannot draw tls policy map table');
  649. },
  650. success: function (data) {
  651. if (role == "admin") {
  652. $.each(data, function (i, item) {
  653. item.dest = escapeHtml(item.dest);
  654. item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
  655. if (item.parameters == '') {
  656. item.parameters = '<code>-</code>';
  657. } else {
  658. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  659. }
  660. item.action = '<div class="btn-group">' +
  661. '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  662. '<a href="#" data-action="delete_selected" data-id="single-tls-policy-map" data-api-url="delete/tls-policy-map" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  663. '</div>';
  664. item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
  665. });
  666. }
  667. }
  668. }),
  669. "paging": {
  670. "enabled": true,
  671. "limit": 5,
  672. "size": pagination_size
  673. },
  674. "state": {
  675. "enabled": true
  676. },
  677. "filtering": {
  678. "enabled": true,
  679. "delay": 1200,
  680. "position": "left",
  681. "connectors": false,
  682. "placeholder": lang.filter_table
  683. },
  684. "sorting": {
  685. "enabled": true
  686. },
  687. "on": {
  688. "destroy.ft.table": function(e, ft){
  689. $('.refresh_table').attr('disabled', 'true');
  690. },
  691. "ready.ft.table": function(e, ft){
  692. table_mailbox_ready(ft, 'tls_policy_table');
  693. },
  694. "after.ft.filtering": function(e, ft){
  695. table_mailbox_ready(ft, 'tls_policy_table');
  696. }
  697. },
  698. "toggleSelector": "table tbody span.footable-toggle"
  699. });
  700. }
  701. function draw_transport_maps_table() {
  702. ft_transport_maps_table = FooTable.init('#transport_maps_table', {
  703. "columns": [
  704. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  705. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  706. {"name":"dest","title":lang.tls_map_dest},
  707. {"name":"parameters","title":lang.tls_map_parameters},
  708. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  709. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  710. ],
  711. "empty": lang.empty,
  712. "rows": $.ajax({
  713. dataType: 'json',
  714. url: '/api/v1/get/transport-map/all',
  715. jsonp: false,
  716. error: function () {
  717. console.log('Cannot draw transport map table');
  718. },
  719. success: function (data) {
  720. if (role == "admin") {
  721. $.each(data, function (i, item) {
  722. item.dest = escapeHtml(item.dest);
  723. if (item.parameters == '') {
  724. item.parameters = '<code>-</code>';
  725. } else {
  726. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  727. }
  728. item.action = '<div class="btn-group">' +
  729. '<a href="/edit/transport_map/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  730. '<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>' +
  731. '</div>';
  732. item.chkbox = '<input type="checkbox" data-id="transport-map" name="multi_select" value="' + item.id + '" />';
  733. });
  734. }
  735. }
  736. }),
  737. "paging": {
  738. "enabled": true,
  739. "limit": 5,
  740. "size": pagination_size
  741. },
  742. "state": {
  743. "enabled": true
  744. },
  745. "filtering": {
  746. "enabled": true,
  747. "delay": 1200,
  748. "position": "left",
  749. "connectors": false,
  750. "placeholder": lang.filter_table
  751. },
  752. "sorting": {
  753. "enabled": true
  754. },
  755. "on": {
  756. "destroy.ft.table": function(e, ft){
  757. $('.refresh_table').attr('disabled', 'true');
  758. },
  759. "ready.ft.table": function(e, ft){
  760. table_mailbox_ready(ft, 'transport_maps_table');
  761. },
  762. "after.ft.filtering": function(e, ft){
  763. table_mailbox_ready(ft, 'transport_maps_table');
  764. }
  765. },
  766. "toggleSelector": "table tbody span.footable-toggle"
  767. });
  768. }
  769. function draw_alias_table() {
  770. ft_alias_table = FooTable.init('#alias_table', {
  771. "columns": [
  772. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  773. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  774. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  775. {"name":"goto","title":lang.target_address},
  776. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  777. {"name":"public_comment","title":lang.public_comment,"breakpoints":"all"},
  778. {"name":"private_comment","title":lang.private_comment,"breakpoints":"all"},
  779. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  780. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  781. ],
  782. "empty": lang.empty,
  783. "rows": $.ajax({
  784. dataType: 'json',
  785. url: '/api/v1/get/alias/all',
  786. jsonp: false,
  787. error: function () {
  788. console.log('Cannot draw alias table');
  789. },
  790. success: function (data) {
  791. $.each(data, function (i, item) {
  792. item.action = '<div class="btn-group">' +
  793. '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  794. '<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>' +
  795. '</div>';
  796. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  797. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  798. if (item.public_comment !== null) {
  799. item.public_comment = escapeHtml(item.public_comment);
  800. }
  801. else {
  802. item.public_comment = '-';
  803. }
  804. if (item.private_comment !== null) {
  805. item.private_comment = escapeHtml(item.private_comment);
  806. }
  807. else {
  808. item.private_comment = '-';
  809. }
  810. if (item.is_catch_all == 1) {
  811. item.address = '<div class="label label-default">Catch-All</div> ' + escapeHtml(item.address);
  812. }
  813. else {
  814. item.address = escapeHtml(item.address);
  815. }
  816. if (item.goto == "null@localhost") {
  817. item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
  818. }
  819. else if (item.goto == "spam@localhost") {
  820. item.goto = '<span class="label label-danger">Learn as spam</span>';
  821. }
  822. else if (item.goto == "ham@localhost") {
  823. item.goto = '<span class="label label-success">Learn as ham</span>';
  824. }
  825. if (item.in_primary_domain !== "") {
  826. item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
  827. }
  828. });
  829. }
  830. }),
  831. "paging": {
  832. "enabled": true,
  833. "limit": 5,
  834. "size": pagination_size
  835. },
  836. "state": {
  837. "enabled": true
  838. },
  839. "filtering": {
  840. "enabled": true,
  841. "delay": 1200,
  842. "position": "left",
  843. "connectors": false,
  844. "placeholder": lang.filter_table
  845. },
  846. "components": {
  847. "filtering": FooTable.domainFilter
  848. },
  849. "sorting": {
  850. "enabled": true
  851. },
  852. "on": {
  853. "destroy.ft.table": function(e, ft){
  854. $('.refresh_table').attr('disabled', 'true');
  855. },
  856. "ready.ft.table": function(e, ft){
  857. table_mailbox_ready(ft, 'alias_table');
  858. },
  859. "after.ft.filtering": function(e, ft){
  860. table_mailbox_ready(ft, 'alias_table');
  861. }
  862. },
  863. "toggleSelector": "table tbody span.footable-toggle"
  864. });
  865. }
  866. function draw_aliasdomain_table() {
  867. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  868. "columns": [
  869. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  870. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  871. {"name":"target_domain","title":lang.target_domain,"type":"html"},
  872. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  873. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  874. ],
  875. "empty": lang.empty,
  876. "rows": $.ajax({
  877. dataType: 'json',
  878. url: '/api/v1/get/alias-domain/all',
  879. jsonp: false,
  880. error: function () {
  881. console.log('Cannot draw alias domain table');
  882. },
  883. success: function (data) {
  884. $.each(data, function (i, item) {
  885. item.action = '<div class="btn-group">' +
  886. '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  887. '<a href="#" data-action="delete_selected" data-id="single-alias-domain" data-api-url="delete/alias-domain" data-item="' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  888. '<a href="#dnsInfoModal" class="btn btn-xs btn-info" data-toggle="modal" data-domain="' + encodeURIComponent(item.alias_domain) + '"><span class="glyphicon glyphicon-question-sign"></span> DNS</a></div>' +
  889. '</div>';
  890. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  891. if(item.parent_is_backupmx == '1') {
  892. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a> <div class="label label-warning">' + lang.alias_domain_backupmx + '</div></span>';
  893. } else {
  894. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
  895. }
  896. });
  897. }
  898. }),
  899. "paging": {
  900. "enabled": true,
  901. "limit": 5,
  902. "size": pagination_size
  903. },
  904. "state": {
  905. "enabled": true
  906. },
  907. "filtering": {
  908. "enabled": true,
  909. "delay": 1200,
  910. "position": "left",
  911. "connectors": false,
  912. "placeholder": lang.filter_table
  913. },
  914. "sorting": {
  915. "enabled": true
  916. },
  917. "on": {
  918. "destroy.ft.table": function(e, ft){
  919. $('.refresh_table').attr('disabled', 'true');
  920. },
  921. "ready.ft.table": function(e, ft){
  922. table_mailbox_ready(ft, 'aliasdomain_table');
  923. },
  924. "after.ft.filtering": function(e, ft){
  925. table_mailbox_ready(ft, 'aliasdomain_table');
  926. }
  927. },
  928. "toggleSelector": "table tbody span.footable-toggle"
  929. });
  930. }
  931. function draw_sync_job_table() {
  932. ft_syncjob_table = FooTable.init('#sync_job_table', {
  933. "columns": [
  934. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  935. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  936. {"name":"user2","title":lang.owner},
  937. {"name":"server_w_port","title":"Server","breakpoints":"xs sm md","style":{"word-break":"break-all"}},
  938. {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
  939. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  940. {"name":"last_run","title":lang.last_run,"breakpoints":"xs sm md"},
  941. {"name":"log","title":"Log"},
  942. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active},
  943. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  944. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  945. ],
  946. "empty": lang.empty,
  947. "rows": $.ajax({
  948. dataType: 'json',
  949. url: '/api/v1/get/syncjobs/all/no_log',
  950. jsonp: false,
  951. error: function () {
  952. console.log('Cannot draw sync job table');
  953. },
  954. success: function (data) {
  955. $.each(data, function (i, item) {
  956. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">Open logs</a>'
  957. item.user2 = escapeHtml(item.user2);
  958. if (!item.exclude > 0) {
  959. item.exclude = '-';
  960. } else {
  961. item.exclude = '<code>' + item.exclude + '</code>';
  962. }
  963. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  964. item.action = '<div class="btn-group">' +
  965. '<a href="/edit/syncjob/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  966. '<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>' +
  967. '</div>';
  968. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  969. if (item.is_running == 1) {
  970. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  971. } else {
  972. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  973. }
  974. if (!item.last_run > 0) {
  975. item.last_run = lang.waiting;
  976. }
  977. });
  978. }
  979. }),
  980. "paging": {
  981. "enabled": true,
  982. "limit": 5,
  983. "size": pagination_size
  984. },
  985. "state": {
  986. "enabled": true
  987. },
  988. "filtering": {
  989. "enabled": true,
  990. "delay": 1200,
  991. "position": "left",
  992. "connectors": false,
  993. "placeholder": lang.filter_table
  994. },
  995. "sorting": {
  996. "enabled": true
  997. },
  998. "on": {
  999. "destroy.ft.table": function(e, ft){
  1000. $('.refresh_table').attr('disabled', 'true');
  1001. },
  1002. "ready.ft.table": function(e, ft){
  1003. table_mailbox_ready(ft, 'sync_job_table');
  1004. },
  1005. "after.ft.filtering": function(e, ft){
  1006. table_mailbox_ready(ft, 'sync_job_table');
  1007. }
  1008. },
  1009. "toggleSelector": "table tbody span.footable-toggle"
  1010. });
  1011. }
  1012. function draw_filter_table() {
  1013. ft_filter_table = FooTable.init('#filter_table', {
  1014. "columns": [
  1015. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  1016. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  1017. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  1018. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  1019. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  1020. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  1021. {"name":"script_data","title":"Script","breakpoints":"all"},
  1022. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  1023. ],
  1024. "empty": lang.empty,
  1025. "rows": $.ajax({
  1026. dataType: 'json',
  1027. url: '/api/v1/get/filters/all',
  1028. jsonp: false,
  1029. error: function () {
  1030. console.log('Cannot draw filter table');
  1031. },
  1032. success: function (data) {
  1033. $.each(data, function (i, item) {
  1034. if (item.active_int == 1) {
  1035. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  1036. } else {
  1037. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  1038. }
  1039. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  1040. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  1041. item.action = '<div class="btn-group">' +
  1042. '<a href="/edit/filter/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  1043. '<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>' +
  1044. '</div>';
  1045. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  1046. });
  1047. }
  1048. }),
  1049. "paging": {
  1050. "enabled": true,
  1051. "limit": 5,
  1052. "size": pagination_size
  1053. },
  1054. "state": {
  1055. "enabled": true
  1056. },
  1057. "filtering": {
  1058. "enabled": true,
  1059. "delay": 1200,
  1060. "position": "left",
  1061. "connectors": false,
  1062. "placeholder": lang.filter_table
  1063. },
  1064. "sorting": {
  1065. "enabled": true
  1066. },
  1067. "on": {
  1068. "destroy.ft.table": function(e, ft){
  1069. $('.refresh_table').attr('disabled', 'true');
  1070. },
  1071. "ready.ft.table": function(e, ft){
  1072. table_mailbox_ready(ft, 'filter_table');
  1073. },
  1074. "after.ft.filtering": function(e, ft){
  1075. table_mailbox_ready(ft, 'filter_table');
  1076. }
  1077. },
  1078. "toggleSelector": "table tbody span.footable-toggle"
  1079. });
  1080. };
  1081. $('body').on('click', 'span.footable-toggle', function () {
  1082. event.stopPropagation();
  1083. })
  1084. draw_domain_table();
  1085. draw_mailbox_table();
  1086. draw_resource_table();
  1087. draw_alias_table();
  1088. draw_aliasdomain_table();
  1089. draw_sync_job_table();
  1090. draw_filter_table();
  1091. draw_bcc_table();
  1092. draw_recipient_map_table();
  1093. draw_tls_policy_table();
  1094. draw_transport_maps_table();
  1095. });