blob: 55a8e6b40af151faeb3684c9312477c9df796299 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +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 });
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020031 // Sender ACL
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010032 if ($("#editSelectSenderACL option[value='\*']:selected").length > 0){
33 $("#sender_acl_disabled").show();
34 }
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020035 $('#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());
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010047 }
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020048 $("#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 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010060
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 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010071});
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020072
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010073jQuery(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() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010080 $('#wl_policy_domain_table').DataTable({
81 processing: true,
82 serverSide: false,
83 language: lang_datatables,
84 ajax: {
85 type: "GET",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010086 url: '/api/v1/get/policy_wl_domain/' + table_for_domain,
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010087 dataSrc: function(data){
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010088 $.each(data, function (i, item) {
89 if (!validateEmail(item.object)) {
90 item.chkbox = '<input type="checkbox" data-id="policy_wl_domain" name="multi_select" value="' + item.prefid + '" />';
91 }
92 else {
93 item.chkbox = '<input type="checkbox" disabled title="' + lang_user.spamfilter_table_domain_policy + '" />';
94 }
95 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010096
97 return data;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010098 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010099 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100100 columns: [
101 {
102 // placeholder, so checkbox will not block child row toggle
103 title: '',
104 data: null,
105 searchable: false,
106 orderable: false,
107 defaultContent: ''
108 },
109 {
110 title: '',
111 data: 'chkbox',
112 searchable: false,
113 orderable: false,
114 defaultContent: ''
115 },
116 {
117 title: 'ID',
118 data: 'prefid',
119 defaultContent: ''
120 },
121 {
122 title: lang_user.spamfilter_table_rule,
123 data: 'value',
124 defaultContent: ''
125 },
126 {
127 title: 'Scope',
128 data: 'object',
129 defaultContent: ''
130 }
131 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100132 });
133 }
134 function draw_bl_policy_domain_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100135 $('#bl_policy_domain_table').DataTable({
136 processing: true,
137 serverSide: false,
138 language: lang_datatables,
139 ajax: {
140 type: "GET",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100141 url: '/api/v1/get/policy_bl_domain/' + table_for_domain,
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100142 dataSrc: function(data){
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100143 $.each(data, function (i, item) {
144 if (!validateEmail(item.object)) {
145 item.chkbox = '<input type="checkbox" data-id="policy_bl_domain" name="multi_select" value="' + item.prefid + '" />';
146 }
147 else {
148 item.chkbox = '<input type="checkbox" disabled tooltip="' + lang_user.spamfilter_table_domain_policy + '" />';
149 }
150 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100151
152 return data;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100153 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100154 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100155 columns: [
156 {
157 // placeholder, so checkbox will not block child row toggle
158 title: '',
159 data: null,
160 searchable: false,
161 orderable: false,
162 defaultContent: ''
163 },
164 {
165 title: '',
166 data: 'chkbox',
167 searchable: false,
168 orderable: false,
169 defaultContent: ''
170 },
171 {
172 title: 'ID',
173 data: 'prefid',
174 defaultContent: ''
175 },
176 {
177 title: lang_user.spamfilter_table_rule,
178 data: 'value',
179 defaultContent: ''
180 },
181 {
182 title: 'Scope',
183 data: 'object',
184 defaultContent: ''
185 }
186 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100187 });
188 }
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100189
190
191 // detect element visibility changes
192 function onVisible(element, callback) {
193 $(document).ready(function() {
194 element_object = document.querySelector(element);
195 if (element_object === null) return;
196
197 new IntersectionObserver((entries, observer) => {
198 entries.forEach(entry => {
199 if(entry.intersectionRatio > 0) {
200 callback(element_object);
201 observer.disconnect();
202 }
203 });
204 }).observe(element_object);
205 });
206 }
207 // Draw Table if tab is active
208 onVisible("[id^=wl_policy_domain_table]", () => draw_wl_policy_domain_table());
209 onVisible("[id^=bl_policy_domain_table]", () => draw_bl_policy_domain_table());
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200210});