From fb6178754444ff44ed10fbdce066a60740d4d16f Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Mon, 16 Feb 2015 06:42:31 +0000 Subject: [PATCH] fhemweb.js: add devStateIcon okDialog widgets (Forum #33766) git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@8003 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/01_FHEMWEB.pm | 32 ++++++++++++++++++++++++++++-- fhem/www/pgm2/fhemweb.js | 43 +++++++++++++++++++++++++++------------- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm index 580f381f6..5d03ab817 100755 --- a/fhem/FHEM/01_FHEMWEB.pm +++ b/fhem/FHEM/01_FHEMWEB.pm @@ -2404,7 +2404,7 @@ FW_devState($$@) my ($hasOnOff, $link); my $cmdList = AttrVal($d, "webCmd", ""); - my $allSets = getAllSets($d); + my $allSets = FW_widgetOverride($d, getAllSets($d)); my $state = $defs{$d}{STATE}; $state = "" if(!defined($state)); @@ -2431,7 +2431,35 @@ FW_devState($$@) my ($icon, $isHtml); ($icon, $link, $isHtml) = FW_dev2image($d); $txt = ($isHtml ? $icon : FW_makeImage($icon, $state)) if($icon); - $link = "cmd.$d=set $d $link" if(defined($link)); + + my $cmdlist = $link // ""; + my $h = ""; + foreach my $cmd (split(":", $cmdlist)) { + my $htmlTxt; + my @c = split(' ', $cmd); # @c==0 if $cmd==" "; + if(int(@c) && $allSets && $allSets =~ m/\b$c[0]:([^ ]*)/) { + my $values = $1; + foreach my $fn (sort keys %{$data{webCmdFn}}) { + no strict "refs"; + $htmlTxt = &{$data{webCmdFn}{$fn}}($FW_wname, + $d, $FW_room, $cmd, $values); + use strict "refs"; + last if(defined($htmlTxt)); + } + } + + if( $htmlTxt ) { + $h .= "

$htmlTxt

"; + } + } + + if( $h ) { + $link = undef; + $h =~ s/'/\\"/g; + $txt = "$txt"; + } else { + $link = "cmd.$d=set $d $link" if(defined($link)); + } } diff --git a/fhem/www/pgm2/fhemweb.js b/fhem/www/pgm2/fhemweb.js index 38751925a..c80b2b4a7 100644 --- a/fhem/www/pgm2/fhemweb.js +++ b/fhem/www/pgm2/fhemweb.js @@ -29,6 +29,23 @@ window.onbeforeunload = function(e) return undefined; } +function +FW_replaceWidgets(parent) +{ + parent.find("div.fhemWidget").each(function() { + var dev=$(this).attr("dev"); + var cmd=$(this).attr("cmd"); + var rd=$(this).attr("reading"); + var params = cmd.split(" "); + FW_replaceWidget(this, dev, $(this).attr("arg").split(","), + $(this).attr("current"), rd, params[0], params.slice(1), + function(arg) { + FW_cmd(FW_root+"?cmd=set "+dev+(params[0]=="state" ? "":" "+params[0])+ + " "+arg+"&XHR=1"); + }); + }); +} + function FW_jqueryReadyFn() { @@ -67,19 +84,8 @@ FW_jqueryReadyFn() var r = $("head").attr("root"); if(r) FW_root = r; - $("div.fhemWidget").each(function() { - var dev=$(this).attr("dev"); - var cmd=$(this).attr("cmd"); - var rd=$(this).attr("reading"); - var params = cmd.split(" "); - FW_replaceWidget(this, dev, $(this).attr("arg").split(","), - $(this).attr("current"), rd, params[0], params.slice(1), - function(arg) { - FW_cmd(FW_root+"?cmd=set "+dev+(params[0]=="state" ? "":" "+params[0])+ - " "+arg+"&XHR=1"); - }); - }); + FW_replaceWidgets($("html")); // Fix the td count by setting colspan on the last column $("table.block.wide").each(function(){ // table @@ -115,8 +121,9 @@ FW_jqueryReadyFn() $("#saveCheck") .css("cursor", "pointer") .click(function(){ + var parent = this; FW_cmd(FW_root+"?cmd=save ?&XHR=1", function(data) { - FW_okDialog('
'+data+'
'); + FW_okDialog('
'+data+'
',parent); }); }); @@ -217,7 +224,7 @@ FW_errmsg(txt, timeout) } function -FW_okDialog(txt) +FW_okDialog(txt, parent) { var div = $("
"); $(div).html(txt); @@ -230,6 +237,14 @@ FW_okDialog(txt) $(div).remove(); }}] }); + + FW_replaceWidgets(div); + + if(parent) + $(div).dialog( "option", "position", { + my: "left top", at: "right bottom", + of: parent, collision: "flipfit" + }); } function