@ -34,6 +34,7 @@ function initMessages() {
messages [ 10 ] = "Session expired, please reload page..." ;
}
<!-- removeIf ( ! sensor ) -- >
function sensorName ( id ) {
var names = [
"DHT" , "Dallas" , "Emon Analog" , "Emon ADC121" , "Emon ADS1X15" ,
@ -73,6 +74,7 @@ function magnitudeError(error) {
}
return "Error " + error ;
}
<!-- endRemoveIf ( ! sensor ) -- >
// -----------------------------------------------------------------------------
// Utils
@ -452,12 +454,8 @@ function doUpdate() {
// Empty special fields
$ ( ".pwrExpected" ) . val ( 0 ) ;
$ ( "input[name='pwrResetCalibration']" ) .
prop ( "checked" , false ) .
iphoneStyle ( "refresh" ) ;
$ ( "input[name='pwrResetE']" ) .
prop ( "checked" , false ) .
iphoneStyle ( "refresh" ) ;
$ ( "input[name='pwrResetCalibration']" ) . prop ( "checked" , false ) ;
$ ( "input[name='pwrResetE']" ) . prop ( "checked" , false ) ;
// Change handling
numChanged = 0 ;
@ -539,8 +537,7 @@ function doFactoryReset() {
return false ;
}
function doToggle ( element , value ) {
var id = parseInt ( element . attr ( "data" ) , 10 ) ;
function doToggle ( id , value ) {
sendAction ( "relay" , { id : id , status : value ? 1 : 0 } ) ;
return false ;
}
@ -584,10 +581,7 @@ function toggleMenu() {
function showPanel ( ) {
$ ( ".panel" ) . hide ( ) ;
if ( $ ( "#layout" ) . hasClass ( "active" ) ) { toggleMenu ( ) ; }
$ ( "#" + $ ( this ) . attr ( "data" ) ) . show ( ) .
find ( "input[type='checkbox']" ) .
iphoneStyle ( "calculateDimensions" ) .
iphoneStyle ( "refresh" ) ;
$ ( "#" + $ ( this ) . attr ( "data" ) ) . show ( ) ;
}
// -----------------------------------------------------------------------------
@ -609,6 +603,7 @@ function createRelayList(data, container, template_name) {
}
<!-- removeIf ( ! sensor ) -- >
function createMagnitudeList ( data , container , template_name ) {
var current = $ ( "#" + container + " > div" ) . length ;
@ -625,6 +620,7 @@ function createMagnitudeList(data, container, template_name) {
}
}
<!-- endRemoveIf ( ! sensor ) -- >
// -----------------------------------------------------------------------------
// Wifi
@ -666,6 +662,7 @@ function addNetwork() {
// -----------------------------------------------------------------------------
// Relays scheduler
// -----------------------------------------------------------------------------
function delSchedule ( ) {
var parent = $ ( this ) . parents ( ".pure-g" ) ;
$ ( parent ) . remove ( ) ;
@ -677,6 +674,7 @@ function moreSchedule() {
}
function addSchedule ( event ) {
var numSchedules = $ ( "#schedules > div" ) . length ;
if ( numSchedules >= maxSchedules ) {
alert ( "Max number of schedules reached" ) ;
@ -699,13 +697,12 @@ function addSchedule(event) {
$ ( line ) . find ( ".button-del-schedule" ) . on ( "click" , delSchedule ) ;
$ ( line ) . find ( ".button-more-schedule" ) . on ( "click" , moreSchedule ) ;
line . appendTo ( "#schedules" ) ;
$ ( line ) . find ( "input[type='checkbox']" ) . prop ( "checked" , false ) ;
$ ( line ) . find ( "input[type='checkbox']" ) .
prop ( "checked" , false ) .
iphoneStyle ( "calculateDimensions" ) .
iphoneStyle ( "refresh" ) ;
initCheckboxes ( ) ;
return line ;
}
// -----------------------------------------------------------------------------
@ -723,15 +720,8 @@ function initRelays(data) {
// Add relay fields
var line = $ ( template ) . clone ( ) ;
$ ( ".id" , line ) . html ( i ) ;
$ ( "input" , line ) . attr ( "data" , i ) ;
$ ( ":checkbox" , line ) . prop ( 'checked' , data [ i ] ) . attr ( "data" , i ) ;
line . appendTo ( "#relays" ) ;
$ ( "input[type='checkbox']" , line ) . iphoneStyle ( {
onChange : doToggle ,
resizeContainer : true ,
resizeHandle : true ,
checkedLabel : "ON" ,
uncheckedLabel : "OFF"
} ) ;
// Populate the relay SELECTs
$ ( "select.isrelay" ) . append (
@ -739,6 +729,59 @@ function initRelays(data) {
}
}
function initCheckboxes ( ) {
var setCheckbox = function ( element , value ) {
var container = $ ( ".toggle-container" , $ ( element ) ) ;
if ( value ) {
container . css ( "clipPath" , "inset(0 0 0 50%)" ) ;
container . css ( "backgroundColor" , "#00c000" ) ;
} else {
container . css ( "clipPath" , "inset(0 50% 0 0)" ) ;
container . css ( "backgroundColor" , "#c00000" ) ;
}
}
$ ( ".checkbox-container" )
. each ( function ( ) {
var status = $ ( this ) . next ( ) . prop ( 'checked' ) ;
setCheckbox ( this , status ) ;
} )
. off ( 'click' )
. on ( 'click' , function ( ) {
var checkbox = $ ( this ) . next ( ) ;
var status = checkbox . prop ( 'checked' ) ;
status = ! status ;
checkbox . prop ( 'checked' , status ) ;
setCheckbox ( this , status ) ;
if ( "relay" == checkbox . attr ( 'name' ) ) {
var id = checkbox . prop ( 'data' ) ;
doToggle ( id , status ) ;
}
} ) ;
}
function createCheckboxes ( ) {
$ ( "input[type='checkbox']" ) . each ( function ( ) {
var text_on = $ ( this ) . attr ( "on" ) || "YES" ;
var text_off = $ ( this ) . attr ( "off" ) || "NO" ;
var toggles = "<div class=\"toggle\"><p>" + text_on + "</p></div><div class=\"toggle\"><p>" + text_off + "</p></div>" ;
var content = "<div class=\"checkbox-container\"><div class=\"inner-container\">" + toggles
+ "</div><div class=\"inner-container toggle-container\">" + toggles + "</div></div>" ;
$ ( this ) . before ( content ) . hide ( ) ;
} ) ;
}
@ -768,6 +811,7 @@ function initRelayConfig(data) {
// Sensors & Magnitudes
// -----------------------------------------------------------------------------
<!-- removeIf ( ! sensor ) -- >
function initMagnitudes ( data ) {
// check if already initialized
@ -786,11 +830,14 @@ function initMagnitudes(data) {
}
}
<!-- endRemoveIf ( ! sensor ) -- >
// -----------------------------------------------------------------------------
// Lights
// -----------------------------------------------------------------------------
<!-- removeIf ( ! light ) -- >
function initColorRGB ( ) {
// check if already initialized
@ -909,11 +956,14 @@ function initChannels(num) {
}
}
<!-- endRemoveIf ( ! light ) -- >
// -----------------------------------------------------------------------------
// RFBridge
// -----------------------------------------------------------------------------
<!-- removeIf ( ! rfbridge ) -- >
function rfbLearn ( ) {
var parent = $ ( this ) . parents ( ".pure-g" ) ;
var input = $ ( "input" , parent ) ;
@ -952,6 +1002,7 @@ function addRfbNode() {
return line ;
}
<!-- endRemoveIf ( ! rfbridge ) -- >
// -----------------------------------------------------------------------------
// Processing
@ -1000,6 +1051,8 @@ function processData(data) {
// RFBridge
// ---------------------------------------------------------------------
<!-- removeIf ( ! rfbridge ) -- >
if ( "rfbCount" === key ) {
for ( i = 0 ; i < data . rfbCount ; i ++ ) { addRfbNode ( ) ; }
return ;
@ -1017,11 +1070,14 @@ function processData(data) {
}
return ;
}
<!-- endRemoveIf ( ! rfbridge ) -- >
// ---------------------------------------------------------------------
// Lights
// ---------------------------------------------------------------------
<!-- removeIf ( ! light ) -- >
if ( "rgb" === key ) {
initColorRGB ( ) ;
$ ( "input[name='color']" ) . wheelColorPicker ( "setValue" , value , true ) ;
@ -1072,10 +1128,14 @@ function processData(data) {
useCCT = value ;
}
<!-- endRemoveIf ( ! light ) -- >
// ---------------------------------------------------------------------
// Sensors & Magnitudes
// ---------------------------------------------------------------------
<!-- removeIf ( ! sensor ) -- >
if ( "magnitudes" === key ) {
initMagnitudes ( value ) ;
for ( i in value ) {
@ -1091,6 +1151,8 @@ function processData(data) {
return ;
}
<!-- endRemoveIf ( ! sensor ) -- >
// ---------------------------------------------------------------------
// WiFi
// ---------------------------------------------------------------------
@ -1142,9 +1204,7 @@ function processData(data) {
var sch_value = schedule [ key ] ;
$ ( "input[name='" + key + "']" , sch_line ) . val ( sch_value ) ;
$ ( "select[name='" + key + "']" , sch_line ) . prop ( "value" , sch_value ) ;
$ ( "input[type='checkbox'][name='" + key + "']" , sch_line ) .
prop ( "checked" , sch_value ) .
iphoneStyle ( "refresh" ) ;
$ ( "input[type='checkbox'][name='" + key + "']" , sch_line ) . prop ( "checked" , sch_value ) ;
} ) ;
}
return ;
@ -1157,12 +1217,7 @@ function processData(data) {
if ( "relayStatus" === key ) {
initRelays ( value ) ;
for ( i in value ) {
// Set the status for each relay
$ ( "input.relayStatus[data='" + i + "']" ) .
prop ( "checked" , value [ i ] ) .
iphoneStyle ( "refresh" ) ;
$ ( "input[name='relay'][data='" + i + "']" ) . prop ( "checked" , value [ i ] ) ;
}
return ;
}
@ -1184,10 +1239,12 @@ function processData(data) {
}
// Domoticz - Magnitudes
<!-- removeIf ( ! sensor ) -- >
if ( "dczMagnitudes" === key ) {
createMagnitudeList ( value , "dczMagnitudes" , "dczMagnitudeTemplate" ) ;
return ;
}
<!-- endRemoveIf ( ! sensor ) -- >
// ---------------------------------------------------------------------
// Thingspeak
@ -1200,10 +1257,12 @@ function processData(data) {
}
// Thingspeak - Magnitudes
<!-- removeIf ( ! sensor ) -- >
if ( "tspkMagnitudes" === key ) {
createMagnitudeList ( value , "tspkMagnitudes" , "tspkMagnitudeTemplate" ) ;
return ;
}
<!-- endRemoveIf ( ! sensor ) -- >
// ---------------------------------------------------------------------
// General
@ -1273,9 +1332,7 @@ function processData(data) {
var input = $ ( "input[name='" + key + "']" ) ;
if ( input . length > 0 ) {
if ( input . attr ( "type" ) === "checkbox" ) {
input .
prop ( "checked" , value ) .
iphoneStyle ( "refresh" ) ;
input . prop ( "checked" , value ) ;
} else if ( input . attr ( "type" ) === "radio" ) {
input . val ( [ value ] ) ;
} else {
@ -1307,6 +1364,7 @@ function processData(data) {
}
resetOriginals ( ) ;
initCheckboxes ( ) ;
}
@ -1374,6 +1432,7 @@ function connectToURL(url) {
$ . ajax ( {
'method' : 'GET' ,
'crossDomain' : true ,
'url' : urls . auth . href ,
'xhrFields' : { 'withCredentials' : true }
} ) . done ( function ( data ) {
@ -1402,10 +1461,16 @@ function connectToCurrentURL() {
connectToURL ( new URL ( window . location ) ) ;
}
function getParameterByName ( name ) {
var match = RegExp ( '[?&]' + name + '=([^&]*)' ) . exec ( window . location . search ) ;
return match && decodeURIComponent ( match [ 1 ] . replace ( /\+/g , ' ' ) ) ;
}
$ ( function ( ) {
initMessages ( ) ;
loadTimeZones ( ) ;
createCheckboxes ( ) ;
setInterval ( function ( ) { keepTime ( ) ; } , 1000 ) ;
$ ( "#menuLink" ) . on ( "click" , toggleMenu ) ;
@ -1440,13 +1505,21 @@ $(function() {
$ ( ".more" , addNetwork ( ) ) . toggle ( ) ;
} ) ;
$ ( ".button-add-switch-schedule" ) . on ( "click" , { schType : 1 } , addSchedule ) ;
<!-- removeIf ( ! light ) -- >
$ ( ".button-add-light-schedule" ) . on ( "click" , { schType : 2 } , addSchedule ) ;
<!-- endRemoveIf ( ! light ) -- >
$ ( document ) . on ( "change" , "input" , hasChanged ) ;
$ ( document ) . on ( "change" , "select" , hasChanged ) ;
// don't autoconnect when opening from filesystem
if ( window . location . protocol === "file:" ) { return ; }
connectToCurrentURL ( ) ;
// Check host param in query string
if ( host = getParameterByName ( 'host' ) ) {
connect ( host ) ;
} else {
connectToCurrentURL ( ) ;
}
} ) ;