]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/html/include/zoneconf.js
zoneconf.cgi: Add Javascript for new GUI elements
[people/pmueller/ipfire-2.x.git] / html / html / include / zoneconf.js
CommitLineData
5c33a761
LAH
1/*#############################################################################
2# #
3# IPFire.org - A linux based firewall #
4# Copyright (C) 2007-2020 IPFire Team <info@ipfire.org> #
5# #
6# This program is free software: you can redistribute it and/or modify #
7# it under the terms of the GNU General Public License as published by #
8# the Free Software Foundation, either version 3 of the License, or #
9# (at your option) any later version. #
10# #
11# This program is distributed in the hope that it will be useful, #
12# but WITHOUT ANY WARRANTY; without even the implied warranty of #
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14# GNU General Public License for more details. #
15# #
16# You should have received a copy of the GNU General Public License #
17# along with this program. If not, see <http://www.gnu.org/licenses/>. #
18# #
19#############################################################################*/
20
21//zoneconf.cgi dynamic highlighting of interface access selection
22//(call this from "onchange" event of selection elements)
23function highlightAccess(selectObj) {
24 if(!(selectObj && ('zone' in selectObj.dataset) && ('mac' in selectObj.dataset))) {
25 return; //required parameters are missing
26 }
27
28 var zoneColor = selectObj.dataset.zone.trim().toLowerCase(); //zone color (red/green/blue/orange) CSS class
29
30 function colorParentCell(obj, color, enabled = true) { //find nearest parent table cell of "obj" and set its CSS color class
31 do {
32 obj = obj.parentElement;
33 } while(obj && (obj.nodeName.toUpperCase() !== 'TD'));
34 if(obj && (['green', 'red', 'orange', 'blue'].includes(color))) {
35 obj.classList.toggle(color, enabled);
36 }
37 }
38
39 //handle other associated input fields
40 if(selectObj.type.toUpperCase() === 'RADIO') { //this is a radio button group: clear all highlights
41 let radios = document.getElementsByName(selectObj.name);
42 radios.forEach(function(button) {
43 if(button.nodeName.toUpperCase() === 'INPUT') { //make sure the found element is a button
44 colorParentCell(button, zoneColor, false); //remove css
45 }
46 });
47 } else { //this is a dropdown menu: enable/disable additional VLAN tag input box
48 let tagInput = document.getElementById('TAG-' + selectObj.dataset.zone + '-' + selectObj.dataset.mac); //tag input element selector
49 if(tagInput) {
50 tagInput.disabled = (selectObj.value !== 'VLAN'); //enable tag input if VLAN mode selected
51 }
52 }
53
54 //if interface is assigned, highlight table cell in zone color
55 colorParentCell(selectObj, zoneColor, (selectObj.value !== 'NONE'));
56}
b4434345
LAH
57
58//update zone mode
59function changeZoneMode(selectObj) {
60 if(!(selectObj && ('zone' in selectObj.dataset))) {
61 return; //required parameters are missing
62 }
63
64 // STP enable checkbox
65 let stpEnable = document.getElementById('STP-' + selectObj.dataset.zone);
66 if(stpEnable) {
67 stpEnable.disabled = (selectObj.value !== 'BRIDGE'); //STP is available if zone is in bridge mode
68 stpEnable.checked = stpEnable.checked && (! stpEnable.disabled); //un-check if disabled
69 stpEnable.dispatchEvent(new Event('change'));
70 }
71}
72
73//STP enable checkbox change toggles priority input
74function changeEnableSTP(inputObj) {
75 if(!(inputObj && ('zone' in inputObj.dataset))) {
76 return; //required parameters are missing
77 }
78
79 let priority = document.getElementById('STP-PRIORITY-' + inputObj.dataset.zone);
80 if(priority) {
81 priority.disabled = inputObj.disabled || (! inputObj.checked);
82 }
83}