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

01_FHEMWEB.pm: detailLinks attribute added (Forum #129858)

git-svn-id: https://svn.fhem.de/fhem/trunk@26617 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2022-10-29 11:17:51 +00:00
parent 46db7c5684
commit 39dd10e9a9
2 changed files with 78 additions and 66 deletions

View File

@ -166,6 +166,7 @@ FHEMWEB_Initialize($)
confirmDelete:0,1
confirmJSError:0,1
defaultRoom
detailLinks
deviceOverview:always,iconOnly,onClick,never
editConfig:1,0
editFileList:textField-long
@ -1610,22 +1611,29 @@ FW_doDetail($)
my ($link, $txt, $td, $class, $doRet,$nonl) = @_;
FW_pO "<div id='detLink'>";
my $sfx = AttrVal("global", "language", "EN");
$sfx = ($sfx eq "EN" ? "" : "_$sfx");
FW_pH "$FW_ME/docs/commandref${sfx}.html#$t", "Help for $t",
undef, "detLink devSpecHelp";
FW_pH "cmd=forumCopy $d", "Copy for forum.fhem.de", undef,"detLink forumCopy";
FW_pO "<div class='detLink'>";
FW_pO "<select id='moreCmds'>";
FW_pO "<option >...</option>";
FW_pO "<option data-cmd='rawDef $d'>Raw definition</option>";
FW_pO "<option data-cmd='style iconFor $d'>Select icon</option>";
FW_pO "<option data-cmd='style showDSI $d'>Extend devStateIcon</option>";
if($d ne "global") {
FW_pO "<option data-cmd='delete $d'>Delete $d</option>";
my @detCmd = (
'devSpecHelp', "Help for $t",
'forumCopy', 'Copy for forum.fhem.de',
'rawDef', 'Raw definition',
'style iconFor', 'Select icon',
'style showDSI', 'Extend devStateIcon',
'delete', "Delete $d"
);
my $lNum = AttrVal($FW_wname, "detailLinks", 2);
my $li = 0;
while($li < $lNum && $li < @detCmd / 2) {
FW_pH "cmd=$detCmd[2*$li] $d", $detCmd[2*$li+1], undef, "detLink";
$li++;
}
if($li < @detCmd/2) {
FW_pO "<select id='moreCmds'>";
FW_pO "<option >...</option>";
while($li < @detCmd / 2) {
FW_pO "<option data-cmd='$detCmd[2*$li] $d'>$detCmd[2*$li+1]</option>";
$li++;
}
FW_pO "</select>"
}
FW_pO "</select>";
FW_pO "</div>";
FW_pO "<br><br>";
FW_pO "</div>";
}
@ -3896,6 +3904,13 @@ FW_log($$)
</li>
<br>
<a id="FHEMWEB-attr-detailLinks"></a>
<li>detailLinks<br>
number of links to show on the bottom of the device detail page.
The rest of the commands is shown in a dropdown menu. Default is 2.
</li>
<br>
<a id="FHEMWEB-attr-devStateIcon"></a>
<li>devStateIcon<br>
First form:<br>
@ -4721,6 +4736,14 @@ FW_log($$)
attr WEB defaultRoom Zentrale
</li><br>
<a id="FHEMWEB-attr-detailLinks"></a>
<li>detailLinks<br>
Anzahl der Links, die auf der Detailseite unten angezeigt werden. Die
weiteren Befehle werden in einem Auswahlmen&%uuml; angezeigt.
Voreinstellung ist 2.
</li>
<br>
<a id="FHEMWEB-attr-devStateIcon"></a>
<li>devStateIcon<br>
Erste Variante:<br>

View File

@ -951,46 +951,34 @@ FW_removeLink(el)
function
FW_detLink()
{
$("div.forumCopy a").each(function(){
if(FW_isiOS) { // Copy does not work :(
$(this).parent().remove();
if(FW_isiOS || FW_os == "osx") { // our copy fails here
$("#detLink a[href*=forumCopy]").parent().remove();
$("#detLink option[data-cmd^=forumCopy]").remove();
}
$("#detLink a").each(function(){
var m = FW_getLink(this).match(/cmd=([^&]*)/);
if(!m) // delete is already processed
return;
}
var dev = FW_getLink(this).match(/cmd=forumCopy ([^&]*)/)[1];
FW_removeLink(this);
$(this).click(function(evt){
FW_cmd(FW_root+"?cmd=list -r -i "+dev+"&XHR=1", function(data) {
data = '[code]'+data+'[/code]';
var okTxt = '"forum ready" definition copied to the clipboard.';
var errTxt = 'Could not copy the text: ';
var ok;
if(navigator.clipboard) {
navigator.clipboard.writeText(data).then(
function(){ FW_okDialog(okTxt) },
function(err){ FW_okDialog(errTxt+err) });
} else {
var ta = document.createElement("textarea");
ta.value = data;
document.body.appendChild(ta);
ta.select();
if(document.execCommand('copy'))
FW_okDialog(okTxt);
else
FW_okDialog(errTxt+"reason unknown");
document.body.removeChild(ta);
}
});
return false;
});
$(this).click(function(){doDetCmd(m[1])});
});
$("#detLink select#moreCmds").change(function(){
doDetCmd($(this).find("option:selected").attr("data-cmd"));
});
$("#detLink .devSpecHelp a").each(function(){ // Help on detail window
var dev = FW_getLink(this).split("#").pop();
FW_removeLink(this);
function
doDetCmd(fCmd)
{
if(!fCmd)
return;
var m = fCmd.match(/^([^ ]+) (.*)$/);
if(!m)
return;
$(this).click(function(evt){
var cmd=m[1], dev=m[2];
if(cmd == "devSpecHelp") {
if($("#devSpecHelp").length) {
$("#devSpecHelp").remove();
return;
@ -1001,23 +989,24 @@ FW_detLink()
var off = $("#devSpecHelp").position().top-20;
$('body, html').animate({scrollTop:off}, 500);
});
});
});
} else if(cmd == "forumCopy") {
FW_cmd(FW_root+"?cmd=list -r -i "+dev+"&XHR=1", function(data) {
var ta = document.createElement("textarea");
ta.value = '[code]'+data+'[/code]';
document.body.appendChild(ta);
ta.select();
if(document.execCommand('copy'))
FW_okDialog('"forum ready" definition copied to the clipboard.');
else
FW_okDialog('Could not copy');
document.body.removeChild(ta);
});
$("#detLink select#moreCmds").click(function(){
var cmd = $(this).find("option:selected").attr("data-cmd");
if(!cmd)
return;
var m = cmd.match(/^([^ ]+) (.*)$/);
if(!m)
return;
} else if(cmd == "delete") {
FW_delete("delete "+dev);
if(m[1] == "delete") {
FW_delete("delete "+m[2]);
} else if(m[1] == "rawDef") {
var dev = m[2];
} else if(cmd == "rawDef") {
if($("#rawDef").length) {
$("#rawDef").remove();
return;
@ -1086,10 +1075,10 @@ FW_detLink()
});
} else {
location.href = addcsrf(FW_root+"?cmd="+cmd);
location.href = addcsrf(FW_root+"?cmd="+cmd+" "+dev);
}
});
}
}
function