2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-21 01:46:08 +00:00

FHEMWEB: textField by justme1968

git-svn-id: https://svn.fhem.de/fhem/trunk@3922 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2013-09-18 11:45:00 +00:00
parent 4b5bfc2d6a
commit a1beda9398
2 changed files with 60 additions and 2 deletions

View File

@ -137,7 +137,8 @@ FHEMWEB_Initialize($)
$data{webCmdFn}{slider} = "FW_sliderFn"; $data{webCmdFn}{slider} = "FW_sliderFn";
$data{webCmdFn}{timepicker} = "FW_timepickerFn"; $data{webCmdFn}{timepicker} = "FW_timepickerFn";
$data{webCmdFn}{noArg} = "FW_noArg"; $data{webCmdFn}{noArg} = "FW_noArgFn";
$data{webCmdFn}{textField} = "FW_textFieldFn";
$data{webCmdFn}{"~dropdown"}= "FW_dropdownFn"; # Should be the last $data{webCmdFn}{"~dropdown"}= "FW_dropdownFn"; # Should be the last
} }
@ -2147,6 +2148,8 @@ FW_htmlEscape($)
return $txt; return $txt;
} }
###########################
# Widgets START
sub sub
FW_sliderFn($$$$$) FW_sliderFn($$$$$)
{ {
@ -2173,7 +2176,7 @@ FW_sliderFn($$$$$)
} }
sub sub
FW_noArg($$$$$) FW_noArgFn($$$$$)
{ {
my ($FW_wname, $d, $FW_room, $cmd, $values) = @_; my ($FW_wname, $d, $FW_room, $cmd, $values) = @_;
@ -2234,6 +2237,29 @@ FW_dropdownFn()
return undef; return undef;
} }
sub
FW_textFieldFn($$$$)
{
my ($FW_wname, $d, $FW_room, $cmd, $values) = @_;
my @args = split("[ \t]+", $cmd);
return undef if($values !~ m/^textField$/);
return "" if($cmd =~ m/ /);
my $srf = $FW_room ? "&room=$FW_room" : "";
my $cv = ReadingsVal($d, $cmd, "");
my $id = ($cmd eq "state") ? "" : "-$cmd";
my $c = "$FW_ME?XHR=1&cmd=setreading $d $cmd %$srf";
return '<td align="center">'.
"<div>$cmd:<input id='textField.$d$id' type='text' value='$cv' ".
"onChange='textField_setText(this,\"$c\")'></div>".
'</td>';
}
# Widgets END
###########################
sub sub
FW_ActivateInform() FW_ActivateInform()
{ {
@ -2642,6 +2668,7 @@ FW_ActivateInform()
displayed </li> displayed </li>
<li>if the modifier is ":time", then a javascript driven timepicker is <li>if the modifier is ":time", then a javascript driven timepicker is
displayed.</li> displayed.</li>
<li>if the modifier is ":textField", an input field is displayed.</li>
<li>if the modifier is of the form <li>if the modifier is of the form
":slider,&lt;min&gt;,&lt;step&gt;,&lt;max&gt;", then a javascript ":slider,&lt;min&gt;,&lt;step&gt;,&lt;max&gt;", then a javascript
driven slider is displayed</li> driven slider is displayed</li>

View File

@ -0,0 +1,31 @@
function
FW_textFieldUpdateLine(d)
{
var name = "textField."+d[0];
//console.log("Cmd "+d);
el = document.getElementById(name);
if(el) {
el.value = d[1];
}
}
function
textField_setText(el,cmd)
{
var v = el.value;
//console.log("Got "+v);
//console.log("Cmd "+cmd);
var req = new XMLHttpRequest();
req.open("GET", cmd.replace('%',v), true);
req.send(null);
}
FW_widgets['textField'] = {
updateLine:FW_textFieldUpdateLine
};