From f84319d67bf3a4f3b9807aa6e9ca871445a49dcc Mon Sep 17 00:00:00 2001 From: Karai Csaba Date: Sat, 7 May 2016 11:40:52 +0200 Subject: [PATCH] Added: radio button implementation --- examples/dummy-web-server.pl | 14 +++++++++--- examples/web-server/LED.html | 43 ++++++++++++++++++++++-------------- html/userpage.js | 23 ++++++++++++------- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/examples/dummy-web-server.pl b/examples/dummy-web-server.pl index 530c199..6743c43 100755 --- a/examples/dummy-web-server.pl +++ b/examples/dummy-web-server.pl @@ -12,7 +12,7 @@ my $ledLabel : shared = "LED is turned off"; my $ledFreq : shared = 10; my @ledHistory : shared; my $startTime : shared = time; - +my $pattern : shared = "50_50"; # auto-flush on socket $| = 1; @@ -401,13 +401,21 @@ sub process_user_comm_led if( exists $http->{postArgs}{frequency} ) { $ledFreq = $http->{postArgs}{frequency}; - led_add_history("Set LED frequency to $ledFreq Hz"); + led_add_history("Set frequency to $ledFreq Hz"); + } + if( exists $http->{postArgs}{pattern} ) + { + $pattern = $http->{postArgs}{pattern}; + my $out = $pattern; + $out =~ s/_/\% - /; + $out .= "%"; + led_add_history("Set pattern to $out"); } return simple_response(204, "OK"); } elsif( $http->{urlArgs}{reason} eq "load" ) { - $loadData = ', "frequency": ' . $ledFreq; + $loadData = ', "frequency": ' . $ledFreq . ', "pattern": "' . $pattern . '"'; } my $list = ", \"led_history\": [" . join(", ", map { "\"$_\"" } @ledHistory ) . "]"; diff --git a/examples/web-server/LED.html b/examples/web-server/LED.html index 0ff8f44..d471d76 100644 --- a/examples/web-server/LED.html +++ b/examples/web-server/LED.html @@ -3,21 +3,32 @@
-

- - - -

-

-

-

- Frequency: - - -
-

-

-

diff --git a/html/userpage.js b/html/userpage.js index c8fc735..9f85a90 100644 --- a/html/userpage.js +++ b/html/userpage.js @@ -12,7 +12,14 @@ function notifyResponse( data ) var el = elems[ndx]; if(el.tagName == "INPUT") { - el.value = data[v]; + if( el.type == "radio" ) + { + el.checked = data[v] == el.value; + } + else + { + el.value = data[v]; + } } } var elem = document.getElementById(v); @@ -20,18 +27,18 @@ function notifyResponse( data ) { if(elem.tagName == "P" || elem.tagName == "DIV") { - elem.innerHTML = data[v]; + elem.innerHTML = data[v]; } if(elem.tagName == "UL" || elem.tagName == "OL") { - var list = data[v]; - var html = ""; + var list = data[v]; + var html = ""; - for (var i=0; i" + list[i] + ""); } - elem.innerHTML = html; + elem.innerHTML = html; } } }); @@ -49,8 +56,8 @@ function refreshFormData() notifyResponse(resp); if( loadCounter > 0 ) { - loadCounter--; - refreshFormData(); + loadCounter--; + refreshFormData(); } } ); } , 250);