blob: cd938cd8498cab9c04bc097b13b5c8554b124a9f [file] [log] [blame]
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +01001$(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
27 $("#mailbox-password-warning-close").click(function( event ) {
28 $('#mailbox-passwd-hidden-info').addClass('hidden');
29 $('#mailbox-passwd-form-groups').removeClass('hidden');
30 });
31 // Sender ACL
32 if ($("#editSelectSenderACL option[value='\*']:selected").length > 0){
33 $("#sender_acl_disabled").show();
34 }
35 $('#editSelectSenderACL').change(function() {
36 if ($("#editSelectSenderACL option[value='\*']:selected").length > 0){
37 $("#sender_acl_disabled").show();
38 }
39 else {
40 $("#sender_acl_disabled").hide();
41 }
42 });
43 // Resources
44 if ($("#editSelectMultipleBookings").val() == "custom") {
45 $("#multiple_bookings_custom_div").show();
46 $('input[name=multiple_bookings]').val($("#multiple_bookings_custom").val());
47 }
48 $("#editSelectMultipleBookings").change(function() {
49 $('input[name=multiple_bookings]').val($("#editSelectMultipleBookings").val());
50 if ($('input[name=multiple_bookings]').val() == "custom") {
51 $("#multiple_bookings_custom_div").show();
52 }
53 else {
54 $("#multiple_bookings_custom_div").hide();
55 }
56 });
57 $("#multiple_bookings_custom").bind("change keypress keyup blur", function() {
58 $('input[name=multiple_bookings]').val($("#multiple_bookings_custom").val());
59 });
60
61 // load tags
62 if ($('#tags').length){
63 var tagsEl = $('#tags').parent().find('.tag-values')[0];
64 console.log($(tagsEl).val())
65 var tags = JSON.parse($(tagsEl).val());
66 $(tagsEl).val("");
67
68 for (var i = 0; i < tags.length; i++)
69 addTag($('#tags'), tags[i]);
70 }
71});
72
73jQuery(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
103 return data;
104 }
105 },
106 columns: [
107 {
108 // placeholder, so checkbox will not block child row toggle
109 title: '',
110 data: null,
111 searchable: false,
112 orderable: false,
113 defaultContent: ''
114 },
115 {
116 title: '',
117 data: 'chkbox',
118 searchable: false,
119 orderable: false,
120 defaultContent: ''
121 },
122 {
123 title: 'ID',
124 data: 'prefid',
125 defaultContent: ''
126 },
127 {
128 title: lang_user.spamfilter_table_rule,
129 data: 'value',
130 defaultContent: ''
131 },
132 {
133 title: 'Scope',
134 data: 'object',
135 defaultContent: ''
136 }
137 ]
138 });
139 }
140 function draw_bl_policy_domain_table() {
141 $('#bl_policy_domain_table').DataTable({
142 responsive: true,
143 processing: true,
144 serverSide: false,
145 stateSave: true,
146 pageLength: pagination_size,
147 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
148 "tr" +
149 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
150 language: lang_datatables,
151 ajax: {
152 type: "GET",
153 url: '/api/v1/get/policy_bl_domain/' + table_for_domain,
154 dataSrc: function(data){
155 $.each(data, function (i, item) {
156 if (!validateEmail(item.object)) {
157 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="policy_bl_domain" name="multi_select" value="' + item.prefid + '" />';
158 }
159 else {
160 item.chkbox = '<input type="checkbox" class="form-check-input" disabled tooltip="' + lang_user.spamfilter_table_domain_policy + '" />';
161 }
162 });
163
164 return data;
165 }
166 },
167 columns: [
168 {
169 // placeholder, so checkbox will not block child row toggle
170 title: '',
171 data: null,
172 searchable: false,
173 orderable: false,
174 defaultContent: ''
175 },
176 {
177 title: '',
178 data: 'chkbox',
179 searchable: false,
180 orderable: false,
181 defaultContent: ''
182 },
183 {
184 title: 'ID',
185 data: 'prefid',
186 defaultContent: ''
187 },
188 {
189 title: lang_user.spamfilter_table_rule,
190 data: 'value',
191 defaultContent: ''
192 },
193 {
194 title: 'Scope',
195 data: 'object',
196 defaultContent: ''
197 }
198 ]
199 });
200 }
201
202
203 // detect element visibility changes
204 function onVisible(element, callback) {
205 $(document).ready(function() {
206 element_object = document.querySelector(element);
207 if (element_object === null) return;
208
209 new IntersectionObserver((entries, observer) => {
210 entries.forEach(entry => {
211 if(entry.intersectionRatio > 0) {
212 callback(element_object);
213 observer.disconnect();
214 }
215 });
216 }).observe(element_object);
217 });
218 }
219 // Draw Table if tab is active
220 onVisible("[id^=wl_policy_domain_table]", () => draw_wl_policy_domain_table());
221 onVisible("[id^=bl_policy_domain_table]", () => draw_bl_policy_domain_table());
222});