|
1 | 1 | /** |
2 | 2 | * Frontend Advanced Settings - IP Whitelist Management |
3 | 3 | */ |
4 | | -$(document).on('rex:ready', function() { |
5 | | - // Funktion zum Hinzufügen einer IP-Adresse zum Whitelist-Feld |
6 | | - function addIpToWhitelist(ip) { |
7 | | - var ipField = $('#maintenance-allowed-ips'); |
8 | | - |
9 | | - if (!ipField.length) { |
10 | | - console.error('IP field not found'); |
11 | | - return; |
12 | | - } |
| 4 | +(function($) { |
| 5 | + 'use strict'; |
| 6 | + |
| 7 | + $(function() { |
| 8 | + console.log('Maintenance IP management loaded'); |
13 | 9 |
|
14 | | - if (ipField.val().trim() === '') { |
15 | | - // Wenn das Feld leer ist, einfach die IP hinzufügen |
16 | | - ipField.val(ip); |
17 | | - } else { |
18 | | - // IP-Adressen als Array verarbeiten und alle Leerzeichen entfernen |
19 | | - var ips = ipField.val().split(',').map(function(ip) { |
20 | | - return ip.trim(); |
21 | | - }).filter(function(ip) { |
22 | | - // Leere Einträge filtern |
23 | | - return ip !== ''; |
24 | | - }); |
| 10 | + // Funktion zum Hinzufügen einer IP-Adresse zum Whitelist-Feld |
| 11 | + function addIpToWhitelist(ip) { |
| 12 | + console.log('Adding IP:', ip); |
| 13 | + var ipField = $('#maintenance-allowed-ips'); |
| 14 | + |
| 15 | + console.log('Field found:', ipField.length); |
25 | 16 |
|
26 | | - // Prüfen, ob IP bereits enthalten ist |
27 | | - if (ips.indexOf(ip) === -1) { |
28 | | - ips.push(ip); |
29 | | - // Saubere Komma-getrennte Liste ohne unnötige Leerzeichen |
30 | | - ipField.val(ips.join(',')); |
| 17 | + if (!ipField.length) { |
| 18 | + console.error('IP field not found'); |
| 19 | + return; |
| 20 | + } |
| 21 | + |
| 22 | + var currentValue = ipField.val().trim(); |
| 23 | + console.log('Current value:', currentValue); |
| 24 | + |
| 25 | + if (currentValue === '') { |
| 26 | + // Wenn das Feld leer ist, einfach die IP hinzufügen |
| 27 | + ipField.val(ip); |
| 28 | + console.log('Set value to:', ip); |
| 29 | + } else { |
| 30 | + // IP-Adressen als Array verarbeiten und alle Leerzeichen entfernen |
| 31 | + var ips = currentValue.split(',').map(function(ip) { |
| 32 | + return ip.trim(); |
| 33 | + }).filter(function(ip) { |
| 34 | + // Leere Einträge filtern |
| 35 | + return ip !== ''; |
| 36 | + }); |
| 37 | + |
| 38 | + console.log('Current IPs:', ips); |
| 39 | + |
| 40 | + // Prüfen, ob IP bereits enthalten ist |
| 41 | + if (ips.indexOf(ip) === -1) { |
| 42 | + ips.push(ip); |
| 43 | + // Saubere Komma-getrennte Liste ohne unnötige Leerzeichen |
| 44 | + ipField.val(ips.join(',')); |
| 45 | + console.log('Updated value to:', ips.join(',')); |
| 46 | + } else { |
| 47 | + console.log('IP already exists'); |
| 48 | + } |
31 | 49 | } |
32 | 50 | } |
33 | | - } |
34 | | - |
35 | | - // Client-IP-Adresse hinzufügen |
36 | | - $('#maintenance-add-ip').on('click', function(e) { |
37 | | - e.preventDefault(); |
38 | | - var currentIp = $(this).data('ip'); |
39 | | - if (currentIp) { |
40 | | - addIpToWhitelist(currentIp); |
41 | | - } |
42 | | - }); |
43 | | - |
44 | | - // Server-IP-Adresse hinzufügen |
45 | | - $('#maintenance-add-server-ip').on('click', function(e) { |
46 | | - e.preventDefault(); |
47 | | - var serverIp = $(this).data('ip'); |
48 | | - if (serverIp) { |
49 | | - addIpToWhitelist(serverIp); |
50 | | - } |
| 51 | + |
| 52 | + // Client-IP-Adresse hinzufügen |
| 53 | + $(document).on('click', '#maintenance-add-ip', function(e) { |
| 54 | + e.preventDefault(); |
| 55 | + console.log('Add IP button clicked'); |
| 56 | + var currentIp = $(this).data('ip'); |
| 57 | + console.log('IP from data attribute:', currentIp); |
| 58 | + if (currentIp) { |
| 59 | + addIpToWhitelist(currentIp); |
| 60 | + } |
| 61 | + }); |
| 62 | + |
| 63 | + // Server-IP-Adresse hinzufügen |
| 64 | + $(document).on('click', '#maintenance-add-server-ip', function(e) { |
| 65 | + e.preventDefault(); |
| 66 | + console.log('Add Server IP button clicked'); |
| 67 | + var serverIp = $(this).data('ip'); |
| 68 | + console.log('Server IP from data attribute:', serverIp); |
| 69 | + if (serverIp) { |
| 70 | + addIpToWhitelist(serverIp); |
| 71 | + } |
| 72 | + }); |
51 | 73 | }); |
52 | | -}); |
| 74 | +})(jQuery); |
0 commit comments