edit.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. $(document).ready(function() {
  2. $(".arrow-toggle").on('click', function(e) { e.preventDefault(); $(this).find('.arrow').toggleClass("animation"); });
  3. $("#pushover_delete").click(function() { return confirm(lang.delete_ays); });
  4. $(".goto_checkbox").click(function( event ) {
  5. $("form[data-id='editalias'] .goto_checkbox").not(this).prop('checked', false);
  6. if ($("form[data-id='editalias'] .goto_checkbox:checked").length > 0) {
  7. $('#textarea_alias_goto').prop('disabled', true);
  8. }
  9. else {
  10. $("#textarea_alias_goto").removeAttr('disabled');
  11. }
  12. });
  13. $("#disable_sender_check").click(function( event ) {
  14. if ($("form[data-id='editmailbox'] #disable_sender_check:checked").length > 0) {
  15. $('#editSelectSenderACL').prop('disabled', true);
  16. $('#editSelectSenderACL').selectpicker('refresh');
  17. }
  18. else {
  19. $('#editSelectSenderACL').prop('disabled', false);
  20. $('#editSelectSenderACL').selectpicker('refresh');
  21. }
  22. });
  23. if ($("form[data-id='editalias'] .goto_checkbox:checked").length > 0) {
  24. $('#textarea_alias_goto').prop('disabled', true);
  25. }
  26. $("#mailbox-password-warning-close").click(function( event ) {
  27. $('#mailbox-passwd-hidden-info').addClass('hidden');
  28. $('#mailbox-passwd-form-groups').removeClass('hidden');
  29. });
  30. // Sender ACL
  31. if ($("#editSelectSenderACL option[value='\*']:selected").length > 0){
  32. $("#sender_acl_disabled").show();
  33. }
  34. $('#editSelectSenderACL').change(function() {
  35. if ($("#editSelectSenderACL option[value='\*']:selected").length > 0){
  36. $("#sender_acl_disabled").show();
  37. }
  38. else {
  39. $("#sender_acl_disabled").hide();
  40. }
  41. });
  42. // Resources
  43. if ($("#editSelectMultipleBookings").val() == "custom") {
  44. $("#multiple_bookings_custom_div").show();
  45. $('input[name=multiple_bookings]').val($("#multiple_bookings_custom").val());
  46. }
  47. $("#editSelectMultipleBookings").change(function() {
  48. $('input[name=multiple_bookings]').val($("#editSelectMultipleBookings").val());
  49. if ($('input[name=multiple_bookings]').val() == "custom") {
  50. $("#multiple_bookings_custom_div").show();
  51. }
  52. else {
  53. $("#multiple_bookings_custom_div").hide();
  54. }
  55. });
  56. $("#multiple_bookings_custom").bind("change keypress keyup blur", function() {
  57. $('input[name=multiple_bookings]').val($("#multiple_bookings_custom").val());
  58. });
  59. $("#show_mailbox_rename_form").click(function() {
  60. $("#rename_warning").hide();
  61. $("#rename_form").removeClass("d-none");
  62. });
  63. // load tags
  64. if ($('#tags').length){
  65. var tagsEl = $('#tags').parent().find('.tag-values')[0];
  66. console.log($(tagsEl).val())
  67. var tags = JSON.parse($(tagsEl).val());
  68. $(tagsEl).val("");
  69. for (var i = 0; i < tags.length; i++)
  70. addTag($('#tags'), tags[i]);
  71. }
  72. });
  73. jQuery(function($){
  74. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  75. function validateEmail(email) {
  76. 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,}))$/;
  77. return re.test(email);
  78. }
  79. function draw_wl_policy_domain_table() {
  80. $('#wl_policy_domain_table').DataTable({
  81. responsive: true,
  82. processing: true,
  83. serverSide: false,
  84. stateSave: true,
  85. pageLength: pagination_size,
  86. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  87. "tr" +
  88. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  89. language: lang_datatables,
  90. ajax: {
  91. type: "GET",
  92. url: '/api/v1/get/policy_wl_domain/' + table_for_domain,
  93. dataSrc: function(data){
  94. $.each(data, function (i, item) {
  95. if (!validateEmail(item.object)) {
  96. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="policy_wl_domain" name="multi_select" value="' + item.prefid + '" />';
  97. }
  98. else {
  99. item.chkbox = '<input type="checkbox" class="form-check-input" disabled title="' + lang_user.spamfilter_table_domain_policy + '" />';
  100. }
  101. });
  102. return data;
  103. }
  104. },
  105. columns: [
  106. {
  107. // placeholder, so checkbox will not block child row toggle
  108. title: '',
  109. data: null,
  110. searchable: false,
  111. orderable: false,
  112. defaultContent: ''
  113. },
  114. {
  115. title: '',
  116. data: 'chkbox',
  117. searchable: false,
  118. orderable: false,
  119. defaultContent: ''
  120. },
  121. {
  122. title: 'ID',
  123. data: 'prefid',
  124. defaultContent: ''
  125. },
  126. {
  127. title: lang_user.spamfilter_table_rule,
  128. data: 'value',
  129. defaultContent: ''
  130. },
  131. {
  132. title: 'Scope',
  133. data: 'object',
  134. defaultContent: ''
  135. }
  136. ]
  137. });
  138. }
  139. function draw_bl_policy_domain_table() {
  140. $('#bl_policy_domain_table').DataTable({
  141. responsive: true,
  142. processing: true,
  143. serverSide: false,
  144. stateSave: true,
  145. pageLength: pagination_size,
  146. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  147. "tr" +
  148. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  149. language: lang_datatables,
  150. ajax: {
  151. type: "GET",
  152. url: '/api/v1/get/policy_bl_domain/' + table_for_domain,
  153. dataSrc: function(data){
  154. $.each(data, function (i, item) {
  155. if (!validateEmail(item.object)) {
  156. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="policy_bl_domain" name="multi_select" value="' + item.prefid + '" />';
  157. }
  158. else {
  159. item.chkbox = '<input type="checkbox" class="form-check-input" disabled tooltip="' + lang_user.spamfilter_table_domain_policy + '" />';
  160. }
  161. });
  162. return data;
  163. }
  164. },
  165. columns: [
  166. {
  167. // placeholder, so checkbox will not block child row toggle
  168. title: '',
  169. data: null,
  170. searchable: false,
  171. orderable: false,
  172. defaultContent: ''
  173. },
  174. {
  175. title: '',
  176. data: 'chkbox',
  177. searchable: false,
  178. orderable: false,
  179. defaultContent: ''
  180. },
  181. {
  182. title: 'ID',
  183. data: 'prefid',
  184. defaultContent: ''
  185. },
  186. {
  187. title: lang_user.spamfilter_table_rule,
  188. data: 'value',
  189. defaultContent: ''
  190. },
  191. {
  192. title: 'Scope',
  193. data: 'object',
  194. defaultContent: ''
  195. }
  196. ]
  197. });
  198. }
  199. function add_table_row(table_id, type) {
  200. var row = $('<tr />');
  201. if (type == "mbox_attr") {
  202. cols = '<td><input class="input-sm input-xs-lg form-control" data-id="mbox_attr" type="text" name="attribute" required></td>';
  203. cols += '<td><input class="input-sm input-xs-lg form-control" data-id="mbox_attr" type="text" name="value" required></td>';
  204. cols += '<td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-secondary h-100 w-100" type="button">' + lang_admin.remove_row + '</a></td>';
  205. }
  206. row.append(cols);
  207. table_id.append(row);
  208. }
  209. $('#mbox_attr_table').on('click', 'tr a', function (e) {
  210. e.preventDefault();
  211. $(this).parents('tr').remove();
  212. });
  213. $('#add_mbox_attr_row').click(function() {
  214. add_table_row($('#mbox_attr_table'), "mbox_attr");
  215. });
  216. // detect element visibility changes
  217. function onVisible(element, callback) {
  218. $(document).ready(function() {
  219. element_object = document.querySelector(element);
  220. if (element_object === null) return;
  221. new IntersectionObserver((entries, observer) => {
  222. entries.forEach(entry => {
  223. if(entry.intersectionRatio > 0) {
  224. callback(element_object);
  225. observer.disconnect();
  226. }
  227. });
  228. }).observe(element_object);
  229. });
  230. }
  231. // Draw Table if tab is active
  232. onVisible("[id^=wl_policy_domain_table]", () => draw_wl_policy_domain_table());
  233. onVisible("[id^=bl_policy_domain_table]", () => draw_bl_policy_domain_table());
  234. });