fhemweb.js: fix RawDef/Probably assoc. with & codeMirror (Forum #81595)

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@15701 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2017-12-27 08:45:48 +00:00
parent 469fba0844
commit 0e20cb6c93
2 changed files with 15 additions and 7 deletions

View File

@ -235,6 +235,8 @@ FW_Define($$)
return "Usage: define <name> FHEMWEB [IPV6:]<tcp-portnr> [global]" return "Usage: define <name> FHEMWEB [IPV6:]<tcp-portnr> [global]"
if($port !~ m/^(IPV6:)?\d+$/ || ($global && $global ne "global")); if($port !~ m/^(IPV6:)?\d+$/ || ($global && $global ne "global"));
FW_Undef($hash) if($hash->{OLDDEF}); # modify
foreach my $pe ("fhemSVG", "openautomation", "default") { foreach my $pe ("fhemSVG", "openautomation", "default") {
FW_readIcons($pe); FW_readIcons($pe);
} }

View File

@ -641,7 +641,7 @@ function
FW_inlineModify() // Do not generate a new HTML page upon pressing modify FW_inlineModify() // Do not generate a new HTML page upon pressing modify
{ {
var cm; var cm;
if( typeof AddCodeMirror == 'function' ) { if( typeof AddCodeMirror == 'function' ) {
// init codemirror for FW_style edit textarea // init codemirror for FW_style edit textarea
AddCodeMirror($('textarea[name="data"]')); AddCodeMirror($('textarea[name="data"]'));
@ -720,21 +720,24 @@ FW_rawDef()
var textAreaStyle = typeof AddCodeMirror == 'function'?'opacity:0':''; var textAreaStyle = typeof AddCodeMirror == 'function'?'opacity:0':'';
$("#content").append('<div id="rawDef">'+ $("#content").append('<div id="rawDef">'+
'<textarea id="td_rawDef" rows="25" cols="60" style="width:99%; '+textAreaStyle+'"/>'+ '<textarea id="td_rawDef" rows="25" cols="60" style="width:99%; '+
textAreaStyle+'"/>'+
'<button>Execute commands</button>'+ '<button>Execute commands</button>'+
' Dump "Probably associated with" too <input type="checkbox">'+ ' Dump "Probably associated with" too <input type="checkbox">'+
'<br><br></div>'); '<br><br></div>');
var cmVar;
function function
fillData(opt) fillData(opt)
{ {
var s = $('#rawDef textarea'); var s = $('#rawDef textarea');
FW_cmd(FW_root+"?cmd=list "+opt+" "+dev+"&XHR=1", function(data) { FW_cmd(FW_root+"?cmd=list "+opt+" "+dev+"&XHR=1", function(data) {
var re = new RegExp("^define", "gm"); var re = new RegExp("^define", "gm");
data = data.replace(re, "defmod"); data = data.replace(re, "defmod");
s.val(data); s.val(data);
var off = $("#rawDef").position().top-20; var off = $("#rawDef").position().top-20;
$('body, html').animate({scrollTop:off}, 500); $('body, html').animate({scrollTop:off}, 500);
$("#rawDef button").hide(); $("#rawDef button").hide();
@ -749,12 +752,15 @@ FW_rawDef()
s.bind('input propertychange', propertychange); s.bind('input propertychange', propertychange);
if( typeof AddCodeMirror == 'function') { if(cmVar) {
$('#rawDef textarea + .CodeMirror').remove(); cmVar.setValue(data);
} else if(typeof AddCodeMirror == 'function') {
AddCodeMirror(s, function(cm) { AddCodeMirror(s, function(cm) {
cmVar = cm;
cm.on("change", function() { cm.on("change", function() {
s.val(cm.getValue()); s.val(cm.getValue());
propertychange(); propertychange();
}) })
}); });
} }