edit.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. });
  60. jQuery(function($){
  61. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  62. function validateEmail(email) {
  63. 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,}))$/;
  64. return re.test(email);
  65. }
  66. function draw_wl_policy_domain_table() {
  67. $('#wl_policy_domain_table').DataTable({
  68. processing: true,
  69. serverSide: false,
  70. language: lang_datatables,
  71. ajax: {
  72. type: "GET",
  73. url: '/api/v1/get/policy_wl_domain/' + table_for_domain,
  74. dataSrc: function(data){
  75. $.each(data, function (i, item) {
  76. if (!validateEmail(item.object)) {
  77. item.chkbox = '<input type="checkbox" data-id="policy_wl_domain" name="multi_select" value="' + item.prefid + '" />';
  78. }
  79. else {
  80. item.chkbox = '<input type="checkbox" disabled title="' + lang_user.spamfilter_table_domain_policy + '" />';
  81. }
  82. });
  83. return data;
  84. }
  85. },
  86. columns: [
  87. {
  88. // placeholder, so checkbox will not block child row toggle
  89. title: '',
  90. data: null,
  91. searchable: false,
  92. orderable: false,
  93. defaultContent: ''
  94. },
  95. {
  96. title: '',
  97. data: 'chkbox',
  98. searchable: false,
  99. orderable: false,
  100. defaultContent: ''
  101. },
  102. {
  103. title: 'ID',
  104. data: 'prefid',
  105. defaultContent: ''
  106. },
  107. {
  108. title: lang_user.spamfilter_table_rule,
  109. data: 'value',
  110. defaultContent: ''
  111. },
  112. {
  113. title: 'Scope',
  114. data: 'object',
  115. defaultContent: ''
  116. }
  117. ]
  118. });
  119. }
  120. function draw_bl_policy_domain_table() {
  121. $('#bl_policy_domain_table').DataTable({
  122. processing: true,
  123. serverSide: false,
  124. language: lang_datatables,
  125. ajax: {
  126. type: "GET",
  127. url: '/api/v1/get/policy_bl_domain/' + table_for_domain,
  128. dataSrc: function(data){
  129. $.each(data, function (i, item) {
  130. if (!validateEmail(item.object)) {
  131. item.chkbox = '<input type="checkbox" data-id="policy_bl_domain" name="multi_select" value="' + item.prefid + '" />';
  132. }
  133. else {
  134. item.chkbox = '<input type="checkbox" disabled tooltip="' + lang_user.spamfilter_table_domain_policy + '" />';
  135. }
  136. });
  137. return data;
  138. }
  139. },
  140. columns: [
  141. {
  142. // placeholder, so checkbox will not block child row toggle
  143. title: '',
  144. data: null,
  145. searchable: false,
  146. orderable: false,
  147. defaultContent: ''
  148. },
  149. {
  150. title: '',
  151. data: 'chkbox',
  152. searchable: false,
  153. orderable: false,
  154. defaultContent: ''
  155. },
  156. {
  157. title: 'ID',
  158. data: 'prefid',
  159. defaultContent: ''
  160. },
  161. {
  162. title: lang_user.spamfilter_table_rule,
  163. data: 'value',
  164. defaultContent: ''
  165. },
  166. {
  167. title: 'Scope',
  168. data: 'object',
  169. defaultContent: ''
  170. }
  171. ]
  172. });
  173. }
  174. // detect element visibility changes
  175. function onVisible(element, callback) {
  176. $(document).ready(function() {
  177. element_object = document.querySelector(element);
  178. if (element_object === null) return;
  179. new IntersectionObserver((entries, observer) => {
  180. entries.forEach(entry => {
  181. if(entry.intersectionRatio > 0) {
  182. callback(element_object);
  183. observer.disconnect();
  184. }
  185. });
  186. }).observe(element_object);
  187. });
  188. }
  189. // Draw Table if tab is active
  190. onVisible("[id^=wl_policy_domain_table]", () => draw_wl_policy_domain_table());
  191. onVisible("[id^=bl_policy_domain_table]", () => draw_bl_policy_domain_table());
  192. });