mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
AttrTemplate.pm: add order and "online" help (Forum #94495)
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@20206 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a24650ef4a
commit
52a2f4e656
@ -89,6 +89,7 @@ use vars qw(%FW_visibleDeviceHash);
|
|||||||
use vars qw(@FW_httpheader); # HTTP header, line by line
|
use vars qw(@FW_httpheader); # HTTP header, line by line
|
||||||
use vars qw(%FW_httpheader); # HTTP header, as hash
|
use vars qw(%FW_httpheader); # HTTP header, as hash
|
||||||
use vars qw($FW_userAgent); # user agent string
|
use vars qw($FW_userAgent); # user agent string
|
||||||
|
use vars qw($FW_addJs); # Only for helper like AttrTemplate
|
||||||
|
|
||||||
$FW_formmethod = "post";
|
$FW_formmethod = "post";
|
||||||
|
|
||||||
@ -1064,6 +1065,7 @@ FW_answerCall($)
|
|||||||
my $n = $_; $n =~ s+.*/++; $n =~ s/.js$//; $n =~ s/fhem_//; $n .= "Param";
|
my $n = $_; $n =~ s+.*/++; $n =~ s/.js$//; $n =~ s/fhem_//; $n .= "Param";
|
||||||
FW_pO sprintf($jsTemplate, AttrVal($FW_wname, $n, ""), "$FW_ME/$_");
|
FW_pO sprintf($jsTemplate, AttrVal($FW_wname, $n, ""), "$FW_ME/$_");
|
||||||
} @jsList;
|
} @jsList;
|
||||||
|
FW_pO $FW_addJs if($FW_addJs);
|
||||||
|
|
||||||
########################
|
########################
|
||||||
# FW Extensions
|
# FW Extensions
|
||||||
|
@ -5,6 +5,7 @@ package main;
|
|||||||
my %templates;
|
my %templates;
|
||||||
my $initialized;
|
my $initialized;
|
||||||
my %cachedUsage;
|
my %cachedUsage;
|
||||||
|
use vars qw($FW_addJs); # Only for helper like AttrTemplate
|
||||||
|
|
||||||
sub
|
sub
|
||||||
AttrTemplate_Initialize()
|
AttrTemplate_Initialize()
|
||||||
@ -68,6 +69,9 @@ AttrTemplate_Initialize()
|
|||||||
} elsif($line =~ m/^farewell:(.*)/) {
|
} elsif($line =~ m/^farewell:(.*)/) {
|
||||||
$templates{$name}{farewell} = $1;
|
$templates{$name}{farewell} = $1;
|
||||||
|
|
||||||
|
} elsif($line =~ m/^order:(.*)/) {
|
||||||
|
$templates{$name}{order} = $1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
push(@{$templates{$name}{cmds}}, $line);
|
push(@{$templates{$name}{cmds}}, $line);
|
||||||
|
|
||||||
@ -80,9 +84,52 @@ AttrTemplate_Initialize()
|
|||||||
delete($templates{$name});
|
delete($templates{$name});
|
||||||
}
|
}
|
||||||
|
|
||||||
my $nr = (int keys %templates);
|
@templates = sort {
|
||||||
|
my $ao = $templates{$a}{order};
|
||||||
|
my $bo = $templates{$b}{order};
|
||||||
|
$ao = (defined($ao) ? $ao : $a);
|
||||||
|
$bo = (defined($bo) ? $bo : $b);
|
||||||
|
return $ao cmp $bo;
|
||||||
|
} keys %templates;
|
||||||
|
|
||||||
|
my $nr = @templates;
|
||||||
$initialized = 1;
|
$initialized = 1;
|
||||||
Log 2, "AttrTemplates: got $nr entries" if($nr);
|
Log 2, "AttrTemplates: got $nr entries" if($nr);
|
||||||
|
$FW_addJs = "" if(!defined($FW_addJs));
|
||||||
|
$FW_addJs .= << 'JSEND';
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function() {
|
||||||
|
$("select.set").change(attrAct);
|
||||||
|
function
|
||||||
|
attrAct(){
|
||||||
|
if($("select.set").val() == "attrTemplate") {
|
||||||
|
$('<div id="attrTemplateHelp" class="makeTable help"></div>')
|
||||||
|
.insertBefore("div.makeTable.internals");
|
||||||
|
$("select.select_widget[informid$=attrTemplate]").change(function(){
|
||||||
|
var cmd = "{AttrTemplate_Help('"+$(this).val()+"')}";
|
||||||
|
FW_cmd(FW_root+"?cmd="+cmd+"&XHR=1", function(ret) {
|
||||||
|
$("div#attrTemplateHelp").html(ret);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$("div#attrTemplateHelp").remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attrAct();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
JSEND
|
||||||
|
}
|
||||||
|
|
||||||
|
sub
|
||||||
|
AttrTemplate_Help($)
|
||||||
|
{
|
||||||
|
my ($n) = @_;
|
||||||
|
return "" if(!$templates{$n});
|
||||||
|
my $ret = "";
|
||||||
|
$ret = $templates{$n}{desc} if($templates{$n}{desc});
|
||||||
|
$ret .= "<br><pre>".join("\n",@{$templates{$n}{cmds}})."</pre>";
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
@ -100,7 +147,7 @@ AttrTemplate_Set($$@)
|
|||||||
if($cmd ne "attrTemplate") {
|
if($cmd ne "attrTemplate") {
|
||||||
if(!$cachedUsage{$name}) {
|
if(!$cachedUsage{$name}) {
|
||||||
my @list;
|
my @list;
|
||||||
for my $k (sort keys %templates) {
|
for my $k (@templates) {
|
||||||
my $h = $templates{$k};
|
my $h = $templates{$k};
|
||||||
my $matches;
|
my $matches;
|
||||||
$matches = devspec2array($h->{filter}, undef, [$name]) if($h->{filter});
|
$matches = devspec2array($h->{filter}, undef, [$name]) if($h->{filter});
|
||||||
@ -121,7 +168,7 @@ AttrTemplate_Set($$@)
|
|||||||
|
|
||||||
if($entry eq "?") {
|
if($entry eq "?") {
|
||||||
my @hlp;
|
my @hlp;
|
||||||
for my $k (sort keys %templates) {
|
for my $k (@templates) {
|
||||||
my $h = $templates{$k};
|
my $h = $templates{$k};
|
||||||
my $matches;
|
my $matches;
|
||||||
$matches = devspec2array($h->{filter}, undef, [$name]) if($h->{filter});
|
$matches = devspec2array($h->{filter}, undef, [$name]) if($h->{filter});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user