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

01_FHEMWEB.pm: Group Attributes (Forum #119289)

git-svn-id: https://svn.fhem.de/fhem/trunk@23898 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2021-03-06 11:05:44 +00:00
parent 6b8750b2d1
commit 85c894431a
3 changed files with 44 additions and 22 deletions

View File

@ -1438,10 +1438,9 @@ FW_makeTable($$$@)
sub
FW_detailSelect(@)
{
my ($d, $cmd, $list, $param) = @_;
my ($d, $cmd, $list, $param, $typeHash) = @_;
return "" if(!$list || $FW_hiddenroom{input});
my %al = map { s/:.*//;$_ => 1 } split(" ", $list);
my @al = sort keys %al; # remove duplicate items in list
my @al = map { s/:.*//; $_ } split(" ", $list);
my $selEl = (defined($al[0]) ? $al[0] : " ");
$selEl = $1 if($list =~ m/([^ ]*):slider,/); # promote a slider if available
@ -1458,7 +1457,7 @@ FW_detailSelect(@)
$ret .= FW_submit("cmd.$cmd$d", $cmd, $cmd.($psc?" psc":""));
$ret .= "<div class=\"$cmd downText\">&nbsp;$d&nbsp;".
($param ? "&nbsp;$param":"")."</div>";
$ret .= FW_select("sel_$cmd$d","arg.$cmd$d",\@al, $selEl, $cmd);
$ret .= FW_select("sel_$cmd$d","arg.$cmd$d",\@al,$selEl,$cmd,undef,$typeHash);
$ret .= FW_textfield("val.$cmd$d", 30, $cmd);
$ret .= "</form></div>";
return $ret;
@ -1542,7 +1541,8 @@ FW_doDetail($)
FW_makeTable("Internals", $d, $h);
FW_makeTable("Readings", $d, $h->{READINGS});
my $attrList = getAllAttr($d);
my %attrTypeHash;
my $attrList = getAllAttr($d, undef, \%attrTypeHash);
my $roomList = "multiple,".join(",",
sort map { $_ =~ s/ /#/g ;$_} keys %FW_rooms);
my $groupList = "multiple,".join(",",
@ -1553,7 +1553,7 @@ FW_doDetail($)
$attrList = FW_widgetOverride($d, $attrList);
$attrList =~ s/\\/\\\\/g;
$attrList =~ s/'/\\'/g;
FW_pO FW_detailSelect($d, "attr", $attrList);
FW_pO FW_detailSelect($d, "attr", $attrList, undef, \%attrTypeHash);
FW_makeTable("Attributes", $d, $attr{$d}, "deleteattr");
FW_makeTableFromArray("Probably associated with", "assoc", getPawList($d));
@ -2273,18 +2273,31 @@ FW_hidden($$)
sub
FW_select($$$$$@)
{
my ($id, $name, $valueArray, $selected, $class, $jSelFn) = @_;
my ($id, $name, $valueArray, $selected, $class, $jSelFn, $typeHash) = @_;
$jSelFn = ($jSelFn ? "onchange=\"$jSelFn\"" : "");
$id =~ s/\./_/g if($id); # to avoid problems in JS DOM Search
$id = ($id ? "id=\"$id\" informId=\"$id\"" : "");
my $s = "<select $jSelFn $id name=\"$name\" class=\"$class\">";
my $oldType="";
my %processed;
foreach my $v (@{$valueArray}) {
next if($processed{$v});
if($typeHash) {
my $newType = $typeHash->{$v};
if($newType ne $oldType) {
$s .= "</optgroup>" if($oldType);
$s .= "<optgroup label='$newType'>" if($newType);
}
$oldType = $newType;
}
if(defined($selected) && $v eq $selected) {
$s .= "<option selected=\"selected\" value='$v'>$v</option>\n";
} else {
$s .= "<option value='$v'>$v</option>\n";
}
$processed{$v} = 1;
}
$s .= "</optgroup>" if($oldType);
$s .= "</select>";
return $s;
}

View File

@ -125,7 +125,7 @@ sub fhem($@);
sub fhemTimeGm($$$$$$);
sub fhemTimeLocal($$$$$$);
sub fhemTzOffset($);
sub getAllAttr($;$);
sub getAllAttr($;$$);
sub getAllGets($;$);
sub getAllSets($;$);
sub getPawList($);
@ -282,7 +282,7 @@ $cvsid = '$Id$';
my $AttrList = "alias comment:textField-long eventMap:textField-long ".
"group room suppressReading userReadings:textField-long ".
"verbose:0,1,2,3,4,5";
"verbose:0,1,2,3,4,5 userattr";
my $currcfgfile=""; # current config/include file
my $currlogfile; # logfile, without wildcards
@ -2735,28 +2735,37 @@ CommandRename($$)
#####################################
sub
getAllAttr($;$)
getAllAttr($;$$)
{
my ($d, $cl) = @_;
my ($d, $cl, $typeHash) = @_;
return "" if(!$defs{$d});
my $list = "";
my $list = $AttrList; # Global values
my $add = sub($$)
{
my ($v,$type) = @_;
return if(!defined($v));
$list .= " " if($list);
$list .= $v;
map { s/:.*//; $typeHash->{$_} = $type } split(" ",$v) if($typeHash);
};
&$add($AttrList, "global");
if($defs{$d}{".AttrList"}) {
$list .= " " . $defs{$d}{".AttrList"};
} elsif($modules{$defs{$d}{TYPE}}{AttrList}) {
$list .= " " . $modules{$defs{$d}{TYPE}}{AttrList};
&$add($defs{$d}{".AttrList"}, "Module");
} else {
&$add($modules{$defs{$d}{TYPE}}{AttrList}, "Module");
}
my $nl2space = sub($)
my $nl2space = sub($$)
{
my $v = $_[0];
my ($v,$type) = @_;
return if(!defined($v));
$v =~ s/\n/ /g;
$list .= " $v";
&$add($v, $type);
};
$nl2space->($attr{global}{userattr});
$nl2space->($attr{$d}{userattr}) if($attr{$d});
$list .= " userattr";
$nl2space->($attr{global}{userattr}, "Global userattr");
$nl2space->($attr{$d}{userattr}, "Device userattr") if($attr{$d});
return $list;
}

View File

@ -735,7 +735,7 @@ f18_setCss(why)
function bg(c) { return "{ background:#"+c+"; fill:#"+c+"; }\n" }
function fg(c) { return "{ color:#"+c+"; }\n" }
style += ".col_fg, body, input, textarea "+fg(col("fg"));
style += ".col_bg, textarea, input, option "+bg(col("bg"));
style += ".col_bg, textarea, input, option, optgroup "+bg(col("bg"));
style += ".col_link,a:not(.changed),.handle,.fhemlog,input[type=submit],"+
"select,div.ui-widget-content a "+
"{color:#"+col("link")+"!important; stroke:#"+col("link")+";}\n";