blob: 308ec8c1383ee4c9e19d4e412e290eb5309b89ad [file] [log] [blame]
Matthias Andreas Benkardd63fe562023-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
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020061 $("#show_mailbox_rename_form").click(function() {
62 $("#rename_warning").hide();
63 $("#rename_form").removeClass("d-none");
64 });
65
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010066 // load tags
67 if ($('#tags').length){
68 var tagsEl = $('#tags').parent().find('.tag-values')[0];
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010069 var tags = JSON.parse($(tagsEl).val());
70 $(tagsEl).val("");
71
72 for (var i = 0; i < tags.length; i++)
73 addTag($('#tags'), tags[i]);
74 }
75});
76
77jQuery(function($){
78 // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
79 function validateEmail(email) {
80 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,}))$/;
81 return re.test(email);
82 }
83 function draw_wl_policy_domain_table() {
84 $('#wl_policy_domain_table').DataTable({
85 responsive: true,
86 processing: true,
87 serverSide: false,
88 stateSave: true,
89 pageLength: pagination_size,
90 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
91 "tr" +
92 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
93 language: lang_datatables,
94 ajax: {
95 type: "GET",
96 url: '/api/v1/get/policy_wl_domain/' + table_for_domain,
97 dataSrc: function(data){
98 $.each(data, function (i, item) {
99 if (!validateEmail(item.object)) {
100 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="policy_wl_domain" name="multi_select" value="' + item.prefid + '" />';
101 }
102 else {
103 item.chkbox = '<input type="checkbox" class="form-check-input" disabled title="' + lang_user.spamfilter_table_domain_policy + '" />';
104 }
105 });
106
107 return data;
108 }
109 },
110 columns: [
111 {
112 // placeholder, so checkbox will not block child row toggle
113 title: '',
114 data: null,
115 searchable: false,
116 orderable: false,
117 defaultContent: ''
118 },
119 {
120 title: '',
121 data: 'chkbox',
122 searchable: false,
123 orderable: false,
124 defaultContent: ''
125 },
126 {
127 title: 'ID',
128 data: 'prefid',
129 defaultContent: ''
130 },
131 {
132 title: lang_user.spamfilter_table_rule,
133 data: 'value',
134 defaultContent: ''
135 },
136 {
137 title: 'Scope',
138 data: 'object',
139 defaultContent: ''
140 }
141 ]
142 });
143 }
144 function draw_bl_policy_domain_table() {
145 $('#bl_policy_domain_table').DataTable({
146 responsive: true,
147 processing: true,
148 serverSide: false,
149 stateSave: true,
150 pageLength: pagination_size,
151 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
152 "tr" +
153 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
154 language: lang_datatables,
155 ajax: {
156 type: "GET",
157 url: '/api/v1/get/policy_bl_domain/' + table_for_domain,
158 dataSrc: function(data){
159 $.each(data, function (i, item) {
160 if (!validateEmail(item.object)) {
161 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="policy_bl_domain" name="multi_select" value="' + item.prefid + '" />';
162 }
163 else {
164 item.chkbox = '<input type="checkbox" class="form-check-input" disabled tooltip="' + lang_user.spamfilter_table_domain_policy + '" />';
165 }
166 });
167
168 return data;
169 }
170 },
171 columns: [
172 {
173 // placeholder, so checkbox will not block child row toggle
174 title: '',
175 data: null,
176 searchable: false,
177 orderable: false,
178 defaultContent: ''
179 },
180 {
181 title: '',
182 data: 'chkbox',
183 searchable: false,
184 orderable: false,
185 defaultContent: ''
186 },
187 {
188 title: 'ID',
189 data: 'prefid',
190 defaultContent: ''
191 },
192 {
193 title: lang_user.spamfilter_table_rule,
194 data: 'value',
195 defaultContent: ''
196 },
197 {
198 title: 'Scope',
199 data: 'object',
200 defaultContent: ''
201 }
202 ]
203 });
204 }
205
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100206 function add_table_row(table_id, type) {
207 var row = $('<tr />');
208 if (type == "mbox_attr") {
209 cols = '<td><input class="input-sm input-xs-lg form-control" data-id="mbox_attr" type="text" name="attribute" required></td>';
210 cols += '<td><input class="input-sm input-xs-lg form-control" data-id="mbox_attr" type="text" name="value" required></td>';
211 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>';
212 }
213 row.append(cols);
214 table_id.append(row);
215 }
216 $('#mbox_attr_table').on('click', 'tr a', function (e) {
217 e.preventDefault();
218 $(this).parents('tr').remove();
219 });
220 $('#add_mbox_attr_row').click(function() {
221 add_table_row($('#mbox_attr_table'), "mbox_attr");
222 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100223
224 // detect element visibility changes
225 function onVisible(element, callback) {
226 $(document).ready(function() {
227 element_object = document.querySelector(element);
228 if (element_object === null) return;
229
230 new IntersectionObserver((entries, observer) => {
231 entries.forEach(entry => {
232 if(entry.intersectionRatio > 0) {
233 callback(element_object);
234 observer.disconnect();
235 }
236 });
237 }).observe(element_object);
238 });
239 }
240 // Draw Table if tab is active
241 onVisible("[id^=wl_policy_domain_table]", () => draw_wl_policy_domain_table());
242 onVisible("[id^=bl_policy_domain_table]", () => draw_bl_policy_domain_table());
243});