public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Leo-Andres Hofmann <hofmann@leo-andres.de>
To: development@lists.ipfire.org
Subject: [PATCH 4/4] zoneconf.cgi: Add NIC selection highlighting
Date: Tue, 17 Nov 2020 07:29:04 +0100	[thread overview]
Message-ID: <20201117062904.1547-4-hofmann@leo-andres.de> (raw)
In-Reply-To: <20201117062904.1547-1-hofmann@leo-andres.de>

[-- Attachment #1: Type: text/plain, Size: 7053 bytes --]

This improves the usability of the zone configuration by marking assigned
NICs in the zone color. The highlighting is initially applied to the static
HTML output, and JavaScript is used to follow changes made by the user.

Signed-off-by: Leo-Andres Hofmann <hofmann(a)leo-andres.de>
---
 config/rootfiles/common/web-user-interface |  1 +
 html/cgi-bin/zoneconf.cgi                  | 21 +++++---
 html/html/include/zoneconf.js              | 56 ++++++++++++++++++++++
 3 files changed, 72 insertions(+), 6 deletions(-)
 create mode 100644 html/html/include/zoneconf.js

diff --git a/config/rootfiles/common/web-user-interface b/config/rootfiles/common/web-user-interface
index 44856fcc2..3eac4411a 100644
--- a/config/rootfiles/common/web-user-interface
+++ b/config/rootfiles/common/web-user-interface
@@ -308,6 +308,7 @@ srv/web/ipfire/html/images/wakeup.gif
 srv/web/ipfire/html/images/window-new.png
 srv/web/ipfire/html/include
 srv/web/ipfire/html/include/snortupdateutility.js
+srv/web/ipfire/html/include/zoneconf.js
 srv/web/ipfire/html/index.cgi
 srv/web/ipfire/html/redirect-templates
 srv/web/ipfire/html/redirect-templates/legacy
diff --git a/html/cgi-bin/zoneconf.cgi b/html/cgi-bin/zoneconf.cgi
index ef361af95..0914ceb78 100644
--- a/html/cgi-bin/zoneconf.cgi
+++ b/html/cgi-bin/zoneconf.cgi
@@ -26,7 +26,7 @@ require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
 
-my $css = <<END
+my $extraHead = <<END
 <style>
 	table#zoneconf {
 		width: 100%;
@@ -101,6 +101,8 @@ my $css = <<END
 		margin-left: auto;
 	}
 </style>
+
+<script src="/include/zoneconf.js"></script>
 END
 ;
 
@@ -151,7 +153,7 @@ foreach (@nics) {
 	}
 }
 
-&Header::openpage($Lang::tr{"zoneconf title"}, 1, $css);
+&Header::openpage($Lang::tr{"zoneconf title"}, 1, $extraHead);
 &Header::openbigbox('100%', 'center');
 
 ### Evaluate POST parameters ###
@@ -364,6 +366,7 @@ foreach (@nics) {
 	foreach (@zones) {
 		my $uc = uc $_;
 		my $dev_name = $ethsettings{"${uc}_DEV"};
+		my $highlight = "";
 
 		if ($dev_name eq "") { # Again, skip the zone if it is not activated
 			next;
@@ -379,11 +382,12 @@ foreach (@nics) {
 
 				if ($mac eq $ethsettings{"${uc}_MACADDR"}) {
 					$checked = "checked";
+					$highlight = $_;
 				}
 
 				print <<END
-		<td class="">
-			<input type="radio" name="PPPACCESS" value="$mac" $checked>
+		<td class="$highlight">
+			<input type="radio" name="PPPACCESS" value="$mac" data-zone="RED" data-mac="$mac" onchange="highlightAccess(this)" $checked>
 		</td>
 END
 ;
@@ -424,9 +428,14 @@ END
 		$access_selected{"NONE"} = ($access_selected{"NATIVE"} eq "") && ($access_selected{"VLAN"} eq "") ? "selected" : "";
 		my $vlan_disabled = ($wlan) ? "disabled" : "";
 
+		# If the interface is assigned, hightlight table cell
+		if ($access_selected{"NONE"} eq "") {
+			$highlight = $_;
+		}
+
 		print <<END
-		<td class="">
-			<select name="ACCESS $uc $mac" onchange="document.getElementById('TAG-$uc-$mac').disabled = (this.value === 'VLAN' ? false : true)">
+		<td class="$highlight">
+			<select name="ACCESS $uc $mac" data-zone="$uc" data-mac="$mac" onchange="highlightAccess(this)">
 				<option value="NONE" $access_selected{"NONE"}>- $Lang::tr{"zoneconf access none"} -</option>
 				<option value="NATIVE" $access_selected{"NATIVE"}>$Lang::tr{"zoneconf access native"}</option>
 				<option value="VLAN" $access_selected{"VLAN"} $vlan_disabled>$Lang::tr{"zoneconf access vlan"}</option>
diff --git a/html/html/include/zoneconf.js b/html/html/include/zoneconf.js
new file mode 100644
index 000000000..d76f0ab68
--- /dev/null
+++ b/html/html/include/zoneconf.js
@@ -0,0 +1,56 @@
+/*#############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2007-2020  IPFire Team  <info(a)ipfire.org>                     #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+//zoneconf.cgi dynamic highlighting of interface access selection
+//(call this from "onchange" event of selection elements)
+function highlightAccess(selectObj) {
+	if(!(selectObj && ('zone' in selectObj.dataset) && ('mac' in selectObj.dataset))) {
+		return; //required parameters are missing
+	}
+
+	var zoneColor = selectObj.dataset.zone.trim().toLowerCase(); //zone color (red/green/blue/orange) CSS class
+
+	function colorParentCell(obj, color, enabled = true) { //find nearest parent table cell of "obj" and set its CSS color class
+		do {
+			obj = obj.parentElement;
+		} while(obj && (obj.nodeName.toUpperCase() !== 'TD'));
+		if(obj && (['green', 'red', 'orange', 'blue'].includes(color))) {
+			obj.classList.toggle(color, enabled);
+		}
+	}
+
+	//handle other associated input fields
+	if(selectObj.type.toUpperCase() === 'RADIO') { //this is a radio button group: clear all highlights
+		let radios = document.getElementsByName(selectObj.name);
+		radios.forEach(function(button) {
+			if(button.nodeName.toUpperCase() === 'INPUT') { //make sure the found element is a button
+				colorParentCell(button, zoneColor, false); //remove css
+			}
+		});
+	} else { //this is a dropdown menu: enable/disable additional VLAN tag input box
+		let tagInput = document.getElementById('TAG-' + selectObj.dataset.zone + '-' + selectObj.dataset.mac); //tag input element selector
+		if(tagInput) {
+			tagInput.disabled = (selectObj.value !== 'VLAN'); //enable tag input if VLAN mode selected
+		}
+	}
+
+	//if interface is assigned, highlight table cell in zone color
+	colorParentCell(selectObj, zoneColor, (selectObj.value !== 'NONE'));
+}
-- 
2.27.0.windows.1


  parent reply	other threads:[~2020-11-17  6:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-17  6:29 [PATCH 1/4] zoneconf.cgi: Clean up HTML output Leo-Andres Hofmann
2020-11-17  6:29 ` [PATCH 2/4] zoneconf.cgi: Make output HTML 5 standard compliant Leo-Andres Hofmann
2020-11-17  6:29 ` [PATCH 3/4] zoneconf.cgi: Improve CSS Leo-Andres Hofmann
2020-11-17  6:29 ` Leo-Andres Hofmann [this message]
2020-11-17 10:54 ` [PATCH 1/4] zoneconf.cgi: Clean up HTML output Michael Tremer
2020-12-01 22:25 ` Thank you for cleaning up the CGIs (was: Re: [PATCH 1/4] zoneconf.cgi: Clean up HTML output) Peter Müller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201117062904.1547-4-hofmann@leo-andres.de \
    --to=hofmann@leo-andres.de \
    --cc=development@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox