// MSwitch_Web.js // Autor:Byte09 // ######################### var version = '1.0'; var info = ''; var debug ='off'; //#################################################################################################### var globaldetails2 = 'start'; var globallock=''; var t=$("#MSwitchWebTR"), ip=$(t).attr("ip"), ts=$(t).attr("ts"); FW_replaceWidget("[name=aw_ts]", "aw_ts", ["time"], "12:00"); $("[name=aw_ts] input[type=text]").attr("id", "aw_ts"); var randomdev=[]; var globalaffected; var auswfirst=document.getElementById('devices'); function teststart(){ // alle startfunktionen ausführen if (debug == 'on'){ alert(devicename+' Debug MSwitchweb an') }; var r1 = $(''); var r2 = $(''); var r3 = $(''); $( ".col1" ).text( "" ); $(r3).appendTo('.col1'); $(r2).appendTo('.col1'); $(r1).appendTo('.col1'); // next teste auf quickedit an if (QUICKEDIT == '0'){ $("#devices").prop("disabled", false); document.getElementById('aw_great').value='schow greater list'; document.getElementById('lockedit').checked = false ; } // EXEC1 ################################################## if (EXEC1 == '1'){ //alert('aus java '+EXEC1); if (debug == 'on'){ alert('EXEC1') }; var affected = document.getElementById('affected').value ; var devices = affected.split(","); var i; var len = devices.length; for (i=0; i'); $(field).appendTo('#log2'); var field = $(''); // !!!!! ####### $(field).appendTo('#log3'); $("#editevent").click(function(){ transferevent(); return; }); // umwandlung des objekts in standartarray var a3 = Object.keys(o).map(function (k) { return o[k];}) // array umdrehen a3.reverse(); // eintrag in dropdown if (atriwaaray[test] != 1) { atriwaaray[test]=1; var newselect = $(''); $(newselect).appendTo('#trigcmdon'); var newselect = $(''); $(newselect).appendTo('#trigcmdoff'); var newselect = $(''); $(newselect).appendTo('#trigon'); var newselect = $(''); $(newselect).appendTo('#trigoff'); } // aktualisierung der divx max 5 var i; for (i = 0; i < 10; i++) { if (a3[i]) { var newselect = $(''); $(newselect).appendTo('#lf'); } } }); // next ################################################## if (HASHINIT != 'define') { for (i=0; i   " + first +"" + last ; document.getElementById(target).innerHTML = selectfield + '
'; var opt = target + '_opt'; document.getElementById(opt).value=selected; return; } function textfield(copytofield,target) { if (debug == 'on'){ alert('textfield') }; var selected =document.getElementById(copytofield).value; if (copytofield.indexOf('cmdonopt') != -1) { var selectfield = "" ; document.getElementById(target).innerHTML = selectfield + '
'; } else{ var selectfield = "" ; document.getElementById(target).innerHTML = selectfield + '
'; } return; } function selectfield(args,target,copytofield){ if (debug == 'on'){ alert('selectfield') }; var cmdsatz = args.split(","); var selectstart = "'; sel = sel+''; FW_okDialog(sel,''); } // Deviceauswahl function deviceselect(){ if (debug == 'on'){ alert('deviceselect') }; sel ='

'; var ausw=document.getElementById('devices'); for (i=0; i '+pos.value+'
'; } else { sel = sel+' '+pos.value+'
'; } } sel = sel+'
'; FW_okDialog(sel,'',removeFn) ; } // lösche log function deletelog() { if (debug == 'on'){ alert('deletelog') }; anzahl =document.getElementById('dellog').value; arg =''; for (i = 1; i < anzahl; i++) { test = document.getElementById('Checkbox-' + i).checked; if (document.getElementById('Checkbox-' + i).checked) { arg=arg+i+','; } } conf=arg; var nm = $(t).attr("nm"); var def = nm+" deletesinglelog "+encodeURIComponent(conf); location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); return; } // löscht vergösserte Fenster function removeFn() { if (debug == 'on'){ alert('removefn') }; var targ = document.getElementById('devices'); for (i = 0; i < targ.options.length; i++) { test = document.getElementById('Checkbox-' + i).checked; targ.options[i].selected = false; if (test) { targ.options[i].selected = true; } } } // reset device function reset() { if (debug == 'on'){ alert('reset') }; var nm = $(t).attr("nm"); var def = nm+" reset_device checked"; location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); return; } // events from monitor to edit function transferevent(){ if (debug == 'on'){ alert('transferevent') }; var values = $('#lf').val(); if (values){ var string = values.join(','); document.getElementById('add_event').value = string; } } // Sortierung ändern function changesort(){ if (debug == 'on'){ alert('changesort') }; sortby = $("[name=sort]").val(); var nm = $(t).attr("nm"); var def = nm+" sort_device "+sortby; location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); } // device zufügen function addevice(device){ if (debug == 'on'){ alert('adddevice') }; var nm = $(t).attr("nm"); var def = nm+" add_device "+device; location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); } // device löschen function deletedevice(device){ if (debug == 'on'){ alert('deletedevice') }; var nm = $(t).attr("nm"); var def = nm+" del_device "+device; location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); } // unbekannt function aktvalue(target,cmd){ if (debug == 'on'){ alert('aktvalue') }; document.getElementById(target).value = cmd; return; } // unbekannt function writeattr(){ if (debug == 'on'){ alert('writeattr') }; conf=''; var nm = $(t).attr("nm"); var def = nm+" Writesequenz "+encodeURIComponent(conf); location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); } // lösche log function clearlog(){ if (debug == 'on'){ alert('clearlog') }; conf=''; var nm = $(t).attr("nm"); var def = nm+" clearlog "+encodeURIComponent(conf); location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); } // unbekannt function savesys(conf){ if (debug == 'on'){ alert('savesys') }; conf = conf.replace(/:/g,'#[dp]'); conf = conf.replace(/;/g,'#[se]'); conf = conf.replace(/ /g,'#[sp]'); conf = conf.replace(/'/g,'#[st]'); var nm = $(t).attr("nm"); var def = nm+" savesys "+encodeURIComponent(conf); location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); } // unbekannt function showValue(newValue,copytofield,target){ if (debug == 'on'){ alert('showValue') }; var opt = target + '_opt'; document.getElementById(opt).value=newValue; document.getElementById(copytofield).value = newValue; } // unbekannt function showtextfield(newValue,copytofield,target) { if (debug == 'on'){ alert('showtextfield') }; document.getElementById(copytofield).value = newValue; } // unbekannt function checkevent(event){ if (debug == 'on'){ alert('checkevent') }; event = event.replace(/ /g,'~'); cmd ='get " . $Name . " checkevent '+event; FW_cmd(FW_root+'?cmd='+encodeURIComponent(cmd)+'&XHR=1'); } function checkcondition(condition,event){ if (debug == 'on'){ alert('checkcondition') } var selected =document.getElementById(condition).value; if (selected == '') { var textfinal = "
"+NOCONDITION+"
"; FW_okDialog(textfinal); return; } selected = selected.replace(/\|/g,'(DAYS)'); // !!! selected = selected.replace(/\./g,'#[pt]'); // !!! selected = selected.replace(/:/g,'#[dp]'); selected= selected.replace(/~/g,'#[ti]'); selected = selected.replace(/ /g,'#[sp]'); event = event.replace(/~/g,'#[ti]'); event = event.replace(/ /g,'#[sp]'); cmd ='get '+devicename+' checkcondition '+selected+'|'+event; FW_cmd(FW_root+'?cmd='+encodeURIComponent(cmd)+'&XHR=1', function(resp){FW_okDialog(resp);}); } // next $("#eventmonitor").click(function(){ var check = $("[name=eventmonitor]").prop("checked") ? "1":"0"; if (check == 1) { $( "#log2" ).text( "" ); $( "#log1" ).text( "eingehende events:" ); $( "#log3" ).text( "" ); var field = $(''); $(field).appendTo('#log2'); var field = $(''); $(field).appendTo('#log3'); return; } }); // clickfunktions // details speichern /* $("#aw_det").click(function(){ var nm = $(t).attr("nm"); devices = ''; eval(JAVAFORM); devices = devices.replace(/:/g,'#[dp]'); devices = devices.replace(/;/g,'#[se]'); devices = devices.replace(/ /g,'#[sp]'); devices = devices.replace(/%/g,'#[pr]'); devices = encodeURIComponent(devices); var def = nm+" details "+devices+" "; location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); }); */ // modify trigger aw_save $("#aw_md").click(function(){ if (debug == 'on'){ alert('#aw_md') }; var nm = $(t).attr("nm"); trigon = $("[name=trigon]").val(); trigon = trigon.replace(/ /g,'~'); trigoff = $("[name=trigoff]").val(); trigoff = trigoff.replace(/ /g,'~'); trigcmdon = $("[name=trigcmdon]").val(); trigcmdon = trigcmdon.replace(/ /g,'~'); trigcmdoff = $("[name=trigcmdoff]").val(); if(typeof(trigcmdoff)=="undefined"){trigcmdoff="no_trigger"} trigcmdoff = trigcmdoff.replace(/ /g,'~'); trigsave = $("[name=aw_save]").prop("checked") ? "ja":"nein"; trigwhite = $("[name=triggerwhitelist]").val(); if (trigcmdon == trigon && trigcmdon != 'no_trigger' && trigon != 'no_trigger'){ FW_okDialog('on triggers for \'switch Test on + execute on commands\' and \'execute on commands only\' may not be the same !'); return; } if (trigcmdoff == trigoff && trigcmdoff != 'no_trigger' && trigoff != 'no_trigger'){ FW_okDialog('off triggers for \'switch Test off + execute on commands\' and \'execute off commands only\' may not be the same !'); return; } if (trigon == trigoff && trigon != 'no_trigger'){ FW_okDialog('trigger for \'switch Test on + execute on commands\' and \'switch Test off + execute off commands\' must not both be \'*\''); return; } var def = nm+" trigger "+trigon+" "+trigoff+" "+trigsave+" "+trigcmdon+" "+trigcmdoff+" " ; location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); }); // unbekannt $("#aw_little").click(function(){ if (debug == 'on'){ alert('#aw_little') }; var veraenderung = 3; // Textfeld veraendert sich stets um 3 Zeilen var sel = document.getElementById('textfie').innerHTML; var show = document.getElementById('textfie2'); var2 = "size=\"6\""; var result = sel.replace(/size=\"15\"/g,var2); document.getElementById('textfie').innerHTML = result; }); //delete trigger $("#aw_md2").click(function(){ if (debug == 'on'){ alert('#aw_md2') }; var nm = $(t).attr("nm"); var def = nm+" del_trigger "; location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); }); //delete svedcmds $("#del_savecmd").click(function(){ if (debug == 'on'){ alert('#del_savecmd') }; var nm = $(t).attr("nm"); var def = nm+" delcmds "; location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); }); // unbekannt $("#aw_dev").click(function(){ if (debug == 'on'){ alert('#aw_dev') }; var nm = $(t).attr("nm"); devices = $("[name=affected_devices]").val(); var def = nm+" devices "+devices+" "; location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); }); //unbekannt $("#aw_show").click(function(){ if (debug == 'on'){ alert('#aw_show') }; $("[name=noshow]").css("display","block"); $("[name=noshowtask]").css("display","none"); }); //unbekannt $("#aw_addevent").click(function(){ if (debug == 'on'){ alert('#aw_addevent') }; var nm = $(t).attr("nm"); event = $("[name=add_event]").val(); event= event.replace(/ /g,'[sp]'); event= event.replace(/\|/g,'[bs]'); if (event == '') { return; } var def = nm+" addevent "+event+" "; location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); }); //aplly filter to trigger $("#aw_md1").click(function(){ if (debug == 'on'){ alert('#aw_md1') }; var nm = $(t).attr("nm"); var def = nm+" filter_trigger "; location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); }); //unbekannt $("#aw_trig").click(function(){ if (debug == 'on'){ alert('#aw_trig') }; var nm = $(t).attr("nm"); trigdev = $("[name=trigdev]").val(); timeon = $("[name=timeon]").val(); timeoff = $("[name=timeoff]").val(); timeononly = $("[name=timeononly]").val(); timeoffonly = $("[name=timeoffonly]").val(); if(typeof(timeoffonly)=="undefined"){timeoffonly=""} timeonoffonly = $("[name=timeonoffonly]").val(); if(typeof(timeonoffonly)=="undefined"){timeonoffonly=""} trigdevcond = $("[name=triggercondition]").val(); trigdevcond = trigdevcond.replace(/\\./g,'#[pt]'); trigdevcond = trigdevcond.replace(/:/g,'#[dp]'); trigdevcond= trigdevcond.replace(/~/g,'#[ti]'); trigdevcond = trigdevcond.replace(/ /g,'#[sp]'); trigdevcond = trigdevcond+':'; timeon = timeon.replace(/ /g, ''); timeoff = timeoff.replace(/ /g, ''); timeononly = timeononly.replace(/ /g, ''); timeoffonly = timeoffonly.replace(/ /g, ''); timeonoffonly = timeonoffonly.replace(/ /g, ''); timeon = timeon.replace(/:/g, '#[dp]'); timeoff = timeoff.replace(/:/g, '#[dp]'); timeononly = timeononly.replace(/:/g, '#[dp]'); timeoffonly = timeoffonly.replace(/:/g, '#[dp]'); timeonoffonly = timeonoffonly.replace(/:/g, '#[dp]'); timeon = timeon+':'; timeoff = timeoff+':'; timeononly = timeononly+':'; timeoffonly = timeoffonly+':'; timeonoffonly = timeonoffonly+':'; trigwhite = $("[name=triggerwhitelist]").val(); var def = nm+" set_trigger "+trigdev+" "+timeon+" "+timeoff+" "+timeononly+" "+timeoffonly+" "+timeonoffonly+" "+trigdevcond+" "+trigwhite+" " ; def = encodeURIComponent(def); location = location.pathname+"?detail="+devicename+"&cmd=set "+addcsrf(def); });