From 452212864944e41a9cd3fec55b15f705c5442cc4 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Fri, 28 Oct 2022 12:09:44 +0000 Subject: [PATCH] fhemweb.js: detail bottom row reorganization, 3rd try (Forum #129858) git-svn-id: https://svn.fhem.de/fhem/trunk@26608 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/01_FHEMWEB.pm | 8 +- fhem/fhem.pl | 27 ++--- fhem/www/pgm2/fhemweb.js | 213 +++++++++++++++++++++++---------------- 3 files changed, 146 insertions(+), 102 deletions(-) diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm index 26fdfbaa5..f81f076b1 100644 --- a/fhem/FHEM/01_FHEMWEB.pm +++ b/fhem/FHEM/01_FHEMWEB.pm @@ -1246,6 +1246,7 @@ FW_dataAttr() addParam($FW_wname, "confirmJSError", 1). addParam($FW_wname, "addHtmlTitle", 1). addParam($FW_wname, "styleData", ""). + addParam($FW_wname, "hiddenroom", ""). addParam("global", "language", "EN"). "data-availableJs='$FW_fhemwebjs' ". "data-webName='$FW_wname' "; @@ -1613,16 +1614,15 @@ FW_doDetail($) $sfx = ($sfx eq "EN" ? "" : "_$sfx"); FW_pH "$FW_ME/docs/commandref${sfx}.html#$t", "Help for $t", undef, "detLink devSpecHelp"; - FW_pH "cmd=rawDef $d", "Raw definition", undef, "detLink rawDef"; + FW_pH "cmd=forumCopy $d", "Copy for forum.fhem.de", undef,"detLink forumCopy"; FW_pO ""; diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 7283673b1..eb9cf22ef 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,39 +2564,38 @@ CommandSetReading($$) ############# sub -PrintHash($$;$) +PrintHash($$) { - my ($h, $lev, $prefix) = @_; + my ($h, $lev) = @_; 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("$prefix%*s %-19s %-15s %s\n", + $str .= sprintf("%*s %-19s %-15s %s\n", $lev," ", $h->{$c}{TIME},$c,$h->{$c}{VAL}); } elsif($c eq "IODev" || $c eq "HASH") { - $str .= sprintf("$prefix%*s %-10s %s\n", $lev," ",$c, $h->{$c}{NAME}); + $str .= sprintf("%*s %-10s %s\n", $lev," ",$c, $h->{$c}{NAME}); } else { - $sstr .= sprintf("$prefix%*s %s:\n", $lev, " ", $c); - $sstr .= PrintHash($h->{$c}, $lev+2, $prefix); + $sstr .= sprintf("%*s %s:\n", $lev, " ", $c); + $sstr .= PrintHash($h->{$c}, $lev+2); } } elsif(ref($h->{$c}) eq "ARRAY") { - $sstr .= sprintf("$prefix%*s %s:\n", $lev, " ", $c); + $sstr .= sprintf("%*s %s:\n", $lev, " ", $c); foreach my $v (@{$h->{$c}}) { - $sstr .= sprintf("$prefix%*s %s\n", + $sstr .= sprintf("%*s %s\n", $lev+2, " ", defined($v) ? $v:"undef"); } } } else { my $v = $h->{$c}; - $str .= sprintf("$prefix%*s %-10s %s\n", + $str .= sprintf("%*s %-10s %s\n", $lev," ",$c, defined($v) ? $v : ""); } } @@ -2628,7 +2627,11 @@ CommandList($$) $str .= "\n" if($str); my @a = GetDefAndAttr($d); $str .= join("\n", @a)."\n" if(@a); - $str .= PrintHash($defs{$d}, 2, "#") if($opt{i}); + if($opt{i}) { + my $intHash = PrintHash($defs{$d}, 2); + $intHash =~ s/\n/\n#/g; + $str .= "#".$intHash; + } } foreach my $d (sort @list) { $str .= "\n" if($str); diff --git a/fhem/www/pgm2/fhemweb.js b/fhem/www/pgm2/fhemweb.js index d79263885..488defaa3 100644 --- a/fhem/www/pgm2/fhemweb.js +++ b/fhem/www/pgm2/fhemweb.js @@ -132,6 +132,7 @@ 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 @@ -445,18 +446,22 @@ FW_filterIcons() function -FW_deleteDevice(dev) +FW_delete(cmd, fCmd) { - var cmd = addcsrf(FW_root+"?cmd=delete "+dev); + if($("body").attr("data-hiddenroom").match(/\binput\b/)) + return FW_okDialog("Disabled"); + + if(!fCmd) + fCmd = addcsrf(FW_root+"?cmd="+cmd); var cd = $("body").attr("data-confirmDelete"); if(!cd || cd == 0) { - location.href = cmd; + location.href = fCmd; return; } var div = $("
"); - $(div).html("Do you really want to delete "+dev+"?

"+ + $(div).html("Do you really want to "+cmd+"?

"+ " Skip this dialog in the future"); $("body").append(div); @@ -464,7 +469,7 @@ FW_deleteDevice(dev) dialogClass:"no-close", modal:true, width:"auto", closeOnEscape:true, maxWidth:$(window).width()*0.9, maxHeight:$(window).height()*0.9, buttons: [ - {text:"Yes", click:function(){ doClose(); location.href = cmd; }}, + {text:"Yes", click:function(){ doClose(); location.href = fCmd; }}, {text:"No", click:doClose} ], close: doClose }); @@ -479,6 +484,27 @@ FW_deleteDevice(dev) } } +// For all the links starting with delete (deleteattr, etc) +function +FW_confirmDelete() +{ + var b = $("body"); + var cd = $(b).attr("data-confirmDelete"); + if(!cd || cd == 0) + 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; + FW_removeLink(this); + $(this).click(function(e){ FW_delete(ma[1], ma[0]) }); + }); +} + function FW_renameDevice(dev) { @@ -843,6 +869,17 @@ FW_inlineModify() // Do not generate a new HTML page upon pressing modify AddCodeMirror(s[0], function(pcm) {cm = pcm;}); } }); + + if(!$("body").attr("data-hiddenroom").match(/\binput\b/)) { + $("table.internals div.dname").each(function(){ + if($(this).text() == "NAME") { + var dev = $(this).attr("data-name"); + var a=$("NAME"); + $(this).html(a); + a.click(function(){ FW_renameDevice(dev) }); + } + }); + } // Set and attr $("div input.psc[type=submit]:not(.get)").click(function(e){ @@ -901,28 +938,99 @@ FW_inlineModify() // Do not generate a new HTML page upon pressing modify }); } + +function +FW_removeLink(el) +{ + $(el).unbind("click"); + $(el).attr("href", "#"); // Desktop: show underlined Text + $(el).removeAttr("onclick"); // smallscreen style +} + // Fill the "detLink" line with life function FW_detLink() { - $("div.rawDef a").each(function(){ // Help on detail window - var dev = FW_getLink(this).split(" ").pop().split("&")[0]; - $(this).unbind("click"); - $(this).attr("href", "#"); // Desktop: show underlined Text - $(this).removeAttr("onclick"); + $("div.forumCopy a").each(function(){ + if(FW_isiOS) { // Copy does not work :( + $(this).parent().remove(); + return; + } + var dev = FW_getLink(this).match(/cmd=forumCopy ([^&]*)/)[1]; + FW_removeLink(this); $(this).click(function(evt){ + FW_cmd(FW_root+"?cmd=list -r -i "+dev+"&XHR=1", function(data) { + data = '[code]'+data+'[/code]'; + var okTxt = '"forum ready" definition copied to the clipboard.'; + var errTxt = 'Could not copy the text: '; + var ok; + if(navigator.clipboard) { + navigator.clipboard.writeText(data).then( + function(){ FW_okDialog(okTxt) }, + function(err){ FW_okDialog(errTxt+err) }); + + } else { + var ta = document.createElement("textarea"); + ta.value = data; + document.body.appendChild(ta); + ta.select(); + if(document.execCommand('copy')) + FW_okDialog(okTxt); + else + FW_okDialog(errTxt+"reason unknown"); + document.body.removeChild(ta); + } + }); + return false; + }); + }); + + $("#detLink .devSpecHelp a").each(function(){ // Help on detail window + var dev = FW_getLink(this).split("#").pop(); + FW_removeLink(this); + + $(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); + }); + }); + }); + + + $("#detLink select#moreCmds").click(function(){ + var cmd = $(this).find("option:selected").attr("data-cmd"); + if(!cmd) + return; + var m = cmd.match(/^([^ ]+) (.*)$/); + if(!m) + return; + + if(m[1] == "delete") { + FW_delete("delete "+m[2]); + + } else if(m[1] == "rawDef") { + var dev = m[2]; if($("#rawDef").length) { $("#rawDef").remove(); return; } - var textAreaStyle = typeof AddCodeMirror == 'function'?'opacity:0':''; + var textAreaStyle = typeof AddCodeMirror == 'function'?'opacity:0':''; $("#content").append('
'+ '