2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

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
This commit is contained in:
rudolfkoenig 2022-10-28 12:09:44 +00:00
parent 5c531ee3b4
commit 1b6af60580
3 changed files with 146 additions and 102 deletions

View File

@ -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 "<div class='detLink'>";
FW_pO "<select id='moreCmds'>";
FW_pO "<option >More...</option>";
FW_pO "<option data-cmd='forumCopy $d'>Copy for forum.fhem.de</option>";
FW_pO "<option >...</option>";
FW_pO "<option data-cmd='rawDef $d'>Raw definition</option>";
FW_pO "<option data-cmd='style iconFor $d'>Select icon</option>";
FW_pO "<option data-cmd='style showDSI $d'>Extend devStateIcon</option>";
if($d ne "global") {
FW_pO "<option data-cmd='delete $d'>Delete $d</option>";
FW_pO "<option data-cmd='rename $d'>Rename $d</option>";
}
FW_pO "</select>";
FW_pO "</div>";

View File

@ -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);

View File

@ -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>");
$(div).html("Do you really want to delete "+dev+"?<br><br>"+
$(div).html("Do you really want to "+cmd+"?<br><br>"+
"<input type='checkbox' name='noconf'> 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=$("<a style='cursor:pointer'>NAME</a>");
$(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('<div id="devSpecHelp"></div>');
$("#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('<div id="rawDef">'+
'<textarea id="td_rawDef" rows="25" cols="60" style="width:99%; '+
textAreaStyle+'"/>'+
'<button>Execute commands</button>'+
' Dump "Probably associated with" too <input type="checkbox">'+
' Dump "Probably associated with" too '+
'<input class="paw" type="checkbox">'+
' With internals <input class="int" type="checkbox">'+
'<br><br></div>');
var cmVar;
@ -943,7 +1051,8 @@ FW_detLink()
var propertychange = function() {
var nData = $("#rawDef textarea").val();
if(nData != data)
if(nData != data &&
!$("body").attr("data-hiddenroom").match(/\binput\b/))
$("#rawDef button").show();
else
$("#rawDef button").hide();
@ -967,82 +1076,14 @@ FW_detLink()
});
}
fillData("-r");
$("#rawDef input").click(function(){fillData(this.checked ?"-R":"-r")});
$("#rawDef input").click(function(){
fillData(
($("input.paw").is(":checked") ? "-R" : "-r")+
($("input.int").is(":checked") ? " -i" : ""));
});
$("#rawDef button").click(function(){
FW_execRawDef($("#rawDef textarea").val());
});
});
});
$("#detLink .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('<div id="devSpecHelp"></div>');
$("#devSpecHelp").html(data);
var off = $("#devSpecHelp").position().top-20;
$('body, html').animate({scrollTop:off}, 500);
});
});
});
$("#detLink select#moreCmds").change(function(){
var cmd = $(this).find("option:selected").attr("data-cmd");
if(!cmd)
return;
var m = cmd.match(/^([^ ]+) (.*)$/);
if(!m)
return;
if(m[1] == "forumCopy") {
FW_cmd(FW_root+"?cmd=list -r -i "+m[2]+"&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;
ta.style.top = ta.style.left = "0";
ta.style.position = "fixed";
document.body.appendChild(ta);
ta.focus();
ta.select();
try {
if(document.execCommand('copy'))
FW_okDialog(okTxt);
else
FW_okDialog(errTxt);
} catch (err) {
log('Copy:'+err);
FW_okDialog(errTxt+err);
}
document.body.removeChild(ta);
}
});
} else if(m[1] == "rename") {
FW_renameDevice(m[2]);
} else if(m[1] == "delete") {
FW_deleteDevice(m[2]);
} else {
location.href = addcsrf(FW_root+"?cmd="+cmd);