var calculatedSunData; function getEveningDarkStart(){ if(!willSunSet()){ return 0; } if(isMidnightDark()){ var sunData = getSunData(); return sunToTimeUnits(sunData[1]); } else{ return 0; } } function getEveningDarkWidth(){ if(!willSunSet()){ return 0; } if(isMidnightDark()){ var sunData = getSunData(); return constDeviceRowWidth - sunToTimeUnits(sunData[1]); } else{ return 0; } } function getMorningDarkStart(){ //TODO the day of the year when the sun "begins" not to set, will it work then? if(!willSunSet()){ return 0; } if(isMidnightDark()){ return 0; } else{ var sunData = getSunData(); var start = sunToTimeUnits(sunData[1]); if(start == undefined){ return 0; } return start; } } function getMorningDarkWidth(){ if(!willSunSet()){ return 0; } var sunData = getSunData(); if(isMidnightDark()){ return sunToTimeUnits(sunData[0]); } else{ return sunToTimeUnits(sunData[1]) - sunToTimeUnits(sunData[0]); } } function getStates(methods){ var activeStates = new Array(); var i = 1; while(i <= methods){ if(methods & i){ activeStates.push(getStateFromMethod.callWith(i)); } i = i<<1; } return activeStates; } function getSunData(){ if(calculatedSunData == undefined){ main.updateCurrentDay(); } if(calculatedSunData[0] == undefined){ return ["0:0","0:0",""]; //TODO } return calculatedSunData; } function updateSunData(sunData){ calculatedSunData = sunData; } function isMidnightDark(){ var sunData = getSunData(); var sunrise = sunData[0].split(':');; var sunset = sunData[1].split(':'); if(sunset[0] < sunrise[0] || (sunset[0] == sunrise[0] && sunset[1] < sunrise[1])){ return false; } return true; } function pointToArray(point){ //TODO another way than using arrays... var deviceId = point.deviceRow.deviceId; var pointName = "Job_" + deviceId; var startdate = new Date(); //startdate, not in use, always "now" var pointDimValue = point.dimvalue * (255/100); var pointMethod = main.mainGetMethodFromState(point.state); var pointId = point.pointId; var lastRun = point.lastRun; var pointTime = point.absoluteHour * 3600 + point.absoluteMinute * 60; var absolutePointTime = pointTime; var pointType = main.mainGetTypeFromTriggerstate(point.triggerstate); var sunData = getSunData(); if(point.triggerstate == "sunrise"){ var suntime = sunData[0].split(':'); pointTime = suntime[0] * 3600 + suntime[1] * 60; } else if(point.triggerstate == "sunset"){ var suntime = sunData[1].split(':'); pointTime = suntime[0] * 3600 + suntime[1] * 60; } var pointFuzzinessBefore = point.fuzzyBefore; var pointFuzzinessAfter = point.fuzzyAfter; var pointOffset = point.triggerstate == "absolute" ? 0 : point.offset; var pointDays = new Array(); pointDays.push(point.deviceRow.parent.parent.daydate.getDay()); var childPoints = point.getChildPoints(); for(var child in childPoints){ pointDays.push(childPoints[child].deviceRow.parent.parent.daydate.getDay()); //value (day) different per event } return new Array(deviceId, pointName, startdate, lastRun, pointMethod, pointDimValue, pointTime, pointType, pointFuzzinessBefore, pointFuzzinessAfter, pointOffset, pointDays, absolutePointTime, pointId); } function sunToTimeUnits(suntime){ suntime = suntime.split(':'); var hourSize = constDeviceRowWidth/24; //24 hours... return hourSize * suntime[0] + hourSize * suntime[1]/60; } function willSunSet(){ var sunData = getSunData(); return !(sunData[2] && sunData[2] != "") } //INIT: function initiateStoredPointsInGUI(){ for(var devicekey in storedPoints){ for(var i=0;i prevPoint.x) && pointList[i].state != "bell"){ //TODO when more than "bell", make dynamic prevPoint = pointList[i]; } } } if(prevPoint == null){ dayIndex = dayIndex - 1; if(dayIndex == -1){ //too far, begin from end again dayIndex = days.length - 1; } var prevDayDevice = getDeviceRow(dayIndex, deviceId); if(prevDayDevice == undefined){ return null; } return prevDayDevice.endPoint; } if(prevPoint.state == "off"){ return null; } return prevPoint; //only on or dim } function updateDeviceIndex(){ //TODO, better way, please... deviceIndex = []; //empty list var startIndex = 0; for(var i=0;i days.length-1){ dayIndex = dayIndex - days.length; } var deviceRow = days[dayIndex].children[0].children[parseInt(deviceIndex[device])]; previousEndPoint = assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, i==0); if(i == days.length-1){ //last one, bind the first one too then deviceRow = days[startIndex].children[0].children[parseInt(deviceIndex[device])]; assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, false); } } } } //DAYS: var weekday_name_array = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); var currentDayIndex = 6; //Today... var days = new Array(); function addDay(day){ days.push(day); } function decrementCurrentDay(){ days[currentDayIndex].state = "hiddenRight"; var workDate = days[currentDayIndex].daydate; workDate.setDate(workDate.getDate() - 7); days[currentDayIndex].daydate = workDate; if(currentDayIndex == 0){ currentDayIndex = days.length - 1; } else{ currentDayIndex--; } days[currentDayIndex].state = "hiddenLeft"; //place on right side of center, for correct slid days[currentDayIndex].state = "visible"; } function getCurrentDay(){ return days[currentDayIndex]; } function getCurrentDayIndex(dummyvalue){ //by sending in this dummyvalue, this function will be evaluated when that value is changed... return currentDayIndex; } function getCurrentDate(){ if(days.length < 7){ //not initiated yet return new Date(); //now } var date = new Date(days[currentDayIndex].daydate); return date; } function getCurrentDayName(){ var day = getCurrentDay().daydate; return weekday_name_array[day.getDay()] + " " + day.getDate(); } function getDayIndexForDayOfWeek(dayOfWeek){ var offset = days[0].daydate.getDay(); dayOfWeek = days.length - offset + parseInt(dayOfWeek); if(dayOfWeek == -1){ dayOfWeek = days.length - 1; } if(dayOfWeek > days.length-1){ dayOfWeek = dayOfWeek - days.length; } return dayOfWeek; } function getDays(){ return days; } function incrementCurrentDay(){ days[currentDayIndex].state = "hiddenLeft"; var workDate = days[currentDayIndex].daydate; workDate.setDate(workDate.getDate() + 1); if(currentDayIndex == (days.length - 1)){ currentDayIndex = 0; } else{ currentDayIndex++; } days[currentDayIndex].daydate = workDate; days[currentDayIndex].state = "hiddenRight"; //place on right side of center, for correct slide days[currentDayIndex].state = "visible"; } function updateLastRun(deviceId, day, pointId, lastRun){ day = getDayIndexForDayOfWeek(day); var row = getDeviceRow(day,deviceId); for(var k=0;k