From 52aacaf8b7d884611663970b167f6a5ebd222003 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Thu, 27 Oct 2022 11:35:56 +0000 Subject: [PATCH] fhemweb.js: Add function to the dropdown (Forum #129858) git-svn-id: https://svn.fhem.de/fhem/trunk@26600 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/fhem.pl | 40 +++++---- fhem/www/pgm2/fhemweb.js | 170 +++++++++++++++++++++++++-------------- 2 files changed, 134 insertions(+), 76 deletions(-) diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 7da4b3832..7283673b1 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -88,7 +88,7 @@ sub OldReadingsNum($$$;$); sub OldReadingsTimestamp($$$); sub OldReadingsVal($$$); sub OpenLogfile($); -sub PrintHash($$); +sub PrintHash($$;$); sub ReadingsAge($$$); sub ReadingsNum($$$;$); sub ReadingsTimestamp($$$); @@ -2564,37 +2564,40 @@ CommandSetReading($$) ############# sub -PrintHash($$) +PrintHash($$;$) { - my ($h, $lev) = @_; + my ($h, $lev, $prefix) = @_; my $si = AttrVal("global", "showInternalValues", 0); return "" if($h->{".visited"}); $h->{".visited"} = 1; + $prefix="" if(!$prefix); my ($str,$sstr) = ("",""); foreach my $c (sort keys %{$h}) { next if(!$si && $c =~ m/^\./ || $c eq ".visited"); if(ref($h->{$c})) { if(ref($h->{$c}) eq "HASH") { if(defined($h->{$c}{TIME}) && defined($h->{$c}{VAL})) { - $str .= sprintf("%*s %-19s %-15s %s\n", + $str .= sprintf("$prefix%*s %-19s %-15s %s\n", $lev," ", $h->{$c}{TIME},$c,$h->{$c}{VAL}); } elsif($c eq "IODev" || $c eq "HASH") { - $str .= sprintf("%*s %-10s %s\n", $lev," ",$c, $h->{$c}{NAME}); + $str .= sprintf("$prefix%*s %-10s %s\n", $lev," ",$c, $h->{$c}{NAME}); } else { - $sstr .= sprintf("%*s %s:\n", $lev, " ", $c); - $sstr .= PrintHash($h->{$c}, $lev+2); + $sstr .= sprintf("$prefix%*s %s:\n", $lev, " ", $c); + $sstr .= PrintHash($h->{$c}, $lev+2, $prefix); } } elsif(ref($h->{$c}) eq "ARRAY") { - $sstr .= sprintf("%*s %s:\n", $lev, " ", $c); + $sstr .= sprintf("$prefix%*s %s:\n", $lev, " ", $c); foreach my $v (@{$h->{$c}}) { - $sstr .= sprintf("%*s %s\n", $lev+2, " ", defined($v) ? $v:"undef"); + $sstr .= sprintf("$prefix%*s %s\n", + $lev+2, " ", defined($v) ? $v:"undef"); } } } else { my $v = $h->{$c}; - $str .= sprintf("%*s %-10s %s\n", $lev," ",$c, defined($v) ? $v : ""); + $str .= sprintf("$prefix%*s %-10s %s\n", + $lev," ",$c, defined($v) ? $v : ""); } } delete $h->{".visited"}; @@ -2607,22 +2610,25 @@ CommandList($$) { my ($cl, $param) = @_; my $str = ""; + my %opt; + my $optRegexp = '-r|-R|-i'; + $param = cmd_parseOpts($param, $optRegexp, \%opt); - if($param =~ m/^-r *(.*)$/i) { + if($opt{r} || $opt{R}) { my @list; - my $arg = $1; - if($param =~ m/^-R/) { - return "-R needs a valid device as argument" if(!$arg); - push @list, $arg; - push @list, getPawList($arg); + if($opt{R}) { + return "-R needs a valid device as argument" if(!$param); + push @list, $param; + push @list, getPawList($param); } else { - @list = devspec2array($arg ? $arg : ".*", $cl); + @list = devspec2array($param ? $param : ".*", $cl); } foreach my $d (@list) { return "No device named $d found" if(!defined($defs{$d})); $str .= "\n" if($str); my @a = GetDefAndAttr($d); $str .= join("\n", @a)."\n" if(@a); + $str .= PrintHash($defs{$d}, 2, "#") if($opt{i}); } foreach my $d (sort @list) { $str .= "\n" if($str); diff --git a/fhem/www/pgm2/fhemweb.js b/fhem/www/pgm2/fhemweb.js index 638b26972..1c6cfd012 100644 --- a/fhem/www/pgm2/fhemweb.js +++ b/fhem/www/pgm2/fhemweb.js @@ -132,7 +132,6 @@ FW_jqueryReadyFn() FW_root = r; FW_replaceWidgets($("html")); - FW_confirmDelete(); // Fix the td count by setting colspan on the last column $("table.block.wide").each(function(){ // table @@ -233,26 +232,6 @@ FW_jqueryReadyFn() }); }); - $("div.devSpecHelp a").each(function(){ // Help on detail window - var dev = FW_getLink(this).split("#").pop(); - $(this).unbind("click"); - $(this).attr("href", "#"); // Desktop: show underlined Text - $(this).removeAttr("onclick"); - - $(this).click(function(evt){ - if($("#devSpecHelp").length) { - $("#devSpecHelp").remove(); - return; - } - FW_getHelp(dev, function(data){ - $("#content").append('
'); - $("#devSpecHelp").html(data); - var off = $("#devSpecHelp").position().top-20; - $('body, html').animate({scrollTop:off}, 500); - }); - }); - }); - $("table.attributes tr div.dname") // Click on attribute fills input value .each(function(){ $(this) @@ -315,7 +294,7 @@ FW_jqueryReadyFn() FW_smallScreenCommands(); FW_inlineModify(); - FW_rawDef(); + FW_detLink(); FW_treeMenu(); $("body").attr("data-os", FW_os); @@ -464,48 +443,68 @@ FW_filterIcons() } } + function -FW_confirmDelete() +FW_deleteDevice(dev) { - var b = $("body"); - var cd = $(b).attr("data-confirmDelete"); - if(!cd || cd == 0) + var cmd = addcsrf(FW_root+"?cmd=delete "+dev); + + var cd = $("body").attr("data-confirmDelete"); + if(!cd || cd == 0) { + location.href = cmd; return; - var wn = $(b).attr("data-webName"); - $("div#content").find("a").each(function(){ - var href = $(this).attr("href"); - if(!href) - return; - var ma = $(this).attr("href").match(/.*cmd[^=]*=(delete[^&]*).*$/); - if(!ma || ma.length != 2) - return; - $(this).attr("href", "#"); - $(this).unbind("click"); - $(this).click(function(e){ - e.preventDefault(); + } - var div = $("