// $Id$
//for tooltip
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
var shortDays = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];
function FW_weekprofileInputDialog(title,inp,parent,callback)
{
var div = $("
");
$(div).append(title);
$(div).append(table);
$(div).append('');
$("body").append(div);
$(div).dialog({
dialogClass:"no-close",modal:true, width:"auto", closeOnEscape:true,
maxWidth:$(window).width()*0.9, maxHeight:$(window).height()*0.9,
title: title,
buttons: [{text:"OK", click:function(){
var res=[];
if($("#FW_weekprofileMultiSelDiologFreeText").val())
res.push($("#FW_weekprofileMultiSelDiologFreeText").val());
$("#FW_weekprofileMultiSelDiolog table input").each(function(){
if($(this).prop("checked"))
res.push($(this).attr("name"));
});
$(this).dialog("close");
$(div).remove();
if(callback)
callback(res);
}},{text:"CANCEL", click:function(){
$(this).dialog("close");
$(div).remove();
if(callback)
callback(null);
}}]
});
if(parent)
$(div).dialog( "option", "position", {
my: "left top", at: "right bottom",
of: parent, collision: "flipfit"
});
}
function weekprofile_DoEditWeek(devName,newPage)
{
var widget = $('div[informid="'+devName+'"]').get(0);
if (newPage == 1) {
var url = location.href;
var pos = url.indexOf('?');
if (pos >=0)
url = url.substr(pos);
else
url='';
window.location.assign(FW_root+'?cmd={weekprofile_editOnNewpage("'+widget.DEVICE+'","'+widget.CURPRF+'","'+url+'");;}');
} else {
widget.MODE = 'EDIT';
$(widget.MENU.BASE).hide();
widget.setValueFn("REUSEPRF");
}
}
function FW_weekprofilePRFChached(devName,select)
{
var widget = $('div[informid="'+devName+'"]').get(0)
var prfName = select.options[select.selectedIndex].value;
widget.CURPRF = prfName;
widget.PROFILE = null;
FW_queryValue('get '+devName+' profile_data '+prfName, widget);
}
function FW_weekprofileSendToDev(devName,bnt)
{
var widget = $('div[informid="'+devName+'"]').get(0)
var deviceLst = null;
bnt.setValueFn = function(data) {
try {
deviceLst=JSON.parse(data);
var devicesNames = [];
var devicesAlias = [];
for (var k=0; k < deviceLst.length; k++) {
devicesNames.push(deviceLst[k]['NAME']);
devicesAlias.push(deviceLst[k]['ALIAS']);
}
var selected = [];
if (widget.MASTERDEV)
selected.push(widget.MASTERDEV);
FW_weekprofileMultiSelDialog("Device(s):",devicesNames,devicesAlias,selected,bnt,
function(sndDevs) {
if (!sndDevs || sndDevs.length==0)
return;
FW_cmd(FW_root+"?cmd=set "+widget.DEVICE+" send_to_device "+widget.CURPRF+" "+sndDevs.join(',')+"&XHR=1",function(arg) {FW_weekprofileSendCallback(widget.DEVICE,arg);});
});
} catch(e){
console.log(devName+" error parsing json '" +data+"'");
FW_errmsg(devName+" Parameter "+e,5000);
return;
}
}
FW_queryValue('get '+devName+' sndDevList', bnt);
}
function FW_weekprofileCopyPrf(devName,lnk)
{
var widget = $('div[informid="'+devName+'"]').get(0)
FW_weekprofileInputDialog("Name:","text",lnk,function(name,ok){
if (!name || name.length <=0)
return;
FW_cmd(FW_root+"?cmd=set "+widget.DEVICE+" copy_profile "+widget.CURPRF+" "+name+"&XHR=1",function(arg) {FW_weekprofileSendCallback(widget.DEVICE,arg);});
});
}
function FW_weekprofileRemovePrf(devName,lnk)
{
var widget = $('div[informid="'+devName+'"]').get(0)
FW_weekprofileInputDialog("
Delete Profile: '"+widget.CURPRF+"' ?
","hidden",lnk,function(name,ok){
if (ok < 1)
return;
FW_cmd(FW_root+"?cmd=set "+widget.DEVICE+" remove_profile "+widget.CURPRF+"&XHR=1",function(arg) {FW_weekprofileSendCallback(widget.DEVICE,arg);});
});
}
function FW_weekprofileShow(widget)
{
$(widget.MENU.BASE).show();
$(widget.MENU.CONTENT).empty();
var html='';
if (widget.PROFILENAMES) {
html += " "
html += "";
html += " "
html += "";
html += " "
html += "";
html += " "
html += "";
$(widget.MENU.CONTENT).append(html);
var select = $(widget.MENU.CONTENT).find('select[name="PROFILES"]').get(0);
var prfName = select.options[select.selectedIndex].value;
if (widget.CURPRF != prfName)
FW_weekprofilePRFChached(widget.DEVICE,select);
}
if (!widget.PROFILE) {
return;
}
var table = widget.CONTENT;
for (var i = 0; i < shortDays.length; ++i) {
$(table).append('
'+widget.WEEKDAYS[i]+'
');
var tr = $(table).find("tr").get(i);
for (var k = 0; k < widget.PROFILE[shortDays[i]]['temp'].length; ++k) {
var str = '';
k>0 ? str = widget.PROFILE[shortDays[i]]['time'][k-1] : str = '00:00';
str = str + '-' + widget.PROFILE[shortDays[i]]['time'][k];
$(tr).append('
');
}
}
}
function FW_weekprofileEditTimeChanged(inp)
{
if (inp == null) {return;}
var times = inp.value.split(':');
if (times.length == 0)
return;
var hour = parseInt(times[0]);
var min = (times.length==2) ? parseInt(times[1]): 0;
inp.value = ((hour<10)?("0"+hour):hour) +":"+ ((min<10)?("0"+min):min);
//set new end time as new start time for the next interval
var nexttr = inp.parentNode.parentNode.nextSibling;
if (nexttr!=null){
nexttr.firstChild.firstChild.innerHTML=inp.value;
}
}
function FW_weekprofileEditRowStyle(table)
{
var alltr = $(table).find("tr");
for (var i = 0; i < alltr.length; ++i){
var delButton = $(alltr[i]).find('input[name="DEL"]');
var addButton = $(alltr[i]).find('input[name="ADD"]');
var inp = $(alltr[i]).find('input[name="ENDTIME"]');
$(alltr[i]).attr('class',(i%2==0)? "odd":"even");
delButton.attr('type',"button");
addButton.attr('type',"button");
inp.removeAttr('style');
inp.removeAttr('readonly');
FW_weekprofileEditTimeChanged(inp.get(0));
if (i==0){
$(alltr[i]).find('span[name="STARTTIME"]').get(0).innerHTML = "00:00";
if (alltr.length == 1){
delButton.attr('type',"hidden");
}
}
if (i==alltr.length-1){
if (alltr.length > 1){
addButton.attr('type',"hidden");
}
inp.attr('style',"border:none;background:transparent;box-shadow:none");
inp.get(0).value = "24:00";
inp.attr('readonly',true);
}
}
}
function FW_weekprofileEditAddInterval(tr)
{
var newtr = $(tr).clone(true);
var alltr = $(tr).parent().children();
for (var i = 0; i < alltr.length; ++i) {
if ( $(alltr[i]).is($(tr))) {
newtr.insertAfter($(alltr[i]));
break;
}
}
FW_weekprofileEditRowStyle($(tr).parent());
var timSel = newtr.find('input[name="ENDTIME"]');
if (alltr.length == 1)
timSel = $(tr).find('input[name="ENDTIME"]');
timSel.focus();
timSel.select();
}
function FW_weekprofileEditDelInterval(tr)
{
var parent = $(tr).parent();
$(tr).remove();
FW_weekprofileEditRowStyle(parent)
}
function FW_weekprofileEditDay(widget,day)
{
var div = $("
").get(0);
$(div).append("
"+widget.WEEKDAYS[day]+"
");
var table = $("
").get(0);
$(table).attr('id',"weekprofile."+widget.DEVICE+"."+shortDays[day]);
$(table).attr('class',"block wide weekprofile");
var html;
var times = widget.PROFILE[shortDays[day]]['time'];
var temps = widget.PROFILE[shortDays[day]]['temp'];
for (var i = 0; i < times.length; ++i) {
var startTime = (i>0) ? times[i-1] : "00:00";
var endTime = (i";
//from
html += "
"+startTime+"
";
html += "
-
";
//to
html += "
";
//temp
html += "
";
//ADD-Button
html += "
";
//DEL-Button
html += "
";
html += "";
}
$(table).append(html);
$(div).append(table);
FW_weekprofileEditRowStyle(table);
return div;
}
function FW_weekprofileEditWeek(widget)
{
var table = widget.CONTENT;
var daysInRow = 2;
$(table).append('
');
var tr = $(table).find("tr:last");
for (var i = 0; i < shortDays.length; ++i) {
tr.append('
');
tr.find('td:last').append(FW_weekprofileEditDay(widget,i));
if ((i+1)%daysInRow == 0){
$('