From 452212864944e41a9cd3fec55b15f705c5442cc4 Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Fri, 28 Oct 2022 12:09:44 +0000
Subject: [PATCH] fhemweb.js: detail bottom row reorganization, 3rd try (Forum
#129858)
git-svn-id: https://svn.fhem.de/fhem/trunk@26608 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/01_FHEMWEB.pm | 8 +-
fhem/fhem.pl | 27 ++---
fhem/www/pgm2/fhemweb.js | 213 +++++++++++++++++++++++----------------
3 files changed, 146 insertions(+), 102 deletions(-)
diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm
index 26fdfbaa5..f81f076b1 100644
--- a/fhem/FHEM/01_FHEMWEB.pm
+++ b/fhem/FHEM/01_FHEMWEB.pm
@@ -1246,6 +1246,7 @@ FW_dataAttr()
addParam($FW_wname, "confirmJSError", 1).
addParam($FW_wname, "addHtmlTitle", 1).
addParam($FW_wname, "styleData", "").
+ addParam($FW_wname, "hiddenroom", "").
addParam("global", "language", "EN").
"data-availableJs='$FW_fhemwebjs' ".
"data-webName='$FW_wname' ";
@@ -1613,16 +1614,15 @@ FW_doDetail($)
$sfx = ($sfx eq "EN" ? "" : "_$sfx");
FW_pH "$FW_ME/docs/commandref${sfx}.html#$t", "Help for $t",
undef, "detLink devSpecHelp";
- FW_pH "cmd=rawDef $d", "Raw definition", undef, "detLink rawDef";
+ FW_pH "cmd=forumCopy $d", "Copy for forum.fhem.de", undef,"detLink forumCopy";
FW_pO "
");
- $(div).html("Do you really want to delete "+dev+"?
"+
+ $(div).html("Do you really want to "+cmd+"?
"+
"
Skip this dialog in the future");
$("body").append(div);
@@ -464,7 +469,7 @@ FW_deleteDevice(dev)
dialogClass:"no-close", modal:true, width:"auto", closeOnEscape:true,
maxWidth:$(window).width()*0.9, maxHeight:$(window).height()*0.9,
buttons: [
- {text:"Yes", click:function(){ doClose(); location.href = cmd; }},
+ {text:"Yes", click:function(){ doClose(); location.href = fCmd; }},
{text:"No", click:doClose} ],
close: doClose
});
@@ -479,6 +484,27 @@ FW_deleteDevice(dev)
}
}
+// For all the links starting with delete (deleteattr, etc)
+function
+FW_confirmDelete()
+{
+ var b = $("body");
+ var cd = $(b).attr("data-confirmDelete");
+ if(!cd || cd == 0)
+ return;
+ var wn = $(b).attr("data-webName");
+ $("div#content").find("a").each(function(){
+ var href = $(this).attr("href");
+ if(!href)
+ return;
+ var ma = $(this).attr("href").match(/.*cmd[^=]*=(delete[^&]*).*$/);
+ if(!ma || ma.length != 2)
+ return;
+ FW_removeLink(this);
+ $(this).click(function(e){ FW_delete(ma[1], ma[0]) });
+ });
+}
+
function
FW_renameDevice(dev)
{
@@ -843,6 +869,17 @@ FW_inlineModify() // Do not generate a new HTML page upon pressing modify
AddCodeMirror(s[0], function(pcm) {cm = pcm;});
}
});
+
+ if(!$("body").attr("data-hiddenroom").match(/\binput\b/)) {
+ $("table.internals div.dname").each(function(){
+ if($(this).text() == "NAME") {
+ var dev = $(this).attr("data-name");
+ var a=$("
NAME");
+ $(this).html(a);
+ a.click(function(){ FW_renameDevice(dev) });
+ }
+ });
+ }
// Set and attr
$("div input.psc[type=submit]:not(.get)").click(function(e){
@@ -901,28 +938,99 @@ FW_inlineModify() // Do not generate a new HTML page upon pressing modify
});
}
+
+function
+FW_removeLink(el)
+{
+ $(el).unbind("click");
+ $(el).attr("href", "#"); // Desktop: show underlined Text
+ $(el).removeAttr("onclick"); // smallscreen style
+}
+
// Fill the "detLink" line with life
function
FW_detLink()
{
- $("div.rawDef a").each(function(){ // Help on detail window
- var dev = FW_getLink(this).split(" ").pop().split("&")[0];
- $(this).unbind("click");
- $(this).attr("href", "#"); // Desktop: show underlined Text
- $(this).removeAttr("onclick");
+ $("div.forumCopy a").each(function(){
+ if(FW_isiOS) { // Copy does not work :(
+ $(this).parent().remove();
+ 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;
+ });
+ });
+
+ $("#detLink .devSpecHelp a").each(function(){ // Help on detail window
+ var dev = FW_getLink(this).split("#").pop();
+ FW_removeLink(this);
+
+ $(this).click(function(evt){
+ if($("#devSpecHelp").length) {
+ $("#devSpecHelp").remove();
+ return;
+ }
+ FW_getHelp(dev, function(data){
+ $("#content").append('
');
+ $("#devSpecHelp").html(data);
+ var off = $("#devSpecHelp").position().top-20;
+ $('body, html').animate({scrollTop:off}, 500);
+ });
+ });
+ });
+
+
+ $("#detLink select#moreCmds").click(function(){
+ var cmd = $(this).find("option:selected").attr("data-cmd");
+ if(!cmd)
+ return;
+ var m = cmd.match(/^([^ ]+) (.*)$/);
+ if(!m)
+ return;
+
+ if(m[1] == "delete") {
+ FW_delete("delete "+m[2]);
+
+ } else if(m[1] == "rawDef") {
+ var dev = m[2];
if($("#rawDef").length) {
$("#rawDef").remove();
return;
}
- var textAreaStyle = typeof AddCodeMirror == 'function'?'opacity:0':'';
+ var textAreaStyle = typeof AddCodeMirror == 'function'?'opacity:0':'';
$("#content").append('
'+
''+
''+
- ' Dump "Probably associated with" too '+
+ ' Dump "Probably associated with" too '+
+ ''+
+ ' With internals '+
'
');
var cmVar;
@@ -943,7 +1051,8 @@ FW_detLink()
var propertychange = function() {
var nData = $("#rawDef textarea").val();
- if(nData != data)
+ if(nData != data &&
+ !$("body").attr("data-hiddenroom").match(/\binput\b/))
$("#rawDef button").show();
else
$("#rawDef button").hide();
@@ -967,82 +1076,14 @@ FW_detLink()
});
}
fillData("-r");
-
- $("#rawDef input").click(function(){fillData(this.checked ?"-R":"-r")});
-
+ $("#rawDef input").click(function(){
+ fillData(
+ ($("input.paw").is(":checked") ? "-R" : "-r")+
+ ($("input.int").is(":checked") ? " -i" : ""));
+ });
$("#rawDef button").click(function(){
FW_execRawDef($("#rawDef textarea").val());
});
- });
-
- });
-
- $("#detLink .devSpecHelp a").each(function(){ // Help on detail window
- var dev = FW_getLink(this).split("#").pop();
- $(this).unbind("click");
- $(this).attr("href", "#"); // Desktop: show underlined Text
- $(this).removeAttr("onclick");
-
- $(this).click(function(evt){
- if($("#devSpecHelp").length) {
- $("#devSpecHelp").remove();
- return;
- }
- FW_getHelp(dev, function(data){
- $("#content").append('
');
- $("#devSpecHelp").html(data);
- var off = $("#devSpecHelp").position().top-20;
- $('body, html').animate({scrollTop:off}, 500);
- });
- });
- });
-
-
- $("#detLink select#moreCmds").change(function(){
- var cmd = $(this).find("option:selected").attr("data-cmd");
- if(!cmd)
- return;
- var m = cmd.match(/^([^ ]+) (.*)$/);
- if(!m)
- return;
-
- if(m[1] == "forumCopy") {
- FW_cmd(FW_root+"?cmd=list -r -i "+m[2]+"&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;
- ta.style.top = ta.style.left = "0";
- ta.style.position = "fixed";
- document.body.appendChild(ta);
- ta.focus();
- ta.select();
- try {
- if(document.execCommand('copy'))
- FW_okDialog(okTxt);
- else
- FW_okDialog(errTxt);
- } catch (err) {
- log('Copy:'+err);
- FW_okDialog(errTxt+err);
- }
- document.body.removeChild(ta);
- }
- });
-
- } else if(m[1] == "rename") {
- FW_renameDevice(m[2]);
-
- } else if(m[1] == "delete") {
- FW_deleteDevice(m[2]);
} else {
location.href = addcsrf(FW_root+"?cmd="+cmd);