]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/html/include/zoneconf.js
1 /*#############################################################################
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2020 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
19 #############################################################################*/
21 //zoneconf.cgi dynamic highlighting of interface access selection
22 //(call this from "onchange" event of selection elements)
23 function highlightAccess(selectObj
) {
24 if(!(selectObj
&& ('zone' in selectObj
.dataset
) && ('mac' in selectObj
.dataset
))) {
25 return; //required parameters are missing
28 var zoneColor
= selectObj
.dataset
.zone
.trim().toLowerCase(); //zone color (red/green/blue/orange) CSS class
30 function colorParentCell(obj
, color
, enabled
= true) { //find nearest parent table cell of "obj" and set its CSS color class
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
);
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
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
50 tagInput
.disabled
= (selectObj
.value
!== 'VLAN'); //enable tag input if VLAN mode selected
54 //if interface is assigned, highlight table cell in zone color
55 colorParentCell(selectObj
, zoneColor
, (selectObj
.value
!== 'NONE'));
59 function changeZoneMode(selectObj
) {
60 if(!(selectObj
&& ('zone' in selectObj
.dataset
))) {
61 return; //required parameters are missing
64 // STP enable checkbox
65 let stpEnable
= document
.getElementById('STP-' + selectObj
.dataset
.zone
);
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'));
73 //STP enable checkbox change toggles priority input
74 function changeEnableSTP(inputObj
) {
75 if(!(inputObj
&& ('zone' in inputObj
.dataset
))) {
76 return; //required parameters are missing
79 let priority
= document
.getElementById('STP-PRIORITY-' + inputObj
.dataset
.zone
);
81 priority
.disabled
= inputObj
.disabled
|| (! inputObj
.checked
);