2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

notify/at: add a simple command wizard.

git-svn-id: https://svn.fhem.de/fhem/trunk@13630 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2017-03-06 21:05:08 +00:00
parent 0b16da548b
commit bd7c95af12
3 changed files with 107 additions and 24 deletions

View File

@ -341,23 +341,22 @@ at_fhemwebFn($$$$)
my $isPerl = ($ts =~ m/^{(.*)}/);
$ts = $1 if($isPerl);
return "<br>Timespec wizard:".
"<table id='atWizard' nm='$hash->{NAME}' ts='$ts' rl='$hash->{RELATIVE}' ".
my $h1 = "<br>Change Wizard:".
"<table class='block wide' id='atWizard' nm='$hash->{NAME}' ts='$ts' ".
"rl='$hash->{RELATIVE}' ".
"pr='$hash->{PERIODIC}' ip='$isPerl' class='block wide'>".<<'EOF';
<tr class="even">
<td>Relative &nbsp; <input type="checkbox" id="aw_rl" value="yes"></td>
<td>Periodic &nbsp; <input type="checkbox" id="aw_pr" value="yes"></td>
</tr><tr class="odd"><td>Use perl function for timespec</td>
<td><input type="checkbox" id="aw_ip"></td>
</tr><tr class="even"><td>Timespec</td>
<td><input type="text" name="aw_pts"></td>
</tr><tr class="even"><td>Timespec</td>
<td><input type="text" name="aw_ts" size="5"></td>
<tr class="even"><td>Change the timespec:</td></tr>
<tr class="odd">
<td>Relative <input type="checkbox" id="aw_rl" value="yes">&nbsp;
Periodic <input type="checkbox" id="aw_pr" value="yes">&nbsp;
Use perl function for timespec <input type="checkbox" id="aw_ip"></td>
</tr><tr class="even"><td><input type="text" name="aw_pts"></td>
</tr><tr class="even"><td><input type="text" name="aw_ts"></td>
</tr><tr class="odd"><td><input type="button" id="aw_md" value="Modify"></td>
</tr>
</tr><tr class="even">
<td colspan="2"><input type="button" id="aw_md" value="Modify"></td>
</tr>
</table>
EOF
my $j1 = << 'EOF';
<script type="text/javascript">
{
var t=$("#atWizard"), ip=$(t).attr("ip"), ts=$(t).attr("ts");
@ -390,6 +389,11 @@ return "<br>Timespec wizard:".
}
</script>
EOF
my @d = split(" ",$hash->{DEF},2);
LoadModule("notify");
my ($h2, $j2) = notfy_addFWCmd($d, $d[0], 2);
return "$h1$h2</table><br>$j1$j2";
}
1;

View File

@ -220,13 +220,14 @@ notify_fhemwebFn($$$$)
my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
my $hash = $defs{$d};
my $ret .= "<br>Regexp wizard";
my $row=0;
$ret .= "<br><table class=\"block wide\">";
my $ret .= "Change wizard<br><table class='block wide'>";
my $row = 0;
my @ra = split(/\|/, $hash->{REGEXP});
$ret .= "<tr class='".(($row++&1)?"odd":"even").
"'><td colspan='2'>Change the condition:</td></tr>";
if(@ra > 1) {
foreach my $r (@ra) {
$ret .= "<tr class=\"".(($row++&1)?"odd":"even")."\">";
$ret .= "<tr class='".(($row++&1)?"odd":"even")."'>";
my $cmd = "cmd.X= set $d removeRegexpPart&val.X=$r"; # =.set: avoid JS
$ret .= "<td>$r</td>";
$ret .= FW_pH("$cmd&detail=$d", "removeRegexpPart", 1,undef,1);
@ -236,9 +237,10 @@ notify_fhemwebFn($$$$)
my @et = devspec2array("TYPE=eventTypes");
if(!@et) {
$ret .= "<tr class='".(($row++&1)?"odd":"even")."'>";
$ret .= FW_pH("$FW_ME/docs/commandref.html#eventTypes",
"To add a regexp an eventTypes definition is needed",
1, undef, 1);
1, undef, 1)."</tr>";
} else {
my %dh;
my $etList = AnalyzeCommand(undef, "get $et[0] list");
@ -263,9 +265,88 @@ notify_fhemwebFn($$$$)
$ret .= FW_detailSelect($d, "set", $list, "addRegexpPart");
$ret .= "</td></tr>";
}
$ret .= "</table>";
my ($tr, $js) = notfy_addFWCmd($d, $hash->{REGEXP}, $row);
return "$ret$tr</table><br>$js";
}
return $ret;
sub
notfy_addFWCmd($$$)
{
my ($d, $param, $row) = @_;
my $ret="";
$ret .= "<tr class='".(($row++&1)?"odd":"even")."'><td colspan='2'>".
"&nbsp;</td></tr>";
$ret .= "<tr class='".(($row++&1)?"odd":"even")."'><td colspan='2'>".
"Change the executed command:</td></tr>";
$ret .= "<tr class='".(($row++&1)?"odd":"even")."'><td colspan='2'>";
my @list = grep { !$defs{$_}{TEMPORARY} && $_ ne $d &&
$modules{$defs{$_}{TYPE}}{SetFn} } sort keys %defs;
$ret .= "<input class='set' id='modCmd' type='submit' value='modify' ".
"data-d='$d' data-p='$param'>";
$ret .= "<div class='set downText'>&nbsp;$d $param set </div>";
$ret .= FW_select("modDev", "mod", \@list, undef, "set");
$ret .= "<select class='set' id='modArg'></select>";
$ret .= "<input type='text' name='modVal' size='10'/>";
$ret .= "</td></tr>";
my $js = << 'END';
<script>
var ntArr, ntDev;
function
ntfyCmd()
{
ntDev=$("#modDev").val();
FW_cmd(FW_root+
"?cmd="+addcsrf(encodeURIComponent("set "+ntDev+" ?"))+"&XHR=1",
function(ret) {
ret = ret.replace(/[\r\n]/g,'');
ntArr=ret.substr(ret.indexOf("choose one of")+14,ret.length).split(" ");
var str="";
for(var i1=0; i1<ntArr.length; i1++) {
var off = ntArr[i1].indexOf(":");
str += "<option value="+i1+">"+
(off==-1 ? ntArr[i1] : ntArr[i1].substr(0,off))+
"</option>";
}
$("#modArg").html(str);
ntfyArg();
});
}
function
ntfyArg()
{
var v=ntArr[$("#modArg").val()];
var vArr = [];
if(v.indexOf(":") > 0)
vArr = v.substr(v.indexOf(":")+1).split(",");
FW_replaceWidget($("#modArg").next(), ntDev, vArr);
}
function
ntfyGo()
{
var d=$("#modCmd").attr("data-d");
var p=$("#modCmd").attr("data-p");
var cmd = "modify "+d+" "+p+" set "+$("#modDev").val()+" "+
$("#modArg :selected").text()+" "+$("[name=modVal]").val();
location=FW_root+"?cmd="+addcsrf(encodeURIComponent(cmd))+"&detail="+d;
}
$(document).ready(function(){
$("#modDev").change(ntfyCmd);
$("#modArg").change(ntfyArg);
$("#modCmd").click(ntfyGo);
$("#").change(ntfyArg);
ntfyCmd();
});
</script>
END
return ($ret, $js);
}
1;

View File

@ -93,8 +93,6 @@ svg.on,svg.FS20_on { fill:orange!important; }
border-color:transparent; }
.rc_button img:active { border-color: gray; }
table#atWizard td:first-child { width: 240px; }
/* jQuery-UI mods */
div.ui-dialog { border:3px solid #278727; padding: 0.2em; }
div.ui-dialog div.ui-dialog-titlebar { display:none; }