edit.js 6.9 KB

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